-
Notifications
You must be signed in to change notification settings - Fork 2
116 lines (103 loc) · 3.78 KB
/
reusable-deploy-backend-server.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# This workflow will build and push a new container image to Amazon ECR,
# and then will deploy a new task definition to Amazon ECS, when there is a push to the main branch.
name: Resuable Deployer for GitPOAP Backend
on:
workflow_call:
inputs:
ECR_REPOSITORY:
required: true
type: string
ECS_SERVICE:
required: true
type: string
ECS_CLUSTER:
required: true
type: string
CONTAINER_NAME:
required: true
type: string
deploy_environment:
required: true
type: string
task_definition_tag:
required: true
type: string
login_redirect_url:
required: true
type: string
discord_redirect_url:
required: true
type: string
secrets:
AWS_ACCESS_KEY_ID:
required: true
AWS_SECRET_ACCESS_KEY:
required: true
env:
AWS_REGION: us-east-2
jobs:
deploy:
name: Deploy ${{ inputs.deploy_environment }}
runs-on: ubuntu-latest
environment: ${{ inputs.deploy_environment }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
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: Apply any waiting DB migrations
id: db-migrate
uses: gagoar/invoke-aws-lambda@master
with:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
REGION: ${{ env.AWS_REGION }}
FunctionName: gitpoap-migration${{ inputs.task_definition_tag }}-lambda
LogType: Tail
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/${{ inputs.ECR_REPOSITORY }}:$IMAGE_TAG -f aws/server.Dockerfile .
docker push $ECR_REGISTRY/${{ inputs.ECR_REPOSITORY }}:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/${{ inputs.ECR_REPOSITORY }}:$IMAGE_TAG"
- name: Install jinja-cli
run: pip3 install jinja-cli
- name: Create task-definition.json for this stage
run: |
cat > defs.json <<EOF
{
"task_definition_tag": "${{ inputs.task_definition_tag }}",
"aws_region": "${{ env.AWS_REGION }}",
"deploy_environment": "${{ inputs.deploy_environment }}",
"login_redirect_url": "${{ inputs.login_redirect_url }}",
"discord_redirect_url": "${{ inputs.discord_redirect_url }}"
}
EOF
jinja -d defs.json aws/server.task-definition.json.j2 > aws/server.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: aws/server.task-definition.json
container-name: ${{ inputs.CONTAINER_NAME }}
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: ${{ inputs.ECS_SERVICE }}
cluster: ${{ inputs.ECS_CLUSTER }}
wait-for-service-stability: true