Skip to content

Commit 9b74753

Browse files
committed
Parallelize main CI jobs
1 parent 192234b commit 9b74753

File tree

1 file changed

+140
-24
lines changed

1 file changed

+140
-24
lines changed

.github/workflows/docker.yml

Lines changed: 140 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,63 +6,179 @@ 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+
# TODO: nanoserver depends on servercore to be
123+
# tagged beforehand, I can't figure it out so
124+
# we'll skip it for now.
125+
include:
126+
- name: core-ltsc2022
127+
constraint: windowsservercore-ltsc2022
128+
runner: windows-2022
129+
# - name: nano-ltsc2022
130+
# constraint: nanoserver-ltsc2022,windowsservercore-ltsc2022
131+
# runner: windows-2022
132+
- name: core-ltsc2025
133+
constraint: windowsservercore-ltsc2025
134+
runner: windows-2025
135+
# - name: nano-ltsc2025
136+
# constraint: nanoserver-ltsc2025,windowsservercore-ltsc2025
137+
# runner: windows-2025
138+
name: windows-build (${{ matrix.name }})
139+
runs-on: ${{ matrix.runner }}
140+
env:
141+
BASHBREW_LIBRARY: ./library
142+
BASHBREW_NAMESPACE: caddy
143+
steps:
144+
- uses: actions/checkout@master
145+
50146
- name: install bashbrew
147+
shell: bash
51148
run: curl -o /bashbrew.exe https://doi-janky.infosiftr.net/job/bashbrew/job/master/lastSuccessfulBuild/artifact/bashbrew-windows-amd64.exe
149+
150+
- name: set constraint args
151+
shell: bash
152+
run: |
153+
constraint="${{ matrix.constraint }}"
154+
if [[ $constraint == *,* ]]; then
155+
IFS=',' read -ra CONSTR <<< "$constraint"
156+
constr_args=""
157+
for c in "${CONSTR[@]}"; do
158+
constr_args="$constr_args --constraint $c"
159+
done
160+
else
161+
constr_args="--constraint $constraint"
162+
fi
163+
echo "CONSTR_ARGS=$constr_args" >> $GITHUB_ENV
164+
52165
- name: build
166+
shell: bash
53167
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
168+
/bashbrew --arch windows-amd64 $CONSTR_ARGS build caddy
169+
56170
- name: push
171+
if: github.repository == 'caddyserver/caddy-docker' && github.ref == 'refs/heads/master'
172+
shell: bash
57173
# NOTE: DOCKERHUB_TOKEN and DOCKERHUB_USERNAME must be present in https://github.com/caddyserver/caddy-docker/settings
58174
# the user must have permission to push to https://hub.docker.com/r/caddy/caddy
59175
run: |
60176
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'
177+
/bashbrew --arch windows-amd64 $CONSTR_ARGS push caddy
178+
64179
- 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
68180
if: github.repository != 'caddyserver/caddy-docker' || github.ref != 'refs/heads/master'
181+
shell: bash
182+
run: |
183+
/bashbrew --arch windows-amd64 $CONSTR_ARGS push --dry-run caddy
184+

0 commit comments

Comments
 (0)