-
Notifications
You must be signed in to change notification settings - Fork 0
389 lines (340 loc) · 12.9 KB
/
build.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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
name: Build, test and push
permissions:
contents: read
packages: write
security-events: write
on:
workflow_dispatch:
schedule:
- cron: "0 3 * * 3" # Build the preview image every Wednesday at 03:00
release:
types:
- published
push:
branches:
- main
- feature/**
- fix/**
paths:
- .github/**
- docker/**
concurrency:
group: ${{ github.ref }}-publish
cancel-in-progress: true
jobs:
python:
name: Python
runs-on: ubuntu-latest
timeout-minutes: 15
env:
IMAGE_NAME: tna-python
DOCKERFILE_LOCATION: docker/tna-python
BASE_IMAGE: ghcr.io/nationalarchives/tna-python
USER_IMAGE: app
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Lint Dockerfile
uses: ./.github/actions/lint
with:
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
- name: Test Docker image build
id: build
uses: ./.github/actions/test-build
with:
image-name: ${{ env.IMAGE_NAME }}
base-image: ${{ env.BASE_IMAGE }}
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
user-image: ${{ env.USER_IMAGE }}
- name: Test Flask
uses: ./.github/actions/test-container
with:
application-repository: nationalarchives/flask-application-template
service: app
image: ${{ env.IMAGE_NAME }}
image-tag: ${{ steps.build.outputs.tag }}
expected-user: app
- name: Test FastAPI
uses: ./.github/actions/test-container
with:
application-repository: nationalarchives/fastapi-application-template
service: app
image: ${{ env.IMAGE_NAME }}
image-tag: ${{ steps.build.outputs.tag }}
expected-user: app
- name: Build and push Docker images
uses: ./.github/actions/push
with:
image-id: ${{ steps.build.outputs.image-id }}
image-tag: ${{ steps.build.outputs.tag }}
major-version: ${{ steps.build.outputs.major-version }}
minor-version: ${{ steps.build.outputs.minor-version }}
base-image: ${{ env.BASE_IMAGE }}
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
user-image: ${{ env.USER_IMAGE }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Scan Docker image
uses: ./.github/actions/scan
with:
image-id: ${{ steps.build.outputs.image-id }}
image-tag: ${{ steps.build.outputs.tag }}
python-root:
name: Python (root)
runs-on: ubuntu-latest
timeout-minutes: 15
env:
IMAGE_NAME: tna-python-root
DOCKERFILE_LOCATION: docker/tna-python
BASE_IMAGE: ghcr.io/nationalarchives/tna-python
USER_IMAGE: root
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Lint Dockerfile
uses: ./.github/actions/lint
with:
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
ignore-linting-rules: DL3002
- name: Test Docker image build
id: build
uses: ./.github/actions/test-build
with:
image-name: ${{ env.IMAGE_NAME }}
base-image: ${{ env.BASE_IMAGE }}
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
user-image: ${{ env.USER_IMAGE }}
- name: Test Flask
uses: ./.github/actions/test-container
with:
application-repository: nationalarchives/flask-application-template
service: app
image: ${{ env.IMAGE_NAME }}
image-tag: ${{ steps.build.outputs.tag }}
expected-user: root
- name: Test FastAPI
uses: ./.github/actions/test-container
with:
application-repository: nationalarchives/fastapi-application-template
service: app
image: ${{ env.IMAGE_NAME }}
image-tag: ${{ steps.build.outputs.tag }}
expected-user: root
- name: Build and push Docker images
uses: ./.github/actions/push
with:
image-id: ${{ steps.build.outputs.image-id }}
image-tag: ${{ steps.build.outputs.tag }}
major-version: ${{ steps.build.outputs.major-version }}
minor-version: ${{ steps.build.outputs.minor-version }}
base-image: ${{ env.BASE_IMAGE }}
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
user-image: ${{ env.USER_IMAGE }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Scan Docker image
uses: ./.github/actions/scan
with:
image-id: ${{ steps.build.outputs.image-id }}
image-tag: ${{ steps.build.outputs.tag }}
python-django:
name: Python Django
needs: python
runs-on: ubuntu-latest
timeout-minutes: 5
env:
IMAGE_NAME: tna-python-django
DOCKERFILE_LOCATION: docker/tna-python-django
BASE_IMAGE: ghcr.io/nationalarchives/tna-python
USER_IMAGE: root
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Lint Dockerfile
uses: ./.github/actions/lint
with:
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
- name: Test Docker image build
id: build
uses: ./.github/actions/test-build
with:
image-name: ${{ env.IMAGE_NAME }}
base-image: ${{ env.BASE_IMAGE }}
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
user-image: ${{ env.USER_IMAGE }}
- name: Test Django
uses: ./.github/actions/test-container
with:
application-repository: nationalarchives/django-application-template
service: app
image: ${{ env.IMAGE_NAME }}
image-tag: ${{ steps.build.outputs.tag }}
expected-user: app
- name: Build and push Docker images
uses: ./.github/actions/push
with:
image-id: ${{ steps.build.outputs.image-id }}
image-tag: ${{ steps.build.outputs.tag }}
major-version: ${{ steps.build.outputs.major-version }}
minor-version: ${{ steps.build.outputs.minor-version }}
base-image: ${{ env.BASE_IMAGE }}
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
user-image: ${{ env.USER_IMAGE }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Scan Docker image
uses: ./.github/actions/scan
with:
image-id: ${{ steps.build.outputs.image-id }}
image-tag: ${{ steps.build.outputs.tag }}
python-django-root:
name: Python Django (root)
needs: python-root
runs-on: ubuntu-latest
timeout-minutes: 5
env:
IMAGE_NAME: tna-python-django-root
DOCKERFILE_LOCATION: docker/tna-python-django
BASE_IMAGE: ghcr.io/nationalarchives/tna-python-root
USER_IMAGE: root
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Lint Dockerfile
uses: ./.github/actions/lint
with:
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
ignore-linting-rules: DL3002
- name: Test Docker image build
id: build
uses: ./.github/actions/test-build
with:
image-name: ${{ env.IMAGE_NAME }}
base-image: ${{ env.BASE_IMAGE }}
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
user-image: ${{ env.USER_IMAGE }}
- name: Test Django
uses: ./.github/actions/test-container
with:
application-repository: nationalarchives/django-application-template
service: app
image: ${{ env.IMAGE_NAME }}
image-tag: ${{ steps.build.outputs.tag }}
expected-user: root
- name: Build and push Docker images
uses: ./.github/actions/push
with:
image-id: ${{ steps.build.outputs.image-id }}
image-tag: ${{ steps.build.outputs.tag }}
major-version: ${{ steps.build.outputs.major-version }}
minor-version: ${{ steps.build.outputs.minor-version }}
base-image: ${{ env.BASE_IMAGE }}
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
user-image: ${{ env.USER_IMAGE }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Scan Docker image
uses: ./.github/actions/scan
with:
image-id: ${{ steps.build.outputs.image-id }}
image-tag: ${{ steps.build.outputs.tag }}
python-dev:
name: Python Dev
needs: python-root
runs-on: ubuntu-latest
timeout-minutes: 5
env:
IMAGE_NAME: tna-python-dev
DOCKERFILE_LOCATION: docker/tna-python-dev
BASE_IMAGE: ghcr.io/nationalarchives/tna-python-root
USER_IMAGE: root
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Lint Dockerfile
uses: ./.github/actions/lint
with:
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
ignore-linting-rules: DL3002,DL3008,SC1091
- name: Test Docker image build
id: build
uses: ./.github/actions/test-build
with:
image-name: ${{ env.IMAGE_NAME }}
base-image: ${{ env.BASE_IMAGE }}
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
user-image: ${{ env.USER_IMAGE }}
# - uses: actions/setup-node@v4
# - uses: actions/setup-python@v5
# - name: Test development formatting
# run: |
# set +e
# # Install Python linting and formatting tools
# pip install black flake8 isort
# npm i stylelint-config-standard-scss stylelint-selector-bem-pattern
# # Create directories for test files
# mkdir tests
# # Create test files for Prettier
# echo " const foo = 'bar';; const a=foo ;console.log( a) " > tests/test.js
# echo " * { color : red;text-decoration:underline} " > tests/test.css
# echo " \$colour : #ff0000; * { color : \$colour;text-decoration:underline} " > tests/test.scss
# echo " { 'foo' : 'bar'} " > tests/test.json
# # Create test files for Python
# echo "import sys " > tests/test.py
# echo "import datetime " >> tests/test.py
# echo "print( 'test' ) " >> tests/test.py
# # Run the dev container
# docker run -v ./tests:/app/tests --name test_container -d ${{ steps.build.outputs.image-id }}:${{ steps.build.outputs.tag }}
# # Wait for everything to be installed
# echo "Sleeping..."
# # TODO: Improve this
# sleep 30
# # Copy configuration files from container
# docker cp test_container:/home/app/.eslintrc.js .eslintrc.js
# docker cp test_container:/home/app/.flake8 .flake8
# docker cp test_container:/home/app/.isort.cfg .isort.cfg
# docker cp test_container:/home/app/.stylelintrc .stylelintrc
# # Check that Prettier finds issues
# echo "Checking Prettier..."
# npx prettier tests --check; [[ "$?" == "1" ]]
# echo "Checking stylelint..."
# npx stylelint --config .stylelintrc "tests/**/*.{css,scss}"; [[ "$?" == "1" ]]
# echo "Checking eslint..."
# npx [email protected] -c .eslintrc.js "tests"; [[ "$?" == "1" ]]
# # Check that issues are found in Python code
# echo "Checking isort..."
# isort --settings-file .isort.cfg --check tests; [[ "$?" == "1" ]]
# echo "Checking black..."
# black --check tests; [[ "$?" == "1" ]]
# echo "Checking flake8..."
# flake8 --config=.flake8 tests; [[ "$?" == "1" ]]
# set -e
# # Format the code
# echo "Formatting code..."
# docker exec test_container format
# # Check that Prettier finds no issues
# echo "Checking Prettier..."
# npx prettier tests --check
# echo "Checking stylelint..."
# npx stylelint --config .stylelintrc "tests/**/*.{css,scss}"
# echo "Checking eslint..."
# npx [email protected] -c .eslintrc.js "tests"
# # Check that no issues are found in Python code
# echo "Checking isort..."
# isort --settings-file .isort.cfg --check tests
# echo "Checking black..."
# black --check tests
# echo "Checking flake8..."
# flake8 --config=.flake8 tests
- name: Build and push Docker images
uses: ./.github/actions/push
with:
image-id: ${{ steps.build.outputs.image-id }}
image-tag: ${{ steps.build.outputs.tag }}
major-version: ${{ steps.build.outputs.major-version }}
minor-version: ${{ steps.build.outputs.minor-version }}
base-image: ${{ env.BASE_IMAGE }}
dockerfile-location: ${{ env.DOCKERFILE_LOCATION }}
user-image: ${{ env.USER_IMAGE }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Scan Docker image
uses: ./.github/actions/scan
with:
image-id: ${{ steps.build.outputs.image-id }}
image-tag: ${{ steps.build.outputs.tag }}