Skip to content

Commit 6b54c99

Browse files
authored
Merge pull request #18 from netresearch/fix/build-runtime-target
fix: build the runtime stage, not whatever comes last
2 parents 62923f0 + 879eb73 commit 6b54c99

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

.github/workflows/build.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ jobs:
9494
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
9595
with:
9696
context: .
97+
# Named explicitly. Without it Docker builds the LAST stage in the
98+
# Dockerfile, and adding the web stage after runtime silently turned
99+
# this build into the nginx one - php-fpm:latest was published as
100+
# nginx until the smoke test on main caught it on /bin/bash.
101+
target: runtime
97102
# A pull request builds one architecture and keeps it local: `--load`
98103
# cannot import a manifest list, so asking for both there fails with
99104
# "docker exporter does not currently support exporting manifest
@@ -117,6 +122,21 @@ jobs:
117122
sbom: ${{ github.event_name != 'pull_request' }}
118123
provenance: ${{ github.event_name != 'pull_request' && 'mode=max' || 'false' }}
119124

125+
# The smoke test would have caught a swapped image, but it is a separate
126+
# job and the pull-request build never leaves this runner, so it only
127+
# runs on main - which is where the wrong image had already been
128+
# published. This asserts the identity of what was just built, in the
129+
# job that builds it, where a missing `target:` actually goes wrong.
130+
- name: The image is php-fpm, not the web stage
131+
if: github.event_name == 'pull_request'
132+
env:
133+
TAGS: ${{ steps.meta.outputs.tags }}
134+
run: |
135+
set -euo pipefail
136+
tag="$(printf '%s\n' "$TAGS" | head -n1)"
137+
docker run --rm --entrypoint sh "$tag" -c \
138+
'command -v php-fpm >/dev/null && test -x /bin/bash && ! command -v nginx >/dev/null'
139+
120140
- name: Attest the build
121141
if: github.event_name != 'pull_request'
122142
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
@@ -166,6 +186,16 @@ jobs:
166186
sbom: ${{ github.event_name != 'pull_request' }}
167187
provenance: ${{ github.event_name != 'pull_request' && 'mode=max' || 'false' }}
168188

189+
- name: The web image is nginx, not the runtime stage
190+
if: github.event_name == 'pull_request'
191+
env:
192+
TAGS: ${{ steps.meta-web.outputs.tags }}
193+
run: |
194+
set -euo pipefail
195+
tag="$(printf '%s\n' "$TAGS" | head -n1)"
196+
docker run --rm --entrypoint sh "$tag" -c \
197+
'command -v nginx >/dev/null && ! command -v php-fpm >/dev/null'
198+
169199
- name: Attest the build (web)
170200
if: github.event_name != 'pull_request'
171201
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2

0 commit comments

Comments
 (0)