Skip to content

Commit

Permalink
[docs] AWS CodeDeploy 연동 및 자동화 배포 #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Si-Hyeak-KANG committed Jan 15, 2024
1 parent d0f3ca3 commit 8911fe7
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ jobs:
- name: Copy Jar
run: cp ./build/libs/*.jar ./deploy

# appspec.yml 파일 복사
- name: Copy appspec.yml
run: cp appspec.yml ./deploy

# script files 복사
- name: Copy script
run: cp ./scripts/*.sh ./deploy

- name: Make zip file
run: zip -r ./sebadog.zip ./deploy
shell: bash
Expand All @@ -52,3 +60,11 @@ jobs:

- name: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./sebadog.zip s3://$S3_BUCKET_NAME/

# Deploy
- name: Deploy
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
aws deploy create-deployment --application-name sebadog --deployment-group-name sebadog-group --file-exists-behavior OVERWRITE --s3-location bucket=$3_BUCKET_NAME,bundleType=zip,key=sebadog.zip --region ap-northeast-2
18 changes: 18 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 0.0
os: linux
files:
- source: /
destination: /home/ubuntu/app/
overwrite: yes

permissions:
- object: /
pattern: "**"
owner: ubuntu
group: ubuntu

hooks:
ApplicationStart:
- location: deploy.sh
timeout: 60
runas: ubuntu
31 changes: 31 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

REPOSITORY=/home/ubuntu/app

echo "> 현재 구동 중인 애플리케이션 pid 확인"

CURRENT_PID=$(pgrep -fla java | grep hayan | awk '{print $1}')

echo "현재 구동 중인 애플리케이션 pid: $CURRENT_PID"

if [ -z "$CURRENT_PID" ]; then
echo "현재 구동 중인 애플리케이션이 없으므로 종료하지 않습니다."
else
echo "> kill -15 $CURRENT_PID"
kill -15 $CURRENT_PID
sleep 5
fi

echo "> 새 애플리케이션 배포"

JAR_NAME=$(ls -tr $REPOSITORY/*SNAPSHOT.jar | tail -n 1)

echo "> JAR NAME: $JAR_NAME"

echo "> $JAR_NAME 에 실행권한 추가"

chmod +x $JAR_NAME

echo "> $JAR_NAME 실행"

nohup java -jar -Duser.timezone=Asia/Seoul $JAR_NAME >> $REPOSITORY/nohup.out 2>&1 &

0 comments on commit 8911fe7

Please sign in to comment.