-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (73 loc) · 2.97 KB
/
deployment-production.yml
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
81
82
83
---
name: Production Deployment
on:
push:
branches:
- deploy/prod
jobs:
deployment:
name: Deployment
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set tag
id: vars
run: echo "rev_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
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: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
mask-password: 'false'
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: api-ecr
IMAGE_TAG: ${{ steps.vars.outputs.rev_sha }}
NODE_ENV: production
JWT_SECRET: ${{ secrets.JWT_SECRET }}
AES_SECRET: ${{ secrets.AES_SECRET }}
MYSQL_HOST: ${{ secrets.MYSQL_HOST }}
MYSQL_PORT: ${{ secrets.MYSQL_PORT }}
MYSQL_USER: ${{ secrets.MYSQL_USER }}
MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD }}
MYSQL_DATABASE: ${{ secrets.MYSQL_DATABASE }}
AWS_CLOUDWATCH_ACCESS_KEY_ID: ${{ secrets.AWS_CLOUDWATCH_ACCESS_KEY_ID }}
AWS_CLOUDWATCH_SECRET_ACCESS_KEY: ${{ secrets.AWS_CLOUDWATCH_SECRET_ACCESS_KEY }}
run: |
cat .env.example | envsubst > .env
cat .env
ls -al
printenv
echo $ECR_REGISTRY
echo $ECR_REPOSITORY
echo $IMAGE_TAG
docker build --build-arg ENV=production -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> "$GITHUB_OUTPUT"
- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition 'api-service' --query taskDefinition > task-definition.json
echo $(jq '.cpu = $CPU_VALUE' --arg CPU_VALUE 1024 task-definition.json) > task-definition.json
echo $(jq '.memory = $MEMORY_VALUE' --arg MEMORY_VALUE 2048 task-definition.json) > 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: api-application
image: ${{ steps.build-image.outputs.image }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: api-service
cluster: api-cluster
wait-for-service-stability: true