Skip to content

chore: main push trigger #21

chore: main push trigger

chore: main push trigger #21

Workflow file for this run

on:
push:
branches:
- main
env:
AWS_REGION: ap-northeast-2
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
ECR_REPOSITORY: ${{ secrets.PROD_ECR_REPOSITORY }}
IMAGE_TAG: latest
ECS_CONTAINER_NAME: ${{ secrets.ECS_CONTAINER_NAME }}
ECS_CLUSTER_NAME: ${{ secrets.ECS_CLUSTER_NAME }}
ECS_SERVICE_NAME: ${{ secrets.ECS_SERVICE_NAME }}
TASK_DEFINITION_NAME: ${{ secrets.TASK_DEFINITION_NAME }}
ENV: prod
jobs:
deloy-prod:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
token: ${{ secrets.SUBMODULE_ACCESS_TOKEN }}
submodules: true
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- 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: Build with Gradle
run: ./gradlew clean build -x test # Test was run on SonarQube.
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: login to ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
with:
mask-password: 'false'
- name: Build, tag, and push image to Amazon ECR
id: build-image
run: |
docker build -t ${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} .
docker push ${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition ${{ env.TASK_DEFINITION_NAME }}-${{ env.ENV }} --query taskDefinition > task-definition.json
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: ${{ env.ECS_CONTAINER_NAME }}-${{ env.ENV }}
image: ${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
- name: Deploy Amazon ECS task definition
id: deploy
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE_NAME }}-${{ env.ENV }}
cluster: ${{ env.ECS_CLUSTER_NAME }}-${{ env.ENV }}
wait-for-service-stability: true