-
Notifications
You must be signed in to change notification settings - Fork 0
309 lines (290 loc) · 9.84 KB
/
main.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
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
301
302
303
304
305
306
307
308
309
name: Home Deploy
on:
push:
branches:
- master
pull_request:
branches:
- master
env:
CI: true
NODE_VERSION: 17.x
NODE_ENV: production
UI_IMAGE_ARTEFACT_NAME: "ui-docker-image"
INFRA_APP_LIVE: jtalkme
INFRA_APP_STAGING: jtalkme_staging
INFRA_REPOSITORY: Jtalk/jtalk.me-infrastructure
INFRA_DEPLOY_WORKFLOW: Trigger version update for a service
UI_DOCKER_IMAGE_PREFIX: jtalk/home-ui
API_DOCKER_IMAGE_PREFIX: jtalk/home-api
DBMIGRATE_DOCKER_IMAGE_PREFIX: jtalk/home-dbmigrate
DBBACKUP_DOCKER_IMAGE_PREFIX: jtalk/home-dbbackup
jobs:
build-release-ui:
name: Build and Release UI
runs-on: ubuntu-latest
env:
REACT_APP_VERSION: ${{ github.sha }}
steps:
- uses: actions/checkout@v2
- name: Set up Node.JS ${{ env.NODE_VERSION }}
uses: actions/setup-node@v1
with:
node-version: ${{ env.NODE_VERSION }}
- name: Test UI
working-directory: home2-ui
env:
NODE_ENV: development
run: |
npm ci
npm run test
- name: Build UI
working-directory: home2-ui
run: |
npm run build
npm prune --production
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
if: github.ref == 'refs/heads/master'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker images
uses: docker/build-push-action@v2
with:
context: home2-ui
tags: |
${{ env.UI_DOCKER_IMAGE_PREFIX }}:${{ github.sha }}
${{ env.UI_DOCKER_IMAGE_PREFIX }}:latest
load: true
build-args: |
REACT_APP_VERSION=${{ env.REACT_APP_VERSION }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Push images
if: github.ref == 'refs/heads/master'
run: |
docker push ${{ env.UI_DOCKER_IMAGE_PREFIX }}:${{ github.sha }}
docker push ${{ env.UI_DOCKER_IMAGE_PREFIX }}:latest
- name: Save image for testing
id: export-docker
run: |
docker save "${{ env.UI_DOCKER_IMAGE_PREFIX }}:${{ github.sha }}" -o "${{ env.UI_IMAGE_ARTEFACT_NAME }}"
- uses: actions/upload-artifact@v2
with:
name: ${{ env.UI_IMAGE_ARTEFACT_NAME }}
path: ${{ env.UI_IMAGE_ARTEFACT_NAME }}
if-no-files-found: error
cypress-test-ui:
name: Run Cypress tests on the Docker image
runs-on: ubuntu-latest
needs:
- build-release-ui
env:
NODE_ENV: development
steps:
- uses: actions/checkout@v2
- name: Set up Node.JS ${{ env.NODE_VERSION }}
uses: actions/setup-node@v1
with:
node-version: ${{ env.NODE_VERSION }}
- uses: actions/download-artifact@v2
with:
name: ${{ env.UI_IMAGE_ARTEFACT_NAME }}
- name: Load the pre-build UI docker image
run: |
docker load --input "${{ env.UI_IMAGE_ARTEFACT_NAME }}"
- uses: cypress-io/github-action@v2
with:
browser: firefox
headless: true
working-directory: home2-ui
start: docker run -d --rm --name home-ui-ci -p 8070:80 -e REACT_APP_BUGSNAG_API_KEY= ${{ env.UI_DOCKER_IMAGE_PREFIX }}:${{ github.sha }} npm run start:cypress
wait-on: http://localhost:8070/
wait-on-timeout: 10
record: true
env:
CYPRESS_CI: true
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_DASHBOARD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Cypress Test Cleanup
if: always()
working-directory: home2-ui
run: |
docker logs home-ui-ci
docker stop home-ui-ci
build-release-api:
name: Build and Release the API
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
# Using docker to run tests to optimise build time for dependencies
- name: Test project
uses: docker/build-push-action@v2
with:
context: home2-api
target: test
cache-from: type=gha,scope=api-unit-test
cache-to: type=gha,mode=max,scope=api-unit-test
- name: Login to DockerHub
if: github.ref == 'refs/heads/master'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build project
uses: docker/build-push-action@v2
with:
context: home2-api
load: true
tags: |
api
cache-from: type=gha,scope=api
cache-to: type=gha,mode=max,scope=api
- name: Integration test project (prebuild)
uses: docker/build-push-action@v2
with:
context: home2-api
target: integration-test
load: true
tags: |
integration-test
cache-from: type=gha,scope=integration-test
cache-to: type=gha,mode=max,scope=integration-test
- name: Integration test project
working-directory: home2-api
run: docker-compose up --abort-on-container-exit
- name: Push project
if: github.ref == 'refs/heads/master'
uses: docker/build-push-action@v2
with:
context: home2-api
push: true
tags: |
${{ env.API_DOCKER_IMAGE_PREFIX }}:${{ github.sha }}
${{ env.API_DOCKER_IMAGE_PREFIX }}:latest
cache-from: type=gha,mode=max,scope=api
build-release-backup:
name: Build and Release Database Backup Script
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build and push Docker images
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
path: home2-dbbackup
repository: ${{ env.DBBACKUP_DOCKER_IMAGE_PREFIX }}
tags: ${{ github.sha }}
tag_with_ref: true
tag_with_sha: false
push: ${{ github.ref == 'refs/heads/master' }}
build-release-migrations:
name: Build and Release Database Migrations
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build and push Docker images
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
path: home2-dbmigrate
repository: ${{ env.DBMIGRATE_DOCKER_IMAGE_PREFIX }}
tags: ${{ github.sha }}
tag_with_ref: true
tag_with_sha: false
push: ${{ github.ref == 'refs/heads/master' }}
############################## HELM #############################
build-release-helm:
name: Build and release the app's Helm chart
runs-on: ubuntu-latest
needs:
- build-release-ui
- build-release-api
- build-release-migrations
- build-release-backup
- cypress-test-ui
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v2
- uses: azure/setup-helm@v1
- name: Publish Helm chart
uses: stefanprodan/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
charts_dir: deploy
target_dir: helm
app_version: ${{ github.sha }}
chart_version: 1.0.0-${{ github.sha }}
############################ STAGING ############################
deploy-staging:
name: Deploy the app to staging
runs-on: ubuntu-latest
needs:
- build-release-helm
if: github.ref == 'refs/heads/master'
steps:
- name: Trigger staging pipeline in the terraform repo
uses: aurelien-baudet/workflow-dispatch@v2
with:
workflow: ${{ env.INFRA_DEPLOY_WORKFLOW }}
repo: ${{ env.INFRA_REPOSITORY }}
token: ${{ secrets.GH_PUSH_TOKEN }}
inputs: '{ "name": "${{ env.INFRA_APP_STAGING }}", "version": "${{ github.sha }}" }'
ref: master
wait-for-completion: true
wait-for-completion-timeout: 10m
wait-for-completion-interval: 30s
verify-staging:
name: Verify on staging
runs-on: ubuntu-latest
needs:
- deploy-staging
steps:
- name: Check staging is up
uses: Jtalk/url-health-check-action@v1
with:
url: https://staging.jtalk.me/api/owner|https://staging.jtalk.me/api/blog/articles|https://staging.jtalk.me/api/projects|https://staging.jtalk.me
follow-redirect: true
max-attempts: 5
retry-delay: 5s
############################ LIVE ############################
deploy-live:
name: Deploy the app to live
runs-on: ubuntu-latest
needs:
- build-release-helm
- deploy-staging
- verify-staging
if: github.ref == 'refs/heads/master'
steps:
- name: Trigger staging pipeline in the terraform repo
uses: aurelien-baudet/workflow-dispatch@v2
with:
workflow: ${{ env.INFRA_DEPLOY_WORKFLOW }}
repo: ${{ env.INFRA_REPOSITORY }}
token: ${{ secrets.GH_PUSH_TOKEN }}
inputs: '{ "name": "${{ env.INFRA_APP_LIVE }}", "version": "${{ github.sha }}" }'
ref: master
wait-for-completion: true
wait-for-completion-timeout: 10m
wait-for-completion-interval: 30s
verify-live:
name: Verify on LIVE
runs-on: ubuntu-latest
needs:
- deploy-live
steps:
- name: Check LIVE is up
uses: Jtalk/url-health-check-action@v1
with:
url: https://jtalk.me/api/owner|https://jtalk.me/api/blog/articles|https://jtalk.me/api/projects|https://jtalk.me
follow-redirect: true
max-attempts: 5
retry-delay: 5s