Merge pull request 'ci: build the image once instead of twice' (#5) from ci/one-build-not-two into main

Reviewed-on: #5
This commit was merged in pull request #5.
This commit is contained in:
2026-08-24 17:32:01 +01:00
+30 -19
View File
@@ -45,7 +45,8 @@ jobs:
# The suite runs inside the image, against the ffmpeg that ships, rather # The suite runs inside the image, against the ffmpeg that ships, rather
# than against whatever the runner happens to provide. A failing test # than against whatever the runner happens to provide. A failing test
# fails the build. Layers are shared with the push build below. # fails the build. The runtime stage below is built from the same daemon
# afterwards, so its layers are already in cache.
- name: Run the test suite inside the image - name: Run the test suite inside the image
run: docker build --target test -t music-mirror:test . run: docker build --target test -t music-mirror:test .
@@ -124,9 +125,6 @@ jobs:
echo "release=${release}" >> "$GITHUB_OUTPUT" echo "release=${release}" >> "$GITHUB_OUTPUT"
echo "Computed bump=${bump}, release=${release}, base=${base}" echo "Computed bump=${bump}, release=${release}, base=${base}"
- name: Set up Buildx
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4
- name: Log in to the Gitea container registry - name: Log in to the Gitea container registry
if: github.event_name != 'pull_request' if: github.event_name != 'pull_request'
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4 uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4
@@ -135,21 +133,34 @@ jobs:
username: ${{ github.repository_owner }} username: ${{ github.repository_owner }}
password: ${{ secrets.PACKAGES_TOKEN }} password: ${{ secrets.PACKAGES_TOKEN }}
- name: Build and push # Plain `docker build` rather than buildx. buildx boots its own buildkit
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7 # in a container with a cache of its own, so it shared nothing with the
with: # test build above and rebuilt the image from the base up -- installing
context: . # ffmpeg and the package a second time, for nothing. It earns that cost
# Without this the last stage in the Dockerfile -- the test stage -- # when building for several platforms; this only ever targets the amd64
# would be what gets published. # NAS, so it does not.
target: runtime #
# The NAS is the only host this runs on. Building arm64 as well would # `--target runtime` is a strict prefix of the test stage, so every layer
# mean emulating it under QEMU for no consumer. # is already in the daemon's cache and this resolves in seconds.
platforms: linux/amd64 - name: Build the runtime image
push: ${{ github.event_name != 'pull_request' }} run: |
tags: ${{ steps.version.outputs.tags }} set -euo pipefail
labels: | tags=()
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} while IFS= read -r tag; do
org.opencontainers.image.revision=${{ github.sha }} [ -n "$tag" ] && tags+=(-t "$tag")
done <<< "${{ steps.version.outputs.tags }}"
docker build --target runtime \
--label "org.opencontainers.image.source=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" \
--label "org.opencontainers.image.revision=${GITHUB_SHA}" \
"${tags[@]}" .
- name: Push
if: github.event_name != 'pull_request'
run: |
set -euo pipefail
while IFS= read -r tag; do
[ -n "$tag" ] && docker push "$tag"
done <<< "${{ steps.version.outputs.tags }}"
# Record the release: write the computed version into pyproject.toml, then # Record the release: write the computed version into pyproject.toml, then
# commit and tag it, so the packaging metadata always matches the release # commit and tag it, so the packaging metadata always matches the release