-
-
Notifications
You must be signed in to change notification settings - Fork 8
509 lines (473 loc) · 19.1 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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
name: build
on:
schedule:
- cron: '*/30 * * * *'
issue_comment:
types: [created]
workflow_dispatch:
push:
paths:
- '.github/workflows/build.yml'
- 'docker/hugo/**'
concurrency:
group: "docker"
cancel-in-progress: false
env:
PLATFORMS: linux/amd64,linux/arm64
IMAGE_OWNER: hugomods
IMAGE_NAME: hugo
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
jobs:
build-and-push-image:
strategy:
fail-fast: false
matrix:
version: ['', 'std-'] # empty string and `std-` represent extended and standard version of Hugo.
user: ['root', 'hugo'] # default container user.
prefix:
- ''
- 'base-'
- 'ci-'
- 'dart-sass-'
- 'dart-sass-base-'
- 'dart-sass-git-'
- 'dart-sass-go-'
- 'dart-sass-go-git-'
- 'dart-sass-node-'
- 'dart-sass-node-git-'
- 'exts-'
- 'git-'
- 'go-'
- 'go-git-'
- 'node-'
- 'node-git-'
- 'node-lts-'
# Tags placeholders:
# 0: the image owner.
# 1: the image name.
# 2: the Hugo version without leading v.
# 3: standard (std-) or extended (empty string) indicator.
# 4: root user (empty string) or non-root user indicator.
include:
- version: ''
prefix: ''
user: 'root'
dockerfile: Dockerfile
tags: |
{0}/{1}:latest
{0}/{1}:{2}
ghcr.io/{0}/{1}:latest
ghcr.io/{0}/{1}:{2}
- version: ''
prefix: ''
user: 'hugo'
dockerfile: Dockerfile
tags: |
{0}/{1}:non-root
{0}/{1}:non-root-{2}
ghcr.io/{0}/{1}:non-root
ghcr.io/{0}/{1}:non-root-{2}
- version: 'std-'
prefix: ''
dockerfile: Dockerfile
tags: |
{0}/{1}:std{4}
{0}/{1}:std{4}-{2}
ghcr.io/{0}/{1}:std{4}
ghcr.io/{0}/{1}:std{4}-{2}
{0}/{1}:reg{4}
{0}/{1}:reg{4}-{2}
ghcr.io/{0}/{1}:reg{4}
ghcr.io/{0}/{1}:reg{4}-{2}
- prefix: base-
dockerfile: Dockerfile-base
tags: |
{0}/{1}:{3}base{4}
{0}/{1}:{3}base{4}-{2}
ghcr.io/{0}/{1}:{3}base{4}
ghcr.io/{0}/{1}:{3}base{4}-{2}
- prefix: ci-
dockerfile: Dockerfile-ci
tags: |
{0}/{1}:{3}ci{4}
{0}/{1}:{3}ci{4}-{2}
ghcr.io/{0}/{1}:{3}ci{4}
ghcr.io/{0}/{1}:{3}ci{4}-{2}
- prefix: dart-sass-
dockerfile: Dockerfile-dart-sass
tags: |
{0}/{1}:{3}dart-sass{4}
{0}/{1}:{3}dart-sass{4}-{2}
ghcr.io/{0}/{1}:{3}dart-sass{4}
ghcr.io/{0}/{1}:{3}dart-sass{4}-{2}
- prefix: dart-sass-base-
dockerfile: Dockerfile-dart-sass-base
tags: |
{0}/{1}:{3}dart-sass-base{4}
{0}/{1}:{3}dart-sass-base{4}-{2}
ghcr.io/{0}/{1}:{3}dart-sass-base{4}
ghcr.io/{0}/{1}:{3}dart-sass-base{4}-{2}
- prefix: dart-sass-git-
dockerfile: Dockerfile-dart-sass-git
tags: |
{0}/{1}:{3}dart-sass-git{4}
{0}/{1}:{3}dart-sass-git{4}-{2}
ghcr.io/{0}/{1}:{3}dart-sass-git{4}
ghcr.io/{0}/{1}:{3}dart-sass-git{4}-{2}
- prefix: dart-sass-go-
dockerfile: Dockerfile-dart-sass-go
tags: |
{0}/{1}:{3}dart-sass-go{4}
{0}/{1}:{3}dart-sass-go{4}-{2}
ghcr.io/{0}/{1}:{3}dart-sass-go{4}
ghcr.io/{0}/{1}:{3}dart-sass-go{4}-{2}
- prefix: dart-sass-go-git-
dockerfile: Dockerfile-dart-sass-go-git
tags: |
{0}/{1}:{3}dart-sass-go-git{4}
{0}/{1}:{3}dart-sass-go-git{4}-{2}
ghcr.io/{0}/{1}:{3}dart-sass-go-git{4}
ghcr.io/{0}/{1}:{3}dart-sass-go-git{4}-{2}
- prefix: dart-sass-node-
dockerfile: Dockerfile-dart-sass-node
tags: |
{0}/{1}:{3}dart-sass-node{4}
{0}/{1}:{3}dart-sass-node{4}-{2}
ghcr.io/{0}/{1}:{3}dart-sass-node{4}
ghcr.io/{0}/{1}:{3}dart-sass-node{4}-{2}
- prefix: dart-sass-node-git-
dockerfile: Dockerfile-dart-sass-node-git
tags: |
{0}/{1}:{3}dart-sass-node-git{4}
{0}/{1}:{3}dart-sass-node-git{4}-{2}
ghcr.io/{0}/{1}:{3}dart-sass-node-git{4}
ghcr.io/{0}/{1}:{3}dart-sass-node-git{4}-{2}
- prefix: git-
dockerfile: Dockerfile-git
tags: |
{0}/{1}:{3}git{4}
{0}/{1}:{3}git{4}-{2}
ghcr.io/{0}/{1}:{3}git{4}
ghcr.io/{0}/{1}:{3}git{4}-{2}
- prefix: go-
dockerfile: Dockerfile-go
tags: |
{0}/{1}:{3}go{4}
{0}/{1}:{3}go{4}-{2}
ghcr.io/{0}/{1}:{3}go{4}
ghcr.io/{0}/{1}:{3}go{4}-{2}
- prefix: go-git-
dockerfile: Dockerfile-go-git
tags: |
{0}/{1}:{3}go-git{4}
{0}/{1}:{3}go-git{4}-{2}
ghcr.io/{0}/{1}:{3}go-git{4}
ghcr.io/{0}/{1}:{3}go-git{4}-{2}
- prefix: node-
dockerfile: Dockerfile-node
tags: |
{0}/{1}:{3}node{4}
{0}/{1}:{3}node{4}-{2}
ghcr.io/{0}/{1}:{3}node{4}
ghcr.io/{0}/{1}:{3}node{4}-{2}
- prefix: node-git-
dockerfile: Dockerfile-node-git
tags: |
{0}/{1}:{3}node-git{4}
{0}/{1}:{3}node-git{4}-{2}
ghcr.io/{0}/{1}:{3}node-git{4}
ghcr.io/{0}/{1}:{3}node-git{4}-{2}
- prefix: node-lts-
dockerfile: Dockerfile-node-lts
tags: |
{0}/{1}:{3}node-lts{4}
{0}/{1}:{3}node-lts{4}-{2}
ghcr.io/{0}/{1}:{3}node-lts{4}
ghcr.io/{0}/{1}:{3}node-lts{4}-{2}
- prefix: exts-
dockerfile: Dockerfile-exts
tags: |
{0}/{1}:{3}exts{4}
{0}/{1}:{3}exts{4}-{2}
ghcr.io/{0}/{1}:{3}exts{4}
ghcr.io/{0}/{1}:{3}exts{4}-{2}
# build tags
- version: ''
build_tags: 'extended'
- version: ''
prefix: 'ci-'
build_tags: 'extended,withdeploy'
- version: 'std-'
prefix: 'ci-'
build_tags: 'withdeploy'
runs-on: ubuntu-latest
if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event_name == 'push' || github.event.issue.number == 3 }}
steps:
- name: Fetch latest Hugo release
id: release
uses: razonyang/github-action-github-latest-release@v1
with:
owner: gohugoio
name: hugo
prefix: v
- name: Check if the image tag exists
if: steps.release.outputs.version
id: check-image-tag
uses: razonyang/github-action-docker-image-tag-exists@v1
with:
owner: ${{ env.IMAGE_OWNER }}
name: ${{ env.IMAGE_NAME }}
tag: ${{ matrix.version }}${{ matrix.prefix }}${{ steps.release.outputs.version }}
# The `build` is `true` on when the image tag doesn't exist or the commit message contains the word `[build]`.
- id: needs-build
if: steps.release.outputs.version
name: Check if there is a need to build images.
run: |
if [[ ${{ steps.check-image-tag.outputs.exists }} == 0 || "${{ github.event.head_commit.message }}" == *"[build]"* ]]; \
then echo "build=1"; \
else echo "build=0"; \
fi \
>> $GITHUB_OUTPUT;
# Checkout the main repository.
- name: Checkout repository
if: steps.needs-build.outputs.build == true
uses: actions/checkout@v4
# Checkout the Hugo repository for building.
- name: Checkout Hugo repository
if: steps.needs-build.outputs.build == true
uses: actions/checkout@v4
with:
repository: gohugoio/hugo
ref: v${{ steps.release.outputs.version }}
path: ./docker/hugo/src
- name: Build meta
id: build_meta
if: steps.needs-build.outputs.build == true
run: |
echo "date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_OUTPUT
cd ./docker/hugo/src && echo "hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: LDFLAGS
id: ldflags
if: steps.needs-build.outputs.build == true
run: |
HASH='github.com/gohugoio/hugo/common/hugo.commitHash=${{ steps.build_meta.outputs.hash }}'
BUILD_DATE='github.com/gohugoio/hugo/common/hugo.buildDate=${{ steps.build_meta.outputs.date }}'
VENDOR='github.com/gohugoio/hugo/common/hugo.vendorInfo=hugomods'
echo "-X '$HASH' -X '$BUILD_DATE' -X '$VENDOR'"
echo "flags=-X '$HASH' -X '$BUILD_DATE' -X '$VENDOR'">> $GITHUB_OUTPUT
- name: Set up QEMU
if: steps.needs-build.outputs.build == true
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ env.PLATFORMS }}
- name: Set up Docker Buildx
if: steps.needs-build.outputs.build == true
uses: docker/setup-buildx-action@v3
with:
platforms: ${{ env.PLATFORMS }}
- name: Build and export to Docker
if: steps.needs-build.outputs.build == true
uses: docker/build-push-action@v5
with:
load: true
context: docker/hugo
file: docker/hugo/${{ matrix.dockerfile }}
tags: hugomods/hugo:test
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
LDFLAGS=${{ steps.ldflags.outputs.flags }}
HUGO_VERSION=v${{ steps.release.outputs.version }}
BUILD_TAGS=${{ matrix.build_tags }}
USER=${{ matrix.user }}
- id: hugo-version
name: Save Hugo version for subsequent tests.
if: steps.needs-build.outputs.build == true
run: echo "version=$(docker run --rm hugomods/hugo:test hugo version)" >> $GITHUB_OUTPUT
- name: Check Hugo version
if: steps.needs-build.outputs.build == true
run: |
if [[ "${{ steps.hugo-version.outputs.version }}" != *"v${{ steps.release.outputs.version }}"* ]];
then
echo "Expected Hugo version "v${{ steps.release.outputs.version }}", but got "${{ steps.hugo-version.outputs.version }}"." && exit 1;
fi
- name: Check Hugo edition
if: steps.needs-build.outputs.build == true
run: |
if [[ "${{ matrix.version }}" == "std-" && "${{ steps.hugo-version.outputs.version }}" == *"extended"* ]];
then
echo "Expected standard edition of Hugo, got "${{ steps.hugo-version.outputs.version }}"." && exit 1;
elif [[ "${{ matrix.version }}" == "" && "${{ steps.hugo-version.outputs.version }}" != *"extended"* ]]
then
echo "Expected extended edition of Hugo, got "${{ steps.hugo-version.outputs.version }}"." && exit 1;
fi
- name: Check Vendor Info
if: steps.needs-build.outputs.build == true
run: |
if [[ "${{ steps.hugo-version.outputs.version }}" != *"VendorInfo=hugomods"* ]];
then
echo "Expected vendor "hugomods", got "${{ steps.hugo-version.outputs.version }}"." && exit 1;
fi
- name: Check working directory
if: steps.needs-build.outputs.build == true
run: |
TEST_PWD=$(docker run --rm -v $PWD/site:/src hugomods/hugo:test pwd)
if [[ "$TEST_PWD" != "/src" ]];
then
echo "Expected working directory \"/src\", got \"$TEST_PWD\"." && exit 1;
fi
- name: Check /src ownership
if: steps.needs-build.outputs.build == true
run: |
SRC_OWNER=$(docker run --rm hugomods/hugo:test stat -c "%U:%G" /src)
if [[ "$SRC_OWNER" != "hugo:hugo" ]];
then
echo "Expected the owner of \"/src\" to be "hugo:hugo", got \"$SRC_OWNER\"." && exit 1;
fi
- name: Check default user
if: steps.needs-build.outputs.build == true
run: |
TEST_WHOAMI=$(docker run --rm -v $PWD/site:/src hugomods/hugo:test whoami)
if [[ "$TEST_WHOAMI" != "${{ matrix.user }}" ]];
then
echo "Expected default user \"${{ matrix.user }}\", got \"$TEST_WHOAMI\"." && exit 1;
fi
- name: Check the hugo user ID
if: steps.needs-build.outputs.build == true
run: |
TEST_UID=$(docker run --rm -v $PWD/site:/src hugomods/hugo:test id -u hugo)
if [[ "$TEST_UID" != "1000" ]];
then
echo "Expected UID \"1000\", got \"$TEST_UID\"." && exit 1;
fi
- name: Check the hugo user group ID
if: steps.needs-build.outputs.build == true
run: |
TEST_GID=$(docker run --rm -v $PWD/site:/src hugomods/hugo:test id -g hugo)
if [[ "$TEST_GID" != "1000" ]];
then
echo "Expected GID \"1000\", got \"$TEST_GID\"." && exit 1;
fi
- name: Change permission of site to build with non-root image
if: steps.needs-build.outputs.build == true && matrix.user == 'hugo'
run: chmod a+w $PWD/site
- name: Test site build
if: steps.needs-build.outputs.build == true
run: |
docker run --rm -v $PWD/site:/src hugomods/hugo:test hugo
env:
IMAGE_PREFIX: ${{ matrix.prefix }}
- name: Test Extra Markdown Handlers
if: steps.needs-build.outputs.build == true &&
contains(fromJson('["ci-", "exts-"]'), matrix.prefix)
run: |
docker run --rm -v $PWD/site:/src hugomods/hugo:test hugo --config config.yaml,config-markdown-handlers.yaml
env:
IMAGE_PREFIX: ${{ matrix.prefix }}
- name: Check Git installation
if: |
steps.needs-build.outputs.build == true &&
contains(fromJson('["", "ci-", "dart-sass-", "dart-sass-git-", "dart-sass-go-git-", "dart-sass-node-git-", "git-", "node-git-", "go-git-", "exts-"]'), matrix.prefix)
run: docker run --rm hugomods/hugo:test git version
- name: Test site build with --enableGitInfo
if: |
steps.needs-build.outputs.build == true &&
contains(fromJson('["", "ci-", "dart-sass-", "dart-sass-git-", "dart-sass-go-git-", "dart-sass-node-git-", "git-", "node-git-", "go-git-", "exts-"]'), matrix.prefix)
run: >-
docker run --rm
-v $PWD/site:/src
hugomods/hugo:test
/bin/sh -c "
if [[ "${{ matrix.user }}" == "hugo" ]]; then git config --global --add safe.directory /src; fi &&
git init &&
git add -A &&
git config --global user.email "[email protected]" &&
git config --global user.name "HugoMods" &&
git commit -m 'Test commit' &&
hugo --enableGitInfo"
- name: Check Hugo server binding
if: steps.needs-build.outputs.build == true
run: >-
HUGO_SERVER_OUTPUT=$(docker run --rm -v $PWD/site:/src hugomods/hugo:test sh -c "server > server.out & sleep 5 && cat server.out") &&
echo $HUGO_SERVER_OUTPUT &&
if [[ $HUGO_SERVER_OUTPUT != *"bind address 0.0.0.0"* ]]; then echo "Expected bind "0.0.0.0" by default." && exit 1; fi
env:
IMAGE_PREFIX: ${{ matrix.prefix }}
- name: Check Go installation
if: |
steps.needs-build.outputs.build == true &&
contains(fromJson('["", "ci-", "dart-sass-", "dart-sass-go-", "dart-sass-go-git-", "go-", "go-git-", "exts-"]'), matrix.prefix)
run: docker run --rm hugomods/hugo:test go version
- name: Check Node.js, NPM and Yarn installation
if: |
steps.needs-build.outputs.build == true &&
contains(fromJson('["", "ci-", "dart-sass-", "dart-sass-node-", "dart-sass-node-git-", "node-", "node-git-", "node-lts-", "exts-"]'), matrix.prefix)
run: docker run --rm hugomods/hugo:test node -v && npm version && yarn -v
- name: Check PostCSS, PurgeCSS, Autoprefixer and RTLCSS
if: |
steps.needs-build.outputs.build == true &&
contains(fromJson('["ci-", "exts-"]'), matrix.prefix)
run: >-
docker run --rm
-v $PWD/tests/postcss:/src
hugomods/hugo:test
postcss ./main.css
- name: Check CI tools
if: |
steps.needs-build.outputs.build == true &&
contains(fromJson('["ci-"]'), matrix.prefix)
run: >-
docker run --rm
hugomods/hugo:test
sh -c "hugo deploy -h &&
curl --version &&
jq --version &&
htmlproofer -v"
- name: Login to Docker Hub
if: ${{ steps.needs-build.outputs.build == true && env.BRANCH_NAME == 'main' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
if: ${{ steps.needs-build.outputs.build == true && env.BRANCH_NAME == 'main' }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ env.IMAGE_OWNER }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: User tag suffix
id: user-tag
if: ${{ steps.needs-build.outputs.build == true }}
run: |
if [[ ${{ matrix.user }} == "hugo" ]]; \
then echo "suffix=-non-root"; \
else echo "suffix="; \
fi \
>> $GITHUB_OUTPUT;
- name: Build and push
if: steps.needs-build.outputs.build == true
uses: docker/build-push-action@v5
with:
push: ${{ env.BRANCH_NAME == 'main' }}
context: docker/hugo
platforms: ${{ env.PLATFORMS }}
file: docker/hugo/${{ matrix.dockerfile }}
# Reserve reg* variants for backwards compatibility.
tags: >
${{
(matrix.version == 'std-' && matrix.prefix != '') &&
format(
'{0}{1}',
format(matrix.tags, env.IMAGE_OWNER, env.IMAGE_NAME, steps.release.outputs.version, matrix.version, steps.user-tag.outputs.suffix),
format(matrix.tags, env.IMAGE_OWNER, env.IMAGE_NAME, steps.release.outputs.version, 'reg-', steps.user-tag.outputs.suffix)
) ||
format(matrix.tags, env.IMAGE_OWNER, env.IMAGE_NAME, steps.release.outputs.version, matrix.version, steps.user-tag.outputs.suffix)
}}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
LDFLAGS=${{ steps.ldflags.outputs.flags }}
HUGO_VERSION=v${{ steps.release.outputs.version }}
BUILD_TAGS=${{ matrix.build_tags }}
USER=${{ matrix.user }}