-
Notifications
You must be signed in to change notification settings - Fork 0
300 lines (256 loc) · 9 KB
/
ui-deploy-to-pre-prod-manual.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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
name: 'UI - Deploy and Version Main to Pre-Prod'
on:
workflow_dispatch:
permissions:
pull-requests: write
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
jobs:
tag_and_release:
runs-on: ubuntu-latest
environment: pre-prod
outputs:
tag: ${{steps.versioning.outputs.tag}}
new_tag: ${{steps.versioning.outputs.new_tag}}
defaults:
run:
working-directory: ./app
permissions: write-all
steps:
- uses: actions/checkout@v3
with:
ref: main
fetch-depth: '0'
- name: Bump version and push tag
id: versioning
uses: anothrNick/github-tag-action@1.64.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: false
DEFAULT_BUMP: patch
- name: View outputs
run: |
echo Current tag: ${{steps.versioning.outputs.tag}}
echo New tag: ${{steps.versioning.outputs.new_tag}}
react_testing_job:
runs-on: ubuntu-latest
environment: pre-prod
needs: ['tag_and_release']
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v3
with:
ref: ${{needs.tag_and_release.outputs.tag}}
fetch-depth: '0'
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Configure React environment vars
env:
ENDPOINT_DOC_STORE_API: http://test-endpoint.com
AWS_REGION: test region
OIDC_PROVIDER_ID: not provided yet
BUILD_ENV: development
IMAGE_VERSION: 'ndr-${{ vars.BUILD_ENV }}-app:${{ github.sha }}'
run: |
./react-environment-config.sh
working-directory: ./app
shell: bash
- run: make clean-install
- run: make test-ui
install-cypress-build:
runs-on: ubuntu-22.04
needs: ['react_testing_job']
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Cypress install
run: npm install --legacy-peer-deps
working-directory: ./app
- name: Configure React environment vars
env:
ENDPOINT_DOC_STORE_API: http://test-endpoint.com
AWS_REGION: test region
OIDC_PROVIDER_ID: not provided yet
BUILD_ENV: development
IMAGE_VERSION: 'ndr-${{ vars.BUILD_ENV }}-app::${{ github.sha }}'
run: |
./react-environment-config.sh
working-directory: ./app
- name: Cypress build
uses: cypress-io/github-action@v5
with:
# Disable running of tests within install job
install: false
runTests: false
build: npm run build
working-directory: ./app
- name: Save build folder
uses: actions/upload-artifact@v3
with:
name: build
if-no-files-found: error
path: ./app/build
cypress-run-chrome:
runs-on: ubuntu-22.04
needs: install-cypress-build
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download the build folder
uses: actions/download-artifact@v3
with:
name: build
path: ./app/build
env:
CYPRESS_BASE_URL: 'http://localhost:3000'
CYPRESS_RUN_AS_SMOKETEST: false
# Npm run will run the app locally, we want to test the built application with env vars using serve
- name: Install serve globally
run: npm install -g serve
- name: Cypress install
run: |
npm install --legacy-peer-deps
working-directory: ./app
- name: Cypress run
uses: cypress-io/github-action@v5
with:
install: false
start: serve -s build
browser: chrome
working-directory: ./app
cypress-run-firefox:
runs-on: ubuntu-22.04
needs: install-cypress-build
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download the build folder
uses: actions/download-artifact@v3
with:
name: build
path: ./app/build
# Npm run will run the app locally, we want to test the built application with env vars using serve
- name: Install serve globally
run: npm install -g serve
- name: Cypress install
run: |
npm install --legacy-peer-deps
working-directory: ./app
- name: Cypress run
uses: cypress-io/github-action@v5
with:
install: false
start: serve -s build
browser: firefox
working-directory: ./app
env:
CYPRESS_BASE_URL: 'http://localhost:3000'
CYPRESS_RUN_AS_SMOKETEST: false
cypress-run-edge:
runs-on: ubuntu-22.04
needs: install-cypress-build
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download the build folder
uses: actions/download-artifact@v3
with:
name: build
path: ./app/build
# Npm run will run the app locally, we want to test the built application with env vars using serve
- name: Install serve globally
run: npm install -g serve
- name: Cypress install
run: |
npm install --legacy-peer-deps
working-directory: ./app
- name: Cypress run
uses: cypress-io/github-action@v5
with:
install: false
start: serve -s build
browser: edge
working-directory: ./app
env:
CYPRESS_BASE_URL: 'http://localhost:3000'
CYPRESS_RUN_AS_SMOKETEST: false
react_build_and_deploy_docker_image:
runs-on: ubuntu-latest
environment: pre-prod
needs:
[
'cypress-run-edge',
'cypress-run-firefox',
'cypress-run-chrome',
'tag_and_release'
]
defaults:
run:
working-directory: ./app
steps:
- uses: actions/checkout@v3
with:
ref: ${{needs.tag_and_release.outputs.tag}}
fetch-depth: '0'
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }}
role-skip-session-tagging: true
aws-region: ${{ vars.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- uses: dkershner6/aws-ssm-getparameters-action@v1
with:
parameterPairs: '/ndr/${{ vars.BUILD_ENV }}/api_endpoint = DOC_STORE_API_ENDPOINT'
withDecryption: 'true' # defaults to true
- name: Configure React environment vars
env:
ENDPOINT_DOC_STORE_API: ${{ env.DOC_STORE_API_ENDPOINT }}
AWS_REGION: ${{ vars.AWS_REGION }}
OIDC_PROVIDER_ID: not provided yet
BUILD_ENV: ${{ vars.BUILD_ENV }}
IMAGE_VERSION: 'ndr-${{ vars.BUILD_ENV }}-app:${{needs.tag_and_release.outputs.tag}}'
run: |
./react-environment-config.sh
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.AWS_ECR_REPO_NAME }}
IMAGE_TAG: ${{needs.tag_and_release.outputs.tag}}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:latest .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
# Looks like the ECS does not check for image updates, as such we need to force a new task definition to run the new image
# We will always use the "latest" image tag so we do not need to modify the task-definition
- name: Download task definition
id: download-task
run: |
aws ecs describe-task-definition --task-definition ${{ vars.BUILD_ENV }}-ndr-service-task --query taskDefinition > task-definition.json
echo "::set-output name=revision::$(cat task-definition.json | jq .revision)"
- 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: ./app/task-definition.json
container-name: ${{ vars.BUILD_ENV }}-app-container
image: ${{ steps.build-image.outputs.image }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ./app/task-definition.json
service: ${{ vars.BUILD_ENV }}-ecs-cluster-service
cluster: ${{ vars.BUILD_ENV }}-app-cluster
wait-for-service-stability: true
- name: De-register previous revision
run: |
aws ecs deregister-task-definition \
--task-definition ${{ vars.BUILD_ENV }}-ndr-service-task:${{ steps.download-task.outputs.revision }}