From a9438edf75120e199640aadde35fedab97605380 Mon Sep 17 00:00:00 2001 From: min-0 Date: Sun, 28 Jul 2024 16:19:55 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=94=92=EF=B8=8F=20Fix=20gitignore,=20?= =?UTF-8?q?Fix=20secrets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DB 설정 yml에 민감한 내용을 repo secrets으로 변경 후 gitignore에 관련 내용 수정 --- .gitignore | 1 - src/main/resources/application-db.yml | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/application-db.yml diff --git a/.gitignore b/.gitignore index fd8d236..c509c0b 100644 --- a/.gitignore +++ b/.gitignore @@ -37,5 +37,4 @@ out/ .vscode/ ### DB ### -application-*.yml **/.DS_Store \ No newline at end of file diff --git a/src/main/resources/application-db.yml b/src/main/resources/application-db.yml new file mode 100644 index 0000000..8671837 --- /dev/null +++ b/src/main/resources/application-db.yml @@ -0,0 +1,5 @@ +spring: + datasource: + url: ${{ secrets.MYSQL_URL }} + username: ${{ secrets.MYSQL_USERNAME }} + password: ${{ secrets.MYSQL_PASSWORD }} \ No newline at end of file From f60d825a1420b2a2c19baf8ca2d2c702e497d9a7 Mon Sep 17 00:00:00 2001 From: min-0 Date: Sun, 28 Jul 2024 17:01:11 +0900 Subject: [PATCH 2/3] :construction_worker: Add shell scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit appspec의 hooks가 실행할 스크립트 작성 --- scripts/start.sh | 19 +++++++++++++++++++ scripts/stop.sh | 17 +++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 scripts/start.sh create mode 100644 scripts/stop.sh diff --git a/scripts/start.sh b/scripts/start.sh new file mode 100644 index 0000000..a81b7b3 --- /dev/null +++ b/scripts/start.sh @@ -0,0 +1,19 @@ +PROJECT_ROOT="/home/ec2-user/mapddang-back" +JAR_FILE="$PROJECT_ROOT/dnd-travel.jar" + +APP_LOG="$PROJECT_ROOT/application.log" +ERROR_LOG="$PROJECT_ROOT/error.log" +DEPLOY_LOG="$PROJECT_ROOT/deploy.log" + +TIME_NOW=$(date +%c) + +# build 파일 복사 +echo "$TIME_NOW > $JAR_FILE 복사" >> $DEPLOY_LOG +cp $PROJECT_ROOT/build/libs/*.jar $JAR_FILE + +# jar 파일 실행 +echo "$TIME_NOW > $JAR_FILE 실행" >> $DEPLOY_LOG +nohup java -jar $JAR_FILE > $APP_LOG 2> $ERROR_LOG & + +CURRENT_PID=$(pgrep -f $JAR_FILE) +echo "$TIME_NOW > 서비스 PID: $CURRENT_PID " >> $DEPLOY_LOG \ No newline at end of file diff --git a/scripts/stop.sh b/scripts/stop.sh new file mode 100644 index 0000000..810b60e --- /dev/null +++ b/scripts/stop.sh @@ -0,0 +1,17 @@ +PROJECT_ROOT="/home/ec2-user/mapddang-back" +JAR_FILE="$PROJECT_ROOT/dnd-travel.jar" + +DEPLOY_LOG="$PROJECT_ROOT/deploy.log" + +TIME_NOW=$(date +%c) + +# 현재 구동 중인 애플리케이션 pid 확인 +CURRENT_PID=$(pgrep -f $JAR_FILE) + +# 프로세스가 켜져 있으면 종료 +if [ -z $CURRENT_PID ]; then + echo "$TIME_NOW > 현재 실행 중인 애플리케이션이 없음" >> $DEPLOY_LOG +else + echo "$TIME_NOW > 실행 중인 $CURRENT_PID 애플리케이션 종료 " >> $DEPLOY_LOG + kill -15 $CURRENT_PID +fi \ No newline at end of file From d1e17f2635be9668c03577a20b6c156944457b68 Mon Sep 17 00:00:00 2001 From: min-0 Date: Sun, 28 Jul 2024 17:05:41 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=91=B7=20Add=20appspec=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AWS CodeDeploy에서 수행할 내용 생성 --- appspec.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 appspec.yml diff --git a/appspec.yml b/appspec.yml new file mode 100644 index 0000000..b62a5f6 --- /dev/null +++ b/appspec.yml @@ -0,0 +1,21 @@ +version: 0.0 +os: linux + +files: + - source: / # 인스턴스에 복사할 디렉터리 경로 + destination: /home/ec2-user/mapddang-back # 인스턴스에서 파일이 복사되는 위치 + overwrite: yes # 복사할 위치에 파일이 있는 경우 대체 + +permissions: + - object: / # 권한이 지정되는 파일 or 디렉터리 + owner: ec2-user # object의 소유자 + group: ec2-user # object의 그룹 이름 + +hooks: + AfterInstall: # CodeDeploy의 AfterInstall 단계에서 실행 + - location: scripts/stop.sh # hooks에서 실행할 스크립트의 위치 + timeout: 60 # 스크립트 실행에 허용되는 최대 시간, 넘으면 배포 실패 + + ApplicationStart: # CodeDeploy의 ApplicationStart 단계에서 실행 + - location: scripts/start.sh + timeout: 60 \ No newline at end of file