CD - Production #12
Workflow file for this run
This file contains 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: CD - Production | |
on: | |
workflow_dispatch: | |
env: | |
AWS_REGION: ap-northeast-2 | |
ECS_CLUSTER: Codedang-Api | |
permissions: # permissions to the job (for the OpenID Connection) | |
id-token: write | |
contents: read | |
jobs: | |
# TODO: trigger Amplify deployment | |
build-client-api: | |
name: Build client-api image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setup Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.AWS_ROLE_FOR_ECR_PUSH }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Build and push image | |
uses: docker/build-push-action@v5 | |
with: | |
file: ./backend/Dockerfile | |
push: true | |
build-args: 'target=client' | |
tags: ${{ steps.login-ecr.outputs.registry }}/codedang-client-api:latest | |
build-admin-api: | |
name: Build admin-api image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setup Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.AWS_ROLE_FOR_ECR_PUSH }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Build and push image | |
uses: docker/build-push-action@v5 | |
with: | |
file: ./backend/Dockerfile | |
push: true | |
build-args: 'target=admin' | |
tags: ${{ steps.login-ecr.outputs.registry }}/codedang-admin-api:latest | |
build-iris: | |
name: Build iris Docker image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setup Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.AWS_ROLE_FOR_ECR_PUSH }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Build and push image (iris) | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
context: '{{defaultContext}}:iris' | |
tags: ${{ steps.login-ecr.outputs.registry }}/codedang-iris:latest | |
deploy: | |
name: Deploy | |
runs-on: ubuntu-latest | |
needs: [build-client-api, build-admin-api, build-iris] | |
environment: production | |
defaults: | |
run: | |
shell: bash | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.AWS_ROLE_FOR_DEPLOY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Trigger Amplify Frontend Build | |
run: curl -X curl -X POST -d {} "${{ secrets.AMPLIFY_WEBHOOK }}"" | |
- uses: hashicorp/setup-terraform@v3 | |
with: | |
terraform_version: 1.5.2 | |
- name: Create Terraform variable file | |
working-directory: ./infra/deploy | |
run: | | |
echo "$TFVARS" >> terraform.tfvars | |
echo "$OAUTH_GITHUB" >> terraform.tfvars | |
echo "$OAUTH_KAKAO" >> terraform.tfvars | |
env: | |
TFVARS: ${{ secrets.TFVARS }} | |
OAUTH_GITHUB: ${{ secrets.OAUTH_GITHUB }} | |
OAUTH_KAKAO: ${{ secrets.OAUTH_KAKAO }} | |
- name: Terraform Init | |
working-directory: ./infra/deploy | |
run: terraform init | |
# TODO: plan in the other job, and reuse the plan file | |
- name: Terraform Plan | |
working-directory: ./infra/deploy | |
run: terraform plan -target=module.codedang-infra -input=false | |
- name: Terraform Apply | |
working-directory: ./infra/deploy | |
run: terraform apply -target=module.codedang-infra -auto-approve -input=false |