From 83781bc8dec4b1c6eff34be874cb554dfe2a888b Mon Sep 17 00:00:00 2001 From: 5win <94297900+5win@users.noreply.github.com> Date: Thu, 31 Oct 2024 11:06:51 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[#37]=20infra:=20=EC=95=95=EC=B6=95?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20S3=20=EC=A0=84=EC=86=A1=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - tar -cvfz ./build.tar.gz 명령어 추가 --- .github/workflows/prod-ci.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/prod-ci.yml b/.github/workflows/prod-ci.yml index 9ba8989..7266afa 100644 --- a/.github/workflows/prod-ci.yml +++ b/.github/workflows/prod-ci.yml @@ -23,6 +23,9 @@ jobs: - name: Build with Gradle Wrapper run: ./gradlew build + - name: archive build directory + run: tar -cvfz ./build.tar.gz + - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1 with: @@ -30,6 +33,6 @@ jobs: aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: ap-northeast-2 - - name: deploy jar + - name: upload to S3 run: | - aws s3 sync build s3://gamja-bongsa \ No newline at end of file + aws s3 sync ./build.tar.gz s3://gamja-bongsa \ No newline at end of file From 8a30a20ecd0423e5c1609028b6c8a0fec9f12288 Mon Sep 17 00:00:00 2001 From: 5win <94297900+5win@users.noreply.github.com> Date: Thu, 31 Oct 2024 14:05:31 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[#37]=20infra:=20CD=20=ED=8C=8C=EC=9D=B4?= =?UTF-8?q?=ED=94=84=EB=9D=BC=EC=9D=B8=20=EC=B6=94=EA=B0=80,=20CI=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - prod-cd.yml 추가 - codedeploy 위한 appspec.yml 추가 - 배포 script 추가 - prod-ci.yml 수정 --- .github/workflows/prod-cd.yml | 26 ++++++++++++++++++++++++++ .github/workflows/prod-ci.yml | 9 +++++++-- appspec.yml | 18 ++++++++++++++++++ scripts/deploy.sh | 29 +++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/prod-cd.yml create mode 100644 appspec.yml create mode 100644 scripts/deploy.sh diff --git a/.github/workflows/prod-cd.yml b/.github/workflows/prod-cd.yml new file mode 100644 index 0000000..b67890e --- /dev/null +++ b/.github/workflows/prod-cd.yml @@ -0,0 +1,26 @@ +name: Prod-CD + +on: + push: + branches: [ "master" ] + +jobs: + deploy: + + runs-on: ubuntu-latest + + steps: + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ap-northeast-2 + + - name: Code Deploy + run: | + aws deploy create-deployment \ + --application-name gamsa-codedeploy \ + --deployment-config-name CodeDeployDefault.AllAtOnce \ + --deployment-group-name gamsa-deploy-group \ + --s3-location bucket=gamja-bongsa,bundleType=tgz,key=deploy.tar.gz \ No newline at end of file diff --git a/.github/workflows/prod-ci.yml b/.github/workflows/prod-ci.yml index 7266afa..36f90ca 100644 --- a/.github/workflows/prod-ci.yml +++ b/.github/workflows/prod-ci.yml @@ -24,7 +24,12 @@ jobs: run: ./gradlew build - name: archive build directory - run: tar -cvfz ./build.tar.gz + run: | + mkdir deploy + cp scripts/*.sh deploy + cp appspec.yml deploy + cp build/libs/*.jar deploy + tar cvfz deploy.tar.gz deploy - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1 @@ -35,4 +40,4 @@ jobs: - name: upload to S3 run: | - aws s3 sync ./build.tar.gz s3://gamja-bongsa \ No newline at end of file + aws s3 sync deploy.tar.gz s3://gamja-bongsa \ No newline at end of file diff --git a/appspec.yml b/appspec.yml new file mode 100644 index 0000000..bd86107 --- /dev/null +++ b/appspec.yml @@ -0,0 +1,18 @@ +version: 0.0 +os: linux +files: + - source: / + destination: /home/ubuntu/deploy + overwrite: yes + +permissions: + - object: / + pattern: "**" + owner: ubuntu + group: ubuntu + +hooks: + ApplicationStart: + - location: deploy.sh + timeout: 60 + runas: ubuntu \ No newline at end of file diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100644 index 0000000..cc6a3f2 --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +REPOSITORY=/home/ubuntu/deploy +APP_NAME=gamsa + +cd $REPOSITORY + +echo "> 현재 구동 중인 애플리케이션 pid 확인" +CURRENT_PID=$(pgrep -f ${APP_NAME}-*.jar) + +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/ | grep jar | tail -n 1) + +echo "> JAR Name: $JAR_NAME" + +echo "> $JAR_NAME에 실행권한 추가" +chmod +x $JAR_NAME + +echo "> $JAR_NAME 실행" +nohup java -jar $REPOSITORY/$JAR_NAME --spring.profiles.active=prod 2>&1 & \ No newline at end of file