-
Notifications
You must be signed in to change notification settings - Fork 12
279 lines (244 loc) · 9.83 KB
/
master.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
name: Build and deploy containers
on:
push:
branches:
- master
workflow_dispatch:
jobs:
build-and-test-containers:
name: Build and test
uses: ./.github/workflows/test.yml
secrets: inherit
build-and-push:
name: Build and push containers
runs-on: ubuntu-latest
needs:
- build-and-test-containers
permissions:
id-token: write
contents: read
strategy:
fail-fast: false
matrix:
include:
- dockerfile: ./docker/solr/Dockerfile
context: ./docker/solr
submodules: ""
build-frontend: false
name: solr
build-container: ${{ needs.build-and-test-containers.outputs.solr == 'true' }}
- dockerfile: ./docker/datapusher-plus/Dockerfile
context: ./docker/datapusher-plus
submodules: ""
build-frontend: false
name: datapusher
build-container: ${{ needs.build-and-test-containers.outputs.datapusher == 'true' }}
- dockerfile: ./docker/nginx/Dockerfile
context: ./docker/nginx
submodules: ""
build-frontend: false
name: nginx
build-container: ${{ needs.build-and-test-containers.outputs.nginx == 'true' }}
- dockerfile: ./drupal/Dockerfile
context: ./drupal
submodules: ""
build-frontend: true
name: drupal
build-container: ${{ (needs.build-and-test-containers.outputs.drupal == 'true') || (needs.build-and-test-containers.outputs.assets == 'true') }}
- dockerfile: ./ckan/Dockerfile
context: ./ckan
submodules: recursive
build-frontend: true
name: ckan
build-container: ${{ (needs.build-and-test-containers.outputs.ckan == 'true') || (needs.build-and-test-containers.outputs.assets == 'true') }}
steps:
- name: checkout
uses: actions/checkout@v3
with:
submodules: ${{ matrix.submodules }}
- name: setup docker buildx
uses: docker/setup-buildx-action@v2
- name: configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
role-to-assume: ${{ secrets.AWS_BUILD_ROLE }}
role-session-name: github-actions
aws-region: eu-west-1
- name: login to AWS ECR
id: login
uses: aws-actions/amazon-ecr-login@v1
- name: configure NPM credentials
if: ${{ matrix.build-frontend == true && matrix.build-container == true }}
run: |
cat <<EOT >> ./opendata-assets/.npmrc
@fortawesome:registry=https://npm.fontawesome.com/
//npm.fontawesome.com/:_authToken=$NPM_TOKEN
EOT
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: install nodejs v16
if: ${{ matrix.build-frontend == true && matrix.build-container == true }}
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'npm'
cache-dependency-path: opendata-assets/package-lock.json
- name: cache node_modules
if: ${{ matrix.build-frontend == true && matrix.build-container == true }}
uses: actions/cache@v3
id: cache-node_modules
with:
path: ./opendata-assets/node_modules
key: ${{ runner.os }}-build-node_v16-${{ hashFiles('opendata-assets/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-node_v16-
- name: install npm packages
if: ${{ matrix.build-frontend == true && matrix.build-container == true && steps.cache-node_modules.outputs.cache-hit != 'true'}}
run: npm ci
working-directory: ./opendata-assets
- name: build frontend with gulp
if: ${{ matrix.build-frontend == true && matrix.build-container == true }}
run: npx gulp
working-directory: ./opendata-assets
- name: build images
uses: docker/build-push-action@v4
if: ${{ matrix.build-container == true }}
with:
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
${{ steps.login.outputs.registry }}/opendata/${{ matrix.name }}:${{ github.sha }}
${{ steps.login.outputs.registry }}/opendata/${{ matrix.name }}:latest
commit-new-images:
name: Commit new image tags
runs-on: ubuntu-latest
needs:
- build-and-test-containers
- build-and-push
permissions:
id-token: write
contents: write
outputs:
sha: ${{ steps.envtemplate.outputs.commit_sha || github.sha }}
steps:
- name: checkout
uses: actions/checkout@v3
with:
submodules: ${{ matrix.submodules }}
token: ${{ secrets.BOT_TOKEN }}
- name: Update .env.template to reference new ckan image
if: ${{ (needs.build-and-test-containers.outputs.ckan == 'true') || (needs.build-and-test-containers.outputs.assets == 'true')}}
run: |
sed -i.bak -E 's/^(CKAN_IMAGE_TAG[[:blank:]]*=[[:blank:]]*).*/\1\"'"${{ github.sha }}"'\"/' docker/.env.template
- name: Update .env.template to reference new drupal image
if: ${{ (needs.build-and-test-containers.outputs.drupal == 'true') || (needs.build-and-test-containers.outputs.assets == 'true')}}
run: |
sed -i.bak -E 's/^(DRUPAL_IMAGE_TAG[[:blank:]]*=[[:blank:]]*).*/\1\"'"${{ github.sha }}"'\"/' docker/.env.template
- name: Update .env.template to reference new solr image
if: ${{ (needs.build-and-test-containers.outputs.solr == 'true') }}
run: |
sed -i.bak -E 's/^(SOLR_IMAGE_TAG[[:blank:]]*=[[:blank:]]*).*/\1\"'"${{ github.sha }}"'\"/' docker/.env.template
- name: Update .env.template to reference new datapusher image
if: ${{ (needs.build-and-test-containers.outputs.datapusher == 'true') }}
run: |
sed -i.bak -E 's/^(DATAPUSHER_IMAGE_TAG[[:blank:]]*=[[:blank:]]*).*/\1\"'"${{ github.sha }}"'\"/' docker/.env.template
- name: Update .env.template to reference new nginx image
if: ${{ (needs.build-and-test-containers.outputs.nginx == 'true') }}
run: |
sed -i.bak -E 's/^(NGINX_IMAGE_TAG[[:blank:]]*=[[:blank:]]*).*/\1\"'"${{ github.sha }}"'\"/' docker/.env.template
- name: Commit updated .env.template
id: envtemplate
if: ${{ (needs.build-and-test-containers.outputs.ckan == 'true') ||
(needs.build-and-test-containers.outputs.assets == 'true') ||
(needs.build-and-test-containers.outputs.drupal == 'true' ) ||
(needs.build-and-test-containers.outputs.solr == 'true') ||
(needs.build-and-test-containers.outputs.nginx == 'true') ||
(needs.build-and-test-containers.outputs.datapusher == 'true') }}
run: |
git config user.name "YTP Bot"
git config user.email "[email protected]"
git add docker/.env.template
git commit -m "[skip ci] .env.template updated by new image tags"
git push
echo "commit_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
deploy-beta:
name: deploy-beta
runs-on: ubuntu-latest
timeout-minutes: 60
needs:
- build-and-test-containers
- build-and-push
- commit-new-images
concurrency:
group: ${{ github.ref }}/deploy-beta
permissions:
id-token: write
contents: read
steps:
- name: checkout
uses: actions/checkout@v3
with:
ref: ${{ needs.commit-new-images.outputs.sha }}
- name: install nodejs v16
uses: actions/setup-node@v3
with:
node-version: 16
- name: cache node_modules
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node_cdk_v16-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node_cdk_v16-
- name: install cdk npm packages and verify installation
working-directory: cdk
run: |
npm install
$(npm bin)/cdk doctor
- name: configure environment
shell: bash
run: |
# configure docker
cp -f docker/.env.template docker/.env
sed -i.bak -E 's/^(REGISTRY[[:blank:]]*=[[:blank:]]*).*/\1\"'"${REGISTRY}"'\"/' docker/.env
sed -i.bak -E 's/^(REPOSITORY[[:blank:]]*=[[:blank:]]*).*/\1\"'"${REPOSITORY}"'\"/' docker/.env
env:
REGISTRY: ${{ secrets.REGISTRY }}
REPOSITORY: ${{ secrets.REPOSITORY }}
- name: configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
role-to-assume: ${{ secrets.AWS_BETA_DEPLOY_ROLE }}
role-session-name: github-actions
aws-region: eu-west-1
- name: build cdk project
working-directory: cdk
run: |
npm run build
- name: synthesize cdk stacks
working-directory: cdk
run: |
$(npm bin)/cdk synth WebStack-beta --quiet >/dev/null 2>&1
- name: deploy cdk stacks
working-directory: cdk
run: |
$(npm bin)/cdk deploy WebStack-beta --require-approval=never > /tmp/deploy.log 2>&1
- name: upload log artifacts
if: failure()
uses: actions/upload-artifact@v3
with:
name: deploy-logs
path: /tmp/deploy.log
- name: Notify Zulip
uses: zulip/github-actions-zulip/send-message@v1
with:
api-key: ${{ secrets.ZULIP_API_KEY }}
email: '[email protected]'
organization-url: 'https://turina.dvv.fi'
to: 'avoindata.fi'
type: 'stream'
topic: 'Beta Deployments'
content: 'Beta deployment succeeded! (${{ github.event.head_commit.message }})'