Skip to content

Commit

Permalink
Merge branch 'test'
Browse files Browse the repository at this point in the history
  • Loading branch information
choihuk committed Dec 8, 2023
2 parents 4c7d013 + 6d769ad commit 4e2dbb2
Show file tree
Hide file tree
Showing 10 changed files with 190 additions and 2 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/prod_cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: main branch cd

on:
push:
branches:
- "main"

env:
MAIN_YML_PATH: ./src/main/resources/application.yml
PROD_YML_PATH: ./src/main/resources/application-prod.yml

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: application.yml setting
uses: microsoft/variable-substitution@v1
with:
files: ${{ env.MAIN_YML_PATH }}
env:
coolsms.api.key: ${{ secrets.COOLSMS_API_KEY }}
coolsms.api.secret: ${{ secrets.COOLSMS_API_SECRET }}
coolsms.api.from-number: ${{ secrets.COOLSMS_API_FROM_NUMBER }}

- name: application-prod.yml setting
uses: microsoft/variable-substitution@v1
with:
files: ${{ env.PROD_YML_PATH }}
env:
spring.datasource.url: ${{ secrets.RDS_URL }}
spring.datasource.username: ${{ secrets.PROD_DB_USERNAME }}
spring.datasource.password: ${{ secrets.PROD_DB_PASSWORD }}

- name: Cache Gradle packages
uses: actions/cache@v1
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Clean and Build with Gradle
run: ./gradlew clean build -x test

- name: Docker build & push
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ secrets.DOCKER_USERNAME }}/insurance_system_prod .
docker push ${{ secrets.DOCKER_USERNAME }}/insurance_system_prod
- name: Deploy EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST_IP }}
username: ubuntu
key: ${{ secrets.EC2_KEY }}
port: 22
script: |
docker stop insurance_system_prod
docker rm insurance_system_prod
docker rmi choihyeok/insurance_system_prod
docker pull choihyeok/insurance_system_prod
docker run -d -p 80:8080 --name insurance_system_prod choihyeok/insurance_system_prod
10 changes: 10 additions & 0 deletions .github/workflows/test_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

env:
IMAGE_NAME: insurance_system
MAIN_YML_PATH: ./src/main/resources/application.yml
TEST_YML_PATH: ./src/main/resources/application-test.yml

jobs:
Expand All @@ -18,6 +19,15 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: application.yml setting
uses: microsoft/variable-substitution@v1
with:
files: ${{ env.MAIN_YML_PATH }}
env:
coolsms.api.key: ${{ secrets.COOLSMS_API_KEY }}
coolsms.api.secret: ${{ secrets.COOLSMS_API_SECRET }}
coolsms.api.from-number: ${{ secrets.COOLSMS_API_FROM_NUMBER }}

- name: application-test.yml setting
uses: microsoft/variable-substitution@v1
with:
Expand Down
22 changes: 22 additions & 0 deletions Dockerfile_prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 테스트 서버 빌드 스크립트
# jar 파일 빌드
FROM eclipse-temurin:17 as builder

COPY gradlew .
COPY gradle gradle
COPY build.gradle .
COPY settings.gradle .
COPY src src
RUN chmod +x ./gradlew
RUN ./gradlew bootjar

# jar 실행
FROM eclipse-temurin:17-jre as runtime

COPY --from=builder build/libs/*.jar app.jar

ENV PROFILE prod

EXPOSE 8080

ENTRYPOINT ["java", "-Dspring.profiles.active=${PROFILE}", "-jar", "/app.jar"]
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation "com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.0"
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'net.nurigo:sdk:4.3.0'

compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/aplus/insurancesystem/common/service/Esms.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package aplus.insurancesystem.common.service;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum Esms {
COMPENSATION_CLAIM_COMPLETED("보상금 청구가 완료되었습니다. 손해사정에는 수일이 걸릴 수 있습니다."),

SURVEY_COMPLETED("손해사정이 완료되었습니다. 홈페이지에서 결과를 확인해주세요."),

INSURANCE_APPLICATION_APPROVED("보험 가입 심사가 완료되었습니다. 홈페이지에서 결과를 확인해주세요.");

private final String message;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package aplus.insurancesystem.common.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.nurigo.sdk.NurigoApp;
import net.nurigo.sdk.message.model.Message;
import net.nurigo.sdk.message.request.SingleMessageSendingRequest;
import net.nurigo.sdk.message.response.SingleMessageSentResponse;
import net.nurigo.sdk.message.service.DefaultMessageService;

@Service
@Transactional(readOnly = true)
public class MessageService {

private final DefaultMessageService messageService;

private String fromNumber;

public MessageService(@Value("${coolsms.api.key}") String apiKey,
@Value("${coolsms.api.secret}") String apiSecretKey,
@Value("${coolsms.api.from-number}") String fromNumber) {
this.messageService = NurigoApp.INSTANCE.initialize(apiKey, apiSecretKey, "https://api.coolsms.co.kr");
this.fromNumber = fromNumber;
}

public SingleMessageSentResponse sendOne(String to, Esms esms) {
Message message = new Message();
// 발신번호(fromNumber) 및 수신번호(to)는 반드시 01012345678 형태로 입력되어야 함
message.setFrom(fromNumber);
message.setTo(to);
message.setText("[A+보험사] " + esms.getMessage());

SingleMessageSentResponse response = this.messageService.sendOne(new SingleMessageSendingRequest(message));
return response;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package aplus.insurancesystem.domain.compensationClaim.service;


import aplus.insurancesystem.common.service.Esms;
import aplus.insurancesystem.common.service.FileService;
import aplus.insurancesystem.common.service.MessageService;
import aplus.insurancesystem.domain.compensationClaim.dto.request.CreateCarAccidentRequest;
import aplus.insurancesystem.domain.compensationClaim.dto.request.CreateCompensationClaimRequest;
import aplus.insurancesystem.domain.compensationClaim.dto.request.CreateSurveyRequest;
Expand All @@ -21,6 +23,9 @@
import aplus.insurancesystem.domain.contract.entity.Contract;
import aplus.insurancesystem.domain.contract.exception.ContractNotFoundException;
import aplus.insurancesystem.domain.contract.repository.ContractRepository;
import aplus.insurancesystem.domain.contract.service.ContractService;
import aplus.insurancesystem.domain.customer.entity.customer.Customer;
import aplus.insurancesystem.domain.customer.service.CustomerQueryService;
import lombok.RequiredArgsConstructor;
import org.springframework.core.io.InputStreamResource;
import org.springframework.stereotype.Service;
Expand All @@ -38,7 +43,11 @@
public class SurveyServiceImpl implements SurveyService {
private final CompensationClaimRepository compensationClaimRepository;
private final SurveyRepository surveyRepository;
private final ContractRepository contractRepository;
private final ContractService contractService;
private final FileService fileService;
private final MessageService messageService;
private final CustomerQueryService customerQueryService;


@Override
Expand Down Expand Up @@ -70,6 +79,9 @@ public void createSurvey(Long ccid, CreateSurveyRequest request) {
compensationClaim.setSurveyed(true);
compensationClaimRepository.save(compensationClaim);
surveyRepository.save(survey);

String phoneNumber = compensationClaim.getReceptionistPNumber().replaceAll("-", "");
messageService.sendOne(phoneNumber, Esms.SURVEY_COMPLETED);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ spring:
decorator:
datasource:
p6spy:
enable-logging: true
enable-logging: true
12 changes: 12 additions & 0 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url:
username:
password:

jpa:
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
open-in-view: false
hibernate:
ddl-auto: validate
8 changes: 7 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ spring:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

springdoc:
show-login-endpoint: true
show-login-endpoint: true

coolsms:
api:
key: ${COOLSMS_API_KEY}
secret: ${COOLSMS_API_SECRET}
from-number: ${COOLSMS_API_FROM_NUMBER}

0 comments on commit 4e2dbb2

Please sign in to comment.