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 2daf562..0000000 --- a/.github/workflows/ci-cd.yml +++ /dev/null @@ -1,74 +0,0 @@ -name: CI/CD - -on: - push: - branches: - - main - - dev - - prod - 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