From b11b7200984f1097bce837b549aa15f6688070b1 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Wed, 31 Jul 2024 17:10:14 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=EB=B8=8C=EB=9E=9C=EC=B9=98=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-cd.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 2daf562..1bc4b2e 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -6,6 +6,7 @@ on: - main - dev - prod + - feat/** pull_request: branches: - main From 3e46991eb81acb477ab02c810a2b16a8fa7b4339 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Wed, 31 Jul 2024 17:16:16 +0900 Subject: [PATCH 2/2] =?UTF-8?q?ci-cd=20=ED=8C=8C=EC=9D=B4=ED=94=84?= =?UTF-8?q?=EB=9D=BC=EC=9D=B8=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-cd-v2.yml | 66 ++++++++++++++++++++++++++++++ .github/workflows/ci-cd.yml | 75 ---------------------------------- 2 files changed, 66 insertions(+), 75 deletions(-) create mode 100644 .github/workflows/ci-cd-v2.yml delete mode 100644 .github/workflows/ci-cd.yml diff --git a/.github/workflows/ci-cd-v2.yml b/.github/workflows/ci-cd-v2.yml new file mode 100644 index 0000000..19bcff2 --- /dev/null +++ b/.github/workflows/ci-cd-v2.yml @@ -0,0 +1,66 @@ +name: CI/CD Pipeline + +# main 브랜치에 push 또는 pull request가 발생할 때 실행 +# feature/{feature-name} : 새로운 기능이나 버그 수정 작업 브랜치 +on: + push: + branches: + - main + - feat/** + pull_request: + branches: + - main + +env: + PROJECT_NAME: nostroke + BUCKET_NAME: nostroke-dev-bucket + CODE_DEPLOY_APP_NAME: NoStrokeCodeDeployApplication + DEPLOYMENT_GROUP_NAME: nostroke-deploy-group + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up JDK 21 + uses: actions/setup-java@v3 + with: + java-version: '21' + distribution: 'temurin' + + # gradlew 파일 실행권한 설정 + - name: Grant execute permission for gradlew + run: chmod +x ./gradlew + + # 빌드 시작 + - name: Build with Gradle + run: ./gradlew build + + # 프로젝트 zip파일로 압축 + - name: Make Zip File + run: zip -qq -r ./$GITHUB_SHA.zip . + + # aws 접근 id, key + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ap-northeast-2 + + # s3에 압축한 zip파일 업로드 + - name: Upload to S3 + run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$BUCKET_NAME/$PROJECT_NAME/$GITHUB_SHA.zip + + # s3에 업로드한 파일 code Deploy에서 배포 요청 + # Deploy with AWS CodeDeploy + - name: Deploy with AWS CodeDeploy + 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 diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml deleted file mode 100644 index 1bc4b2e..0000000 --- a/.github/workflows/ci-cd.yml +++ /dev/null @@ -1,75 +0,0 @@ -name: CI/CD - -on: - push: - branches: - - main - - dev - - prod - - feat/** - pull_request: - branches: - - main - - dev - - prod - -permissions: - contents: read - checks: write - -jobs: - build: - runs-on: ubuntu-latest - - env: - APPLICATION: ${{ github.ref == 'refs/heads/prod' && secrets.PROD_APPLICATION || secrets.DEV_APPLICATION }} - ENVIRONMENT: ${{ github.ref == 'refs/heads/prod' && 'prod' ||'dev' }} - CODE_DEPLOY_APP_NAME: ${{ github.ref == 'refs/heads/dev' && secrets.CODE_DEPLOY_DEV_APP_NAME || secrets.CODE_DEPLOY_PROD_APP_NAME }} - CODE_DEPLOY_GROUP_NAME: ${{ github.ref == 'refs/heads/dev' && secrets.CODE_DEPLOY_DEV_GROUP_NAME || secrets.CODE_DEPLOY_PROD_GROUP_NAME }} - - steps: - - name: Repository Checkout - uses: actions/checkout@v3 - - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: 17 - distribution: 'corretto' - - - name: create applications.yml - shell: bash - run: | - touch ./src/main/resources/application.yml - echo "$APPLICATION" >> ./src/main/resources/application.yml - - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - - name: Build with Gradle - run: ./gradlew clean build -x test - - # CD - - name: Make Zip File - if: github.event_name == 'push' - run: zip -qq -r ./$GITHUB_SHA.zip . - - - name: Configure AWS credentials - if: github.event_name == 'push' - uses: aws-actions/configure-aws-credentials@v2 - 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: Upload to S3 - if: github.event_name == 'push' - run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://${{ secrets.S3_BUCKET_NAME }}/deploy/$ENVIRONMENT/$GITHUB_SHA.zip - - - name: Deploy with AWS codeDeploy - if: github.event_name == 'push' - run: aws deploy create-deployment - --application-name $CODE_DEPLOY_APP_NAME - --deployment-config-name CodeDeployDefault.AllAtOnce - --deployment-group-name $CODE_DEPLOY_GROUP_NAME - --s3-location bucket=${{ secrets.S3_BUCKET_NAME }},bundleType=zip,key=deploy/$ENVIRONMENT/$GITHUB_SHA.zip