-
Notifications
You must be signed in to change notification settings - Fork 0
248 lines (217 loc) · 8.06 KB
/
main.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
name: Build and deploy containers
on:
push:
branches:
- main
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/nginx/Dockerfile
context: ./docker/nginx
submodules: ""
build-frontend: false
name: nginx
build-container: ${{ needs.build-and-test-containers.outputs.nginx == '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@v4
with:
submodules: ${{ matrix.submodules }}
- name: setup docker buildx
uses: docker/setup-buildx-action@v3
- name: configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4.0.1
with:
role-to-assume: ${{ secrets.AWS_BUILD_ROLE }}
role-session-name: github-actions
aws-region: eu-north-1
- name: login to AWS ECR
id: login
uses: aws-actions/amazon-ecr-login@v2
- name: configure NPM credentials
if: ${{ matrix.build-frontend == true && matrix.build-container == true }}
run: |
cat <<EOT >> ./.npmrc
@fortawesome:registry=https://npm.fontawesome.com/
//npm.fontawesome.com/:_authToken=$NPM_TOKEN
EOT
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: install nodejs v20
if: ${{ matrix.build-frontend == true && matrix.build-container == true }}
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: cache node_modules
uses: actions/cache@v3
id: cache-node_modules
with:
path: node_modules
key: ${{ runner.os }}-build-node_v20-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-node_v20-
- name: install npm packages
if: ${{ matrix.build-frontend == true && matrix.build-container == true && steps.cache-node_modules.outputs.cache-hit != 'true'}}
run: npm ci
- name: build frontend with gulp
if: ${{ matrix.build-frontend == true && matrix.build-container == true }}
run: npx gulp
- 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: |
${{ env.REGISTRY }}/${{ env.REPOSITORY }}/${{ matrix.name }}:${{ github.sha }}
${{ env.REGISTRY }}/${{ env.REPOSITORY }}/${{ matrix.name }}:latest
env:
REPOSITORY: ${{ vars.REPOSITORY }}
REGISTRY: ${{ secrets.REGISTRY }}
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@v4
with:
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 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 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.solr == 'true') ||
(needs.build-and-test-containers.outputs.nginx == 'true') ||
(needs.build-and-test-containers.outputs.assets == 'true') }}
run: |
git config user.name "YTP Bot"
git config user.email "yhteentoimivuus.kehittajat@gofore.com"
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-dev:
name: Deploy dev
runs-on: ubuntu-latest
environment: qa
permissions:
id-token: write
contents: read
needs:
- build-and-push
- commit-new-images
steps:
- name: checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.commit-new-images.outputs.sha }}
- name: install nodejs v20
uses: actions/setup-node@v4
with:
node-version: 20
- name: cache node_modules
uses: actions/cache@v3
with:
path: cdk/node_modules
key: ${{ runner.os }}-node_cdk_v20-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node_cdk_v20-
- name: install cdk npm packages and verify installation
working-directory: cdk
run: |
npm install
npx cdk doctor
#- name: build cdk project
# working-directory: cdk
# run: |
# npm run build
- 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: ${{ vars.REPOSITORY }}
- name: configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4.0.1
with:
role-to-assume: ${{ secrets.AWS_DEV_DEPLOY_ROLE }}
role-session-name: github-actions
aws-region: eu-north-1
- name: synthesize cdk stacks
working-directory: cdk
run: |
npx cdk synth *-dev --quiet >/dev/null 2>&1
- name: deploy cdk stacks
working-directory: cdk
run: |
npx cdk deploy *-dev --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: 'avoindata-bot@turina.dvv.fi'
organization-url: 'https://turina.dvv.fi'
to: 'DGA'
type: 'stream'
topic: 'Dev Deployments'
content: 'Dev deployment succeeded! (${{ github.event.head_commit.message }})'