From 66f36e9e2a02a4cd42d2f95c93796335e344e273 Mon Sep 17 00:00:00 2001 From: yummygyudon Date: Fri, 24 Nov 2023 01:19:06 +0900 Subject: [PATCH 1/5] create new files --- .github/templates/issue/bug_report.md | 0 .github/templates/issue/feature_request.md | 0 .github/templates/pr/pull_request.md | 0 .github/workflows/SKT_T1_CD.yaml | 0 .github/workflows/SKT_T1_CI.yaml | 0 5 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 .github/templates/issue/bug_report.md create mode 100644 .github/templates/issue/feature_request.md create mode 100644 .github/templates/pr/pull_request.md create mode 100644 .github/workflows/SKT_T1_CD.yaml create mode 100644 .github/workflows/SKT_T1_CI.yaml diff --git a/.github/templates/issue/bug_report.md b/.github/templates/issue/bug_report.md new file mode 100644 index 0000000..e69de29 diff --git a/.github/templates/issue/feature_request.md b/.github/templates/issue/feature_request.md new file mode 100644 index 0000000..e69de29 diff --git a/.github/templates/pr/pull_request.md b/.github/templates/pr/pull_request.md new file mode 100644 index 0000000..e69de29 diff --git a/.github/workflows/SKT_T1_CD.yaml b/.github/workflows/SKT_T1_CD.yaml new file mode 100644 index 0000000..e69de29 diff --git a/.github/workflows/SKT_T1_CI.yaml b/.github/workflows/SKT_T1_CI.yaml new file mode 100644 index 0000000..e69de29 From 8cff2c9b479ba1d11dea9b18e44d4c7952482b14 Mon Sep 17 00:00:00 2001 From: yummygyudon Date: Fri, 24 Nov 2023 01:37:16 +0900 Subject: [PATCH 2/5] change file names to prevent conflicts --- .../pr/{pull_request.md => example_pull_request_template.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/templates/pr/{pull_request.md => example_pull_request_template.md} (100%) diff --git a/.github/templates/pr/pull_request.md b/.github/templates/pr/example_pull_request_template.md similarity index 100% rename from .github/templates/pr/pull_request.md rename to .github/templates/pr/example_pull_request_template.md From 8b92dc21da486c8cf3f5ad8ef6c85d67a9bda1b1 Mon Sep 17 00:00:00 2001 From: yummygyudon Date: Fri, 24 Nov 2023 01:37:52 +0900 Subject: [PATCH 3/5] change file names to prevent conflicts --- .github/templates/issue/{bug_report.md => example_bug_report.md} | 0 .../issue/{feature_request.md => example_feature_request.md} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename .github/templates/issue/{bug_report.md => example_bug_report.md} (100%) rename .github/templates/issue/{feature_request.md => example_feature_request.md} (100%) diff --git a/.github/templates/issue/bug_report.md b/.github/templates/issue/example_bug_report.md similarity index 100% rename from .github/templates/issue/bug_report.md rename to .github/templates/issue/example_bug_report.md diff --git a/.github/templates/issue/feature_request.md b/.github/templates/issue/example_feature_request.md similarity index 100% rename from .github/templates/issue/feature_request.md rename to .github/templates/issue/example_feature_request.md From 2923d4325d18714f44da809fe6919bf6fb308023 Mon Sep 17 00:00:00 2001 From: yummygyudon Date: Fri, 24 Nov 2023 14:14:11 +0900 Subject: [PATCH 4/5] FEAT : add CI script and CD script --- .github/workflows/SKT_T1_CD.yml | 59 +++++++++++++++++++++++++++++++++ .github/workflows/SKT_T1_CI.yml | 49 +++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 .github/workflows/SKT_T1_CD.yml create mode 100644 .github/workflows/SKT_T1_CI.yml diff --git a/.github/workflows/SKT_T1_CD.yml b/.github/workflows/SKT_T1_CD.yml new file mode 100644 index 0000000..4da9237 --- /dev/null +++ b/.github/workflows/SKT_T1_CD.yml @@ -0,0 +1,59 @@ +name: πŸš€ SKT-T1-APPLICATION-DEPLOY! + +on: + push: + branches: [ 'main' ] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + codedeploy-application-name: [ skt-t1-app ] + deployment-group-name: [ skt-t1-app-deploy-group ] + s3-bucket: [ skt-t1-app ] + + + steps: + - name: checkout + uses: actions/checkout@v3 + + - name: set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'corretto' + java-version: '17' + + - name: mkdir resources folder + run: touch ./src/main/resources/application.yml + shell: bash + + - name: copy yaml file + run: echo "${{ secrets.APPLICATION_YML }}" > ./src/main/resources/application.yml + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: 🐈 Gradle Build + run: ./gradlew clean build + + - name: πŸ“‚ Make zip file + run: zip -r ./$GITHUB_SHA.zip . + + - name: πŸͺ£ S3 upload + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} + aws-region: ap-northeast-2 + + - name: πŸš€ s3 upload + run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://${{matrix.s3-bucket}}/deploy/$GITHUB_SHA.zip + + - name: β˜€οΈ CodeDeploy~! + run: aws deploy create-deployment + --application-name ${{matrix.codedeploy-application-name}} + --deployment-group-name ${{matrix.deployment-group-name}} + --s3-location bucket=${{matrix.s3-bucket}},bundleType=zip,key=deploy/$GITHUB_SHA.zip + --file-exists-behavior OVERWRITE + --region ap-northeast-2 \ No newline at end of file diff --git a/.github/workflows/SKT_T1_CI.yml b/.github/workflows/SKT_T1_CI.yml new file mode 100644 index 0000000..a272fe5 --- /dev/null +++ b/.github/workflows/SKT_T1_CI.yml @@ -0,0 +1,49 @@ +name: 🏭 SKT-T1-APPLICATION-BUILD! + +# ν•΄λ‹Ή Action이 μ‹€ν–‰λ˜λŠ” Trigger +on: + pull_request: + branches: [ "dev" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + + # 1) μ›Œν¬ν”Œλ‘œμš° μ‹€ν–‰ μ „ 기본적으둜 체크아웃 ν•„μš” + - name: checkout + uses: actions/checkout@v3 + + # 2) JDK 11버전 μ„€μΉ˜, λ‹€λ₯Έ JDK 버전을 μ‚¬μš©ν•˜λ‹€λ©΄ μˆ˜μ • + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'corretto' + + # 3) ν™˜κ²½λ³€μˆ˜ 파일 생성 + - name: Copy application-local.yml + run: | + # application.yml 생성 + touch ./src/main/resources/application.yml + + # application.yml 파일 κ°’ μž…λ ₯ + echo "${{ secrets.APPLICATION_YML }}" >> ./src/main/resources/application.yaml + + # application.yaml 파일 확인 + cat ./src/main/resources/application.yaml + shell: bash + + # 이 μ›Œν¬ν”Œλ‘œμš°λŠ” gradle build + - name: Grant execute permission for gradlew + run: | + chmod +x gradlew + + - name: Build with Gradle + run: | + ./gradlew build -x test From 0ea1507871bb2875fe6f6e06b0f73fd04773933c Mon Sep 17 00:00:00 2001 From: yummygyudon Date: Fri, 24 Nov 2023 14:15:37 +0900 Subject: [PATCH 5/5] FEAT : add scripts for deploy and appspec file --- .github/workflows/SKT_T1_CD.yaml | 0 .github/workflows/SKT_T1_CI.yaml | 0 appspec.yml | 15 +++++++++++++++ script/start.sh | 25 +++++++++++++++++++++++++ script/stop.sh | 5 +++++ 5 files changed, 45 insertions(+) delete mode 100644 .github/workflows/SKT_T1_CD.yaml delete mode 100644 .github/workflows/SKT_T1_CI.yaml create mode 100644 appspec.yml create mode 100644 script/start.sh create mode 100644 script/stop.sh diff --git a/.github/workflows/SKT_T1_CD.yaml b/.github/workflows/SKT_T1_CD.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/.github/workflows/SKT_T1_CI.yaml b/.github/workflows/SKT_T1_CI.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/appspec.yml b/appspec.yml new file mode 100644 index 0000000..efd4c13 --- /dev/null +++ b/appspec.yml @@ -0,0 +1,15 @@ +version: 0.0 +os: linux + +files: + - source: / + destination: /home/ubuntu/app +hooks: + ApplicationStop: + - location: script/stop.sh + timeout: 60 + runas: root + AfterInstall: + - location: script/start.sh + timeout: 60 + runas: root \ No newline at end of file diff --git a/script/start.sh b/script/start.sh new file mode 100644 index 0000000..018e845 --- /dev/null +++ b/script/start.sh @@ -0,0 +1,25 @@ +# μΈμŠ€ν„΄μŠ€μ— 클둠 받은 디렉토리 이름을 `app`으둜 λ°”κΏ”μ•Όν•©λ‹ˆλ‹€. +APPLICATION_PATH=/home/ubuntu/app +# shellcheck disable=SC2164 +cd $APPLICATION_PATH + +# shellcheck disable=SC2010 +JAR_NAME=$(ls $APPLICATION_PATH/build/libs/ | grep '.jar' | tail -n 1) + +# shellcheck disable=SC2034 +JAR_PATH=build/libs/$JAR_NAME +JAR_PID=$(pgrep -f $JAR_NAME) + + if [ -z $JAR_PID ] + then + echo "> ν˜„μž¬ ꡬ동쀑인 μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ΄ μ—†μœΌλ―€λ‘œ μ’…λ£Œν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€." + else + echo "> sudo kill -15 $JAR_PID" + sudo kill -15 $JAR_PID + sleep 10 + fi + + echo "> $JAR_PATH 배포" #3 + # shellcheck disable=SC2153 + # shellcheck disable=SC2024 + sudo nohup java -jar -Dspring.profiles.active=prod "$JAR_PATH" >nohup.out 2>&1