-
Notifications
You must be signed in to change notification settings - Fork 62
284 lines (248 loc) · 11.4 KB
/
ecr-publish.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
name: Deploy to Amazon ECS
on:
push:
branches:
- ecr-deploy
- develop
- release/*
- master
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
jobs:
deploy:
name: Build Docker image and deploy to AWS ECR
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: arn:aws:iam::${{ secrets.ACCOUNT_ID }}:role/delegatedadmin/developer/qppsf-dev-githubactions-conversiontool-role
aws-region: ${{ secrets.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Get certificates for Dev
env:
ENV_CT: dev
if: github.ref == 'refs/heads/develop'
run: bash ./qppsfct-copy-certs.sh ${{ env.ENV_CT }} ${{ secrets.AWS_REGION }}
- name: Dev - Build and deploy to Amazon ECR
id: build-image-dev
if: github.ref == 'refs/heads/develop'
env:
ECR_REPOSITORY: qppsf/conversion-tool/dev
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REPOSITORY:latest .
docker tag $ECR_REPOSITORY:latest $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker build -t $ECR_REPOSITORY:$IMAGE_TAG .
docker tag $ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=${ECR_REGISTRY}/${ECR_REPOSITORY}:${IMAGE_TAG}" >> $GITHUB_OUTPUT
- name: Get task definition for dev
if: github.ref == 'refs/heads/develop' && success()
run: |
aws ecs describe-task-definition --task-definition qppsf-conversion-tool-td-dev --query taskDefinition > task-definition.json
- name: Fill in image ID for ECS task-definition
id: task-def-dev
if: github.ref == 'refs/heads/develop' && success()
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: conversion-tool
image: ${{ steps.build-image-dev.outputs.image }}
- name: Deploy Amazon ECS task definition
if: github.ref == 'refs/heads/develop' && success()
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def-dev.outputs.task-definition }}
service: conversion-tool-service-dev
cluster: qppsf-conversion-tool-dev
wait-for-service-stability: true
- name: Dev - Notify slack success
if: github.ref == 'refs/heads/develop' && success()
uses: voxmedia/github-action-slack-notify-build@v1
with:
channel: p-qpp-sub-alerts
status: Conversion tools - Successful Docker build and AWS ECS deployment
color: good
- name: Dev - Notify slack fail
if: github.ref == 'refs/heads/develop' && failure()
uses: voxmedia/github-action-slack-notify-build@v1
with:
channel: p-qpp-sub-alerts
status: Conversion tools - Failed Docker build or AWS ECS deployment
color: danger
- name: Get certificates for Impl
env:
ENV_CT: impl
if: startsWith(github.ref,'refs/heads/release/')
run: bash ./qppsfct-copy-certs.sh ${{ env.ENV_CT }} ${{ secrets.AWS_REGION }}
- name: Impl - Build and deploy to Amazon ECR
id: build-image-impl
if: startsWith(github.ref,'refs/heads/release/')
env:
ECR_REPOSITORY: qppsf/conversion-tool/impl
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REPOSITORY:latest .
docker tag $ECR_REPOSITORY:latest $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker build -t $ECR_REPOSITORY:$IMAGE_TAG .
docker tag $ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=${ECR_REGISTRY}/${ECR_REPOSITORY}:${IMAGE_TAG}" >> $GITHUB_OUTPUT
- name: Get task definition for Impl
if: startsWith(github.ref,'refs/heads/release/') && success()
run: |
aws ecs describe-task-definition --task-definition qppsf-conversion-tool-td-impl --query taskDefinition > task-definition.json
- name: Fill in image ID for ECS task-definition
id: task-def-impl
if: startsWith(github.ref,'refs/heads/release/') && success()
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: conversion-tool
image: ${{ steps.build-image-impl.outputs.image }}
- name: Deploy Amazon ECS task definition
if: startsWith(github.ref,'refs/heads/release/') && success()
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def-impl.outputs.task-definition }}
service: conversion-tool-service-impl
cluster: qppsf-conversion-tool-impl
wait-for-service-stability: true
- name: Impl - Notify slack success
if: startsWith(github.ref,'refs/heads/release/') && success()
uses: voxmedia/github-action-slack-notify-build@v1
with:
channel: p-qpp-sub-alerts
status: Conversion tools - Successful Docker build and AWS ECS deployment
color: good
- name: Impl - Notify slack fail
if: startsWith(github.ref,'refs/heads/release/') && failure()
uses: voxmedia/github-action-slack-notify-build@v1
with:
channel: p-qpp-sub-alerts
status: Conversion tools - Failed Docker build or AWS ECS deployment
color: danger
- name: Get certificates for Prod
env:
ENV_CT: prod
if: github.ref == 'refs/heads/master'
run: bash ./qppsfct-copy-certs.sh ${{ env.ENV_CT }} ${{ secrets.AWS_REGION }}
- name: Prod - Build and deploy to Amazon ECR
id: build-image-prod
if: github.ref == 'refs/heads/master'
env:
ECR_REPOSITORY: qppsf/conversion-tool/prod
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REPOSITORY:latest .
docker tag $ECR_REPOSITORY:latest $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker build -t $ECR_REPOSITORY:$IMAGE_TAG .
docker tag $ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=${ECR_REGISTRY}/${ECR_REPOSITORY}:${IMAGE_TAG}" >> $GITHUB_OUTPUT
- name: Get task definition for Prod
if: github.ref == 'refs/heads/master' && success()
run: |
aws ecs describe-task-definition --task-definition qppsf-conversion-tool-td-prod --query taskDefinition > task-definition.json
- name: Fill in image ID for ECS task-definition
id: task-def-prod
if: github.ref == 'refs/heads/master' && success()
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: conversion-tool
image: ${{ steps.build-image-prod.outputs.image }}
- name: Deploy Amazon ECS task definition
if: github.ref == 'refs/heads/master' && success()
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def-prod.outputs.task-definition }}
service: conversion-tool-service-prod
cluster: qppsf-conversion-tool-prod
wait-for-service-stability: true
- name: Prod - Notify slack success
if: github.ref == 'refs/heads/master' && success()
uses: voxmedia/github-action-slack-notify-build@v1
with:
channel: p-qpp-sub-alerts
status: Conversion tools - Successful Docker build and AWS ECS deployment
color: good
- name: Prod - Notify slack fail
if: github.ref == 'refs/heads/master' && failure()
uses: voxmedia/github-action-slack-notify-build@v1
with:
channel: p-qpp-sub-alerts
status: Conversion tools - Failed Docker build or AWS ECS deployment
color: danger
- name: Get certificates for Devpre
env:
ENV_CT: devpre
if: github.ref == 'refs/heads/master'
run: bash ./qppsfct-copy-certs.sh ${{ env.ENV_CT }} ${{ secrets.AWS_REGION }}
- name: DevPre - Build and deploy to Amazon ECR
id: build-image-devpre
if: github.ref == 'refs/heads/master'
env:
ECR_REPOSITORY: qppsf/conversion-tool/devpre
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REPOSITORY:latest .
docker tag $ECR_REPOSITORY:latest $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker build -t $ECR_REPOSITORY:$IMAGE_TAG .
docker tag $ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=${ECR_REGISTRY}/${ECR_REPOSITORY}:${IMAGE_TAG}" >> $GITHUB_OUTPUT
- name: Get task definition for DevPre
if: github.ref == 'refs/heads/master' && success()
run: |
aws ecs describe-task-definition --task-definition qppsf-conversion-tool-td-devpre --query taskDefinition > task-definition.json
- name: Fill in image ID for ECS task-definition
id: task-def-devpre
if: github.ref == 'refs/heads/master' && success()
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: conversion-tool
image: ${{ steps.build-image-devpre.outputs.image }}
- name: Deploy Amazon ECS task definition
if: github.ref == 'refs/heads/master' && success()
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def-devpre.outputs.task-definition }}
service: conversion-tool-service-devpre
cluster: qppsf-conversion-tool-devpre
wait-for-service-stability: true
- name: DevPre - Notify slack success
if: github.ref == 'refs/heads/master' && success()
uses: voxmedia/github-action-slack-notify-build@v1
with:
channel: p-qpp-sub-alerts
status: Conversion tools - Successful Docker build and AWS ECS deployment
color: good
- name: DevPre - Notify slack fail
if: github.ref == 'refs/heads/master' && failure()
uses: voxmedia/github-action-slack-notify-build@v1
with:
channel: p-qpp-sub-alerts
status: Conversion tools - Failed Docker build or AWS ECS deployment
color: danger
- name: Logout of Amazon ECR
if: always()
run: docker logout ${{ steps.login-ecr.outputs.registry }}