infra: Github Actions Workflow에 CodeDeploy 설정 추가 #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to Production | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout source code | |
| uses: actions/checkout@master | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Gradle Caching | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.gradle/caches | |
| ~/.gradle/wrapper | |
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
| restore-keys: | | |
| ${{ runner.os }}-gradle- | |
| - name: Make application-prod-profile.yml | |
| run: | | |
| mkdir -p src/main/resources | |
| echo "${{ secrets.APPLICATION_PROD }}" > src/main/resources/application-prod-profile.yml | |
| shell: bash | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| - name: Build with Gradle | |
| run: ./gradlew build -Dspring.profiles.active=prod -x test | |
| - name: Make zip file | |
| run: | | |
| mkdir -p deploy | |
| cp ./build/libs/*.jar ./deploy/ | |
| cp appspec.yml ./deploy/ | |
| cp deploy.sh ./deploy/ | |
| zip -r -qq -j ./spring-build.zip ./deploy | |
| - 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_SECRET_ACCESS_KEY }} | |
| aws-region: ap-northeast-2 | |
| - name: Upload to S3 | |
| run: | | |
| aws s3 cp \ | |
| --region ap-northeast-2 \ | |
| ./spring-build.zip s3://talent-trade-v2 | |
| - name: CodeDeploy 배포 실행 | |
| run: | | |
| aws deploy create-deployment \ | |
| --application-name tradeTalent-deploy \ | |
| --deployment-config-name CodeDeployDefault.OneAtATime \ | |
| --deployment-group-name trade-talent-group \ | |
| --s3-location bucket=talent-trade-v2,bundleType=zip,key=spring-build.zip \ | |
| --region ap-northeast-2 |