From d87cd85da0a269f8e3a54353950f73ba9f67d1f0 Mon Sep 17 00:00:00 2001 From: yerim1ee <97941141+yerim123456@users.noreply.github.com> Date: Tue, 27 Aug 2024 03:33:10 +0900 Subject: [PATCH 1/4] =?UTF-8?q?chore:=20ci-pipeline=EC=97=90=20cd=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80=20(#55)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-pipeline.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.github/workflows/ci-pipeline.yml b/.github/workflows/ci-pipeline.yml index b8a85a1..ad4418f 100644 --- a/.github/workflows/ci-pipeline.yml +++ b/.github/workflows/ci-pipeline.yml @@ -5,6 +5,12 @@ on: branches: - main +env: + PROJECT_NAME: feed-project + BUCKET_NAME: feed-cd-bucket + CODE_DEPLOY_APP_NAME: feed_cicd + DEPLOYMENT_GROUP_NAME: feed_instance + permissions: contents: read checks: write @@ -49,3 +55,24 @@ jobs: with: webhook-url: ${{ secrets.WEBHOOK_URL }} content: ":love_letter: 새로운 PR이 날아왔습니다 ~ :love_letter:\n:link: 리뷰하러 가기: ${{ github.event.pull_request.html_url }}" + + - name: ZIP 파일 생성 + run: zip -qq -r ./$GITHUB_SHA.zip . + shell: bash + + - 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_PRIVATE_ACCESS_KEY }} + aws-region: ap-northeast-2 + + - name: Upload to S3 + run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$BUCKET_NAME/$PROJECT_NAME/$GITHUB_SHA.zip + + - name: Code Deploy To EC2 instance + run: aws deploy create-deployment + --application-name $CODE_DEPLOY_APP_NAME + --deployment-config-name CodeDeployDefault.AllAtOnce + --deployment-group-name $DEPLOYMENT_GROUP_NAME + --s3-location bucket=$BUCKET_NAME,bundleType=zip,key=$PROJECT_NAME/$GITHUB_SHA.zip From b7fa6b85cb10a11d4c329f223be06fb94f6e5ae4 Mon Sep 17 00:00:00 2001 From: yerim1ee <97941141+yerim123456@users.noreply.github.com> Date: Tue, 27 Aug 2024 03:34:45 +0900 Subject: [PATCH 2/4] =?UTF-8?q?chore:=20codeDeploy=EA=B0=80=20=EB=B0=B0?= =?UTF-8?q?=ED=8F=AC=20=EC=9E=91=EC=97=85=EC=8B=9C=20=EC=B0=B8=EC=A1=B0?= =?UTF-8?q?=ED=95=A0=20=EC=A0=95=EB=B3=B4=20=EC=B6=94=EA=B0=80=20(#55)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- appspec.yml | 20 ++++++++++++++++++++ scripts/deploy.sh | 21 +++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 appspec.yml create mode 100644 scripts/deploy.sh diff --git a/appspec.yml b/appspec.yml new file mode 100644 index 0000000..799e37b --- /dev/null +++ b/appspec.yml @@ -0,0 +1,20 @@ +version: 0.0 +os: linux + +# 배포할 파일 및 디렉토리를 정의합니다. +files: + - source: / + destination: /home/ubuntu/feed + +# 권한을 정의합니다. +permissions: + - object: /home/ubuntu/feed/ + owner: ubuntu + group: ubuntu + +# 배포단계에서 진행하는 훅 스크립트를 정의합니다. +hooks: + AfterInstall: + - location: scripts/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..6db89d3 --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,21 @@ + +REPOSITORY=/home/ubuntu/plug +cd $REPOSITORY + +APP_NAME=plug +JAR_NAME=$(ls $REPOSITORY/build/libs/ | grep 'SNAPSHOT.jar' | tail -n 1) +JAR_PATH=$REPOSITORY/build/libs/$JAR_NAME + +CURRENT_PID=$(pgrep -f $APP_NAME) + +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 > /dev/null 2> /dev/null < /dev/null & \ No newline at end of file From c5bdd5fbf9b9f76805946ee502233b09275080f6 Mon Sep 17 00:00:00 2001 From: yerim1ee <97941141+yerim123456@users.noreply.github.com> Date: Tue, 27 Aug 2024 03:35:06 +0900 Subject: [PATCH 3/4] =?UTF-8?q?chore:=20=EB=B9=8C=EB=93=9C=20=ED=9B=84=20j?= =?UTF-8?q?ar=20=ED=8C=8C=EC=9D=BC=20=EC=83=9D=EC=84=B1=20=EB=B0=A9?= =?UTF-8?q?=EC=A7=80(#55)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index f1bf61c..f04aba5 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,7 @@ plugins { group = 'team05' version = '0.0.1-SNAPSHOT' +jar.enabled = false java { toolchain { From 33cc82a20e2d15a8505ee3ef4e51e3799d43752b Mon Sep 17 00:00:00 2001 From: yerim1ee <97941141+yerim123456@users.noreply.github.com> Date: Tue, 27 Aug 2024 03:47:06 +0900 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20CodeDeploy=20=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?=EC=A7=80=EC=97=AD=20=EB=B3=80=EA=B2=BD=20(#55)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-pipeline.yml b/.github/workflows/ci-pipeline.yml index ad4418f..e4c632e 100644 --- a/.github/workflows/ci-pipeline.yml +++ b/.github/workflows/ci-pipeline.yml @@ -8,7 +8,7 @@ on: env: PROJECT_NAME: feed-project BUCKET_NAME: feed-cd-bucket - CODE_DEPLOY_APP_NAME: feed_cicd + CODE_DEPLOY_APP_NAME: feed_cd DEPLOYMENT_GROUP_NAME: feed_instance permissions: