This repository has been archived by the owner on Dec 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
80 lines (64 loc) · 1.96 KB
/
CD.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
name: CD - production
on:
workflow_dispatch:
env:
AWS_REGION: ap-northeast-2
ECS_CLUSTER: skku_royals_api
ECS_SERVICE: skku-royals-ecs-service
permissions:
id-token: write
contents: read
jobs:
build-api:
name: Build 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_GITHUB_ACTION_ROLE }}
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
tags: ${{ steps.login-ecr.outputs.registry }}/skku-royals/api:latest
- name: Update ECS service
run: aws ecs update-service --cluster ${{ env.ECS_CLUSTER }} --service ${{ env.ECS_SERVICE }} --force-new-deployment
deploy:
name: Deploy
runs-on: ubuntu-latest
needs: [build-api]
environment: production
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_GITHUB_ACTION_ROLE }}
aws-region: ${{ env.AWS_REGION }}
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.5.2
- name: Create Terraform variable file
working-directory: ./aws
run: |
echo "$TFVARS" >> terraform.tfvars
env:
TFVARS: ${{ secrets.TFVARS }}
- name: Terraform Init
working-directory: ./aws
run: terraform init
- name: Terraform Plan
working-directory: ./aws
run: terraform plan -input=false
- name: Terraform Apply
working-directory: ./aws
run: terraform apply -auto-approve -input=false