diff --git "a/.github/workflows/\bprod-kr.yml" "b/.github/workflows/\bprod-kr.yml" new file mode 100644 index 00000000..a718a001 --- /dev/null +++ "b/.github/workflows/\bprod-kr.yml" @@ -0,0 +1,70 @@ +# This is a basic workflow to help you get started with Actions + +name: Deploy to prod KR + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the master branch + push: + branches: [ main ] + +permissions: + packages: write + contents: read + id-token: write + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + environment: Prod-Server-KR + + steps: + # (1) 기본 체크아웃 + - name: Checkout + uses: actions/checkout@v3 + + # (2) JDK 17 세팅 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + + # (3) firebase secret decrypt + - name: Decrypt Secrets + run: | + sh .github/workflows/decrypt.sh + + # (4) Gradle build + - name: Build with Gradle + uses: gradle/gradle-build-action@0d13054264b0bb894ded474f08ebb30921341cee + with: + arguments: clean build + + # (5) build 결과물 압축 + - name: Make zip file #1 # build한 파일 모두 압축 + run: zip -qq -r ./$GITHUB_SHA.zip . + shell: bash + + # (6) AWS 인증 (IAM 사용자 Access Key, Secret Key 활용) + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@master + with: + aws-access-key-id: ${{ secrets.KR_PROD_AWS_ACCESS_KEY }} + aws-secret-access-key: ${{ secrets.KR_PROD_AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ secrets.KR_PROD_AWS_REGION }} + + # (7) 빌드 결과물을 S3 버킷에 업로드 + - name: Upload to AWS S3 + run: aws s3 cp --region ${{ secrets.KR_PROD_AWS_REGION }} ./$GITHUB_SHA.zip s3://${{ secrets.KR_PROD_S3_BUCKET_NAME }}/$GITHUB_SHA.zip + + # (8) S3 버킷에 있는 파일을 대상으로 CodeDeploy 실행 + - name: Deploy to AWS EC2 from S3 + run: | + aws deploy create-deployment \ + --application-name ${{ secrets.CODE_DEPLOY_APPLICATION_NAME }} \ + --deployment-config-name CodeDeployDefault.AllAtOnce \ + --deployment-group-name ${{ secrets.CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }} \ + --s3-location bucket=${{ secrets.KR_PROD_S3_BUCKET_NAME }},key=$GITHUB_SHA.zip,bundleType=zip