Release 0.0.4 (#138) #6
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 environment | |
| on: | |
| push: | |
| branches: | |
| - prod | |
| env: | |
| AWS_REGION: ap-northeast-2 | |
| CONTAINER_NAME: gotchai-server | |
| jobs: | |
| deploy-image: | |
| name: Deploy image | |
| runs-on: ubuntu-latest | |
| environment: prod | |
| outputs: | |
| image: ${{ steps.set-image.outputs.image }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: corretto | |
| java-version: 21 | |
| - name: Cache Gradle packages | |
| 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: 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: ${{ env.AWS_REGION }} | |
| - name: Set image | |
| id: set-image | |
| run: echo "image=${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY }}:${{ github.sha }}" >> $GITHUB_OUTPUT | |
| - name: Build and deploy image to AWS ECR | |
| run: | | |
| ./gradlew :api:jib \ | |
| -Djib.to.image=${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY }}:${{ github.sha }} \ | |
| -Djib.to.auth.username=AWS \ | |
| -Djib.to.auth.password=$(aws ecr get-login-password) | |
| deploy-container: | |
| name: Deploy container | |
| runs-on: ubuntu-latest | |
| needs: deploy-image | |
| environment: prod | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Send necessary files to EC2 | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_PRIVATE_KEY }} | |
| source: docker/docker-compose-prod.yml | |
| target: "~" | |
| strip_components: 1 | |
| - name: Build and deploy container to AWS EC2 | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_PRIVATE_KEY }} | |
| script: | | |
| aws secretsmanager get-secret-value --secret-id prod-env --region ap-northeast-2 --query SecretString --output text | jq -r '. | to_entries | map("\(.key)=\(.value)") | .[]' > .env | |
| export IMAGE_URI=${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY }}:${{ github.sha }} | |
| docker-compose -f docker-compose-prod.yml --env-file .env up -d --build | |
| notify-discord: | |
| name: Notify Discord | |
| runs-on: ubuntu-latest | |
| needs: deploy-container | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Get commit | |
| id: get_commit | |
| run: echo "commit_message=$(git log -1 --pretty=%s)" >> "$GITHUB_OUTPUT" | |
| - name: Send Discord notification | |
| run: | | |
| curl -X POST -H "Content-Type: application/json" -d '{ | |
| "username": "GitHub Actions", | |
| "avatar_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png", | |
| "embeds": [ | |
| { | |
| "title": "**프로덕션 환경 배포 성공**", | |
| "description": "프로덕션 서버가 성공적으로 배포되었습니다.", | |
| "color": 3066993, | |
| "fields": [ | |
| { | |
| "name": "Repository", | |
| "value": "[${{ github.repository }}](https://github.com/${{ github.repository }})", | |
| "inline": true | |
| }, | |
| { | |
| "name": "Branch", | |
| "value": "${{ github.ref_name }}", | |
| "inline": true | |
| }, | |
| { | |
| "name": "Commit", | |
| "value": "[${{ steps.get_commit.outputs.commit_message }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }})", | |
| "inline": true | |
| }, | |
| { | |
| "name": "Author", | |
| "value": "[${{ github.actor }}](${{ github.event.sender.html_url }})", | |
| "inline": true | |
| } | |
| ] | |
| } | |
| ] | |
| }' ${{ secrets.DISCORD_WEBHOOK_URL }} |