Skip to content

Commit 20f6fa4

Browse files
committed
Parallelize main CI jobs
1 parent db417da commit 20f6fa4

File tree

1 file changed

+111
-24
lines changed

1 file changed

+111
-24
lines changed

.github/workflows/docker.yml

Lines changed: 111 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,63 +6,150 @@ on:
66
pull_request:
77

88
jobs:
9-
docker-linux-build:
9+
# Parallelized: run quick docker build tests per-Dockerfile in parallel
10+
linux-test:
1011
runs-on: ubuntu-latest
1112
container:
1213
image: hairyhenderson/dockerfiles-builder:latest
1314
env:
1415
BASHBREW_LIBRARY: ./library
1516
BASHBREW_NAMESPACE: caddy
1617
DOCKER_BUILDKIT: '1'
18+
strategy:
19+
matrix:
20+
path:
21+
- 2.10/alpine
22+
- 2.10/builder
23+
- 2.11/alpine
24+
- 2.11/builder
1725
steps:
1826
- uses: actions/checkout@master
19-
- name: non-master build test
20-
run: |
21-
docker build -f 2.10/alpine/Dockerfile 2.10/alpine
22-
docker build -f 2.10/builder/Dockerfile 2.10/builder
27+
- name: non-master build test (per-path)
2328
if: github.repository != 'caddyserver/caddy-docker' || github.ref != 'refs/heads/master'
29+
run: |
30+
docker build -f ${{ matrix.path }}/Dockerfile ${{ matrix.path }}
31+
32+
# Main linux bashbrew build.
33+
linux-build:
34+
runs-on: ubuntu-latest
35+
container:
36+
image: hairyhenderson/dockerfiles-builder:latest
37+
env:
38+
BASHBREW_LIBRARY: ./library
39+
BASHBREW_NAMESPACE: caddy
40+
DOCKER_BUILDKIT: '1'
41+
steps:
42+
- uses: actions/checkout@master
43+
2444
- name: build
2545
run: bashbrew build caddy
46+
2647
- name: push
48+
if: github.repository == 'caddyserver/caddy-docker' && github.ref == 'refs/heads/master'
2749
# NOTE: DOCKERHUB_TOKEN and DOCKERHUB_USERNAME must be present in https://github.com/caddyserver/caddy-docker/settings
2850
# the user must have permission to push to https://hub.docker.com/r/caddy/caddy
2951
run: |
3052
echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login --username ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
3153
bashbrew push caddy
32-
if: github.repository == 'caddyserver/caddy-docker' && github.ref == 'refs/heads/master'
54+
3355
- name: push (non-master dry run)
56+
if: github.repository != 'caddyserver/caddy-docker' || github.ref != 'refs/heads/master'
3457
run: |
3558
bashbrew push --dry-run caddy
36-
if: github.repository != 'caddyserver/caddy-docker' || github.ref != 'refs/heads/master'
3759
38-
docker-windows-build:
39-
runs-on: windows-2022
40-
# env:
41-
# BASHBREW_LIBRARY: ./library
42-
# BASHBREW_NAMESPACE: caddy
60+
61+
# Parallelized: run quick windows docker build tests per-Dockerfile in parallel
62+
windows-test:
63+
strategy:
64+
matrix:
65+
include:
66+
- version: 2.10
67+
os: ltsc2022
68+
runner: windows-2022
69+
- version: 2.10
70+
os: ltsc2025
71+
runner: windows-2025
72+
- version: 2.11
73+
os: ltsc2022
74+
runner: windows-2022
75+
- version: 2.11
76+
os: ltsc2025
77+
runner: windows-2025
78+
name: windows-test (${{ matrix.version }}/windows/${{ matrix.os }})
79+
runs-on: ${{ matrix.runner }}
4380
steps:
4481
- uses: actions/checkout@master
45-
- name: non-master build test
46-
run: |
47-
docker build -f 2.10/windows/ltsc2022/Dockerfile 2.10/windows/ltsc2022
48-
docker build -f 2.10/windows-nanoserver/ltsc2022/Dockerfile 2.10/windows-nanoserver/ltsc2022
82+
- name: non-master build test (per-path)
4983
if: github.repository != 'caddyserver/caddy-docker' || github.ref != 'refs/heads/master'
84+
shell: pwsh
85+
run: |
86+
$path = "${{ matrix.version }}/windows/${{ matrix.os }}"
87+
$nanopath = "${{ matrix.version }}/windows-nanoserver/${{ matrix.os }}"
88+
Write-Host "Building test for $path"
89+
90+
# Early-exit: if there's no nanoserver Dockerfile for this version/os,
91+
# just build the servercore Dockerfile and finish early.
92+
if (-not (Test-Path "$nanopath\Dockerfile")) {
93+
Write-Host "No nanoserver Dockerfile at $nanopath; building servercore only"
94+
docker build -f "$path\Dockerfile" "$path"
95+
exit 0
96+
}
97+
98+
# nanoserver Dockerfile exists — parse it for the referenced servercore tag.
99+
$nanoDockerfile = Get-Content "$nanopath\Dockerfile" -Raw
100+
if (-not ($nanoDockerfile -match 'COPY\s+--from=caddy:([^\s]+)')) {
101+
throw "Could not find 'COPY --from=caddy:<tag>' in $nanopath/Dockerfile; aborting nanoserver test."
102+
}
103+
104+
$referencedTag = $Matches[1]
105+
Write-Host "Found nanoserver copy-from tag: $referencedTag"
106+
107+
# Ensure the servercore Dockerfile exists and build/tag it so nanoserver can COPY from it.
108+
$servercorePath = $path
109+
if (-not (Test-Path "$servercorePath\Dockerfile")) {
110+
throw "Expected servercore Dockerfile at $servercorePath not found; cannot prepare nanoserver build."
111+
}
112+
113+
Write-Host "Building and tagging servercore image at $servercorePath as caddy:$referencedTag"
114+
docker build -t "caddy:$referencedTag" -f "$servercorePath\Dockerfile" "$servercorePath"
115+
Write-Host "Building nanoserver image at $nanopath"
116+
docker build -f "$nanopath\Dockerfile" "$nanopath"
117+
118+
# Main windows build (matrix over constraints) - runs after tests
119+
windows-build:
120+
strategy:
121+
matrix:
122+
include:
123+
- constraint: windowsservercore-ltsc2022
124+
runner: windows-2022
125+
- constraint: nanoserver-ltsc2022
126+
runner: windows-2022
127+
- constraint: windowsservercore-ltsc2025
128+
runner: windows-2025
129+
- constraint: nanoserver-ltsc2025
130+
runner: windows-2025
131+
name: windows-build (${{ matrix.constraint }})
132+
runs-on: ${{ matrix.runner }}
133+
steps:
134+
- uses: actions/checkout@master
135+
50136
- name: install bashbrew
51137
run: curl -o /bashbrew.exe https://doi-janky.infosiftr.net/job/bashbrew/job/master/lastSuccessfulBuild/artifact/bashbrew-windows-amd64.exe
138+
52139
- name: build
53140
run: |
54-
/bashbrew --arch windows-amd64 --constraint windowsservercore-ltsc2022 --namespace caddy --library ./library build caddy;
55-
/bashbrew --arch windows-amd64 --constraint windowsnanoserver-ltsc2022 --namespace caddy --library ./library build caddy
141+
/bashbrew --arch windows-amd64 --constraint ${{ matrix.constraint }} --namespace caddy --library ./library build caddy
142+
56143
- name: push
144+
if: github.repository == 'caddyserver/caddy-docker' && github.ref == 'refs/heads/master'
57145
# NOTE: DOCKERHUB_TOKEN and DOCKERHUB_USERNAME must be present in https://github.com/caddyserver/caddy-docker/settings
58146
# the user must have permission to push to https://hub.docker.com/r/caddy/caddy
59147
run: |
60148
echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login --username ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin;
61-
/bashbrew --arch windows-amd64 --constraint windowsservercore-ltsc2022 --namespace caddy --library ./library push caddy;
62-
/bashbrew --arch windows-amd64 --constraint windowsnanoserver-ltsc2022 --namespace caddy --library ./library push caddy
63-
if: github.repository == 'caddyserver/caddy-docker' && github.ref == 'refs/heads/master'
149+
/bashbrew --arch windows-amd64 --constraint ${{ matrix.constraint }} --namespace caddy --library ./library push caddy
150+
64151
- name: push (non-master dry run)
65-
run: |
66-
/bashbrew --arch windows-amd64 --constraint windowsservercore-ltsc2022 --namespace caddy --library ./library push --dry-run caddy;
67-
/bashbrew --arch windows-amd64 --constraint windowsnanoserver-ltsc2022 --namespace caddy --library ./library push --dry-run caddy
68152
if: github.repository != 'caddyserver/caddy-docker' || github.ref != 'refs/heads/master'
153+
run: |
154+
/bashbrew --arch windows-amd64 --constraint ${{ matrix.constraint }} --namespace caddy --library ./library push --dry-run caddy
155+

0 commit comments

Comments
 (0)