Skip to content

Commit

Permalink
feat: 자동화 배포를 위한 S3 업로드 및 codeDeploy 스크립트 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
KangJiSseok committed Mar 11, 2024
1 parent 1dc2f0a commit bd78291
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,18 @@ jobs:
aws-region: ap-northeast-2
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- name: Configure AWS credential
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: ap-northeast-2
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- name: Upload to S3
working-directory: ./BackEnd
run: aws deploy push --application-name ${{ env.AWS_CODE_DEPLOY_APPLICATION }} --ignore-hidden-files --s3-location s3://${{ env.AWS_S3_BUCKET }}/4K-Backend-EC2/$GITHUB_SHA.zip --source .

- name: Code Deploy to EC2
working-directory: ./BackEnd
run: aws deploy create-deployment —application-name ${{ env.AWS_CODE_DEPLOY_APPLICATION }} —deployment-config-name CodeDeployDefault.AllAtOnce —deployment-group-name ${{ env.AWS_CODE_DEPLOY_GROUP }} —s3-location bucket=${{ env.AWS_S3_BUCKET }},key=4K-Backend-EC2/$GITHUB_SHA.zip,bundleType=zip
8 changes: 8 additions & 0 deletions .idea/modules/webChat.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions BackEnd/appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 0.0
os: linux

files:
- source: /
destination: /home/ubuntu/4k
permissions:
- object: /home/ubuntu/4k/
owner: ubuntu
group: ubuntu
hooks:
AfterInstall:
- location: scripts/deploy.sh
timeout: 60
runas: ubuntu
19 changes: 19 additions & 0 deletions BackEnd/scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
REPOSITORY=/home/ubuntu/4k
cd $REPOSITORY

JAR_NAME=$(ls $REPOSITORY/build/libs/ | grep 'SNAPSHOT.jar' | tail -n 1)
JAR_PATH=$REPOSITORY/build/libs/$JAR_NAME

CURRENT_PID=$(pgrep -fl 'java -jar webChat-0.0.1-SNAPSHOT.jar')

if [ -z $CURRENT_PID ]
then
echo "> 종료할 애플리케이션이 없습니다."
else
echo "> kill -9 $CURRENT_PID"
kill -15 $CURRENT_PID
sleep 5
fi

echo "> Deploy - $JAR_PATH "
nohup java -jar $JAR_PATH > $REPOSITORY/build/libs/nohup.out 2>&1 &

0 comments on commit bd78291

Please sign in to comment.