feat: publish the Docker image for ARM as well
The image is now made for amd64 and for arm64, and each tag (X.Y.Z, X.Y, latest) points at both, so a Raspberry Pi or an ARM NAS pulls the right one. - Dockerfile: the web and Go stages run on the builder and the Go program is cross-compiled (GOARCH from SONDA_ARCH or TARGETARCH); what the image needs besides the program (time zones, the user, the folders) is made in a stage of the builder, so the last stage runs no command and needs no emulation. - release workflow: the runner has no Docker and cannot run ARM, and kaniko takes the base of every stage for one platform, so the arm64 image starts from the arm64 Alpine by digest (found at each release), kaniko builds one image per architecture, and crane sets the architecture of each and joins them under the tags.
This commit is contained in:
parent
dae5118354
commit
b37e3db037
1 changed files with 89 additions and 23 deletions
|
|
@ -2,9 +2,10 @@
|
|||
# 1. semantic-release reads the commits since the last release (Conventional Commits), works out the next version,
|
||||
# writes CHANGELOG.md, makes the release on the forge and tags it. A merge with nothing to release (docs, tests, ci)
|
||||
# makes none.
|
||||
# 2. When there is a release, the image is built from the tag and pushed to git.kmalloc.org/squid/sonda as
|
||||
# X.Y.Z, X.Y and latest.
|
||||
# The runner has no Docker, so the image is built with kaniko, which needs no daemon.
|
||||
# 2. When there is a release, the image is built from the tag, for amd64 and for arm64, and pushed to
|
||||
# git.kmalloc.org/squid/sonda as X.Y.Z-ARCH; then X.Y.Z, X.Y and latest are made to point at both.
|
||||
# The runner has no Docker and cannot emulate another architecture, so the images are built with kaniko, which needs no
|
||||
# daemon, and the Dockerfile crosses to arm64 without running anything for it.
|
||||
# Secret needed: FORGEJO_TOKEN, a token of the owner with the scopes write:repository and write:package.
|
||||
name: release
|
||||
|
||||
|
|
@ -58,16 +59,37 @@ jobs:
|
|||
echo "version=${tag#v}" >> "$GITHUB_OUTPUT"
|
||||
echo "released: ${tag:-nothing}"
|
||||
|
||||
image:
|
||||
# The Alpine of the arm64 image, by digest: kaniko, which has no emulation here, takes the base of every stage for the
|
||||
# platform of the runner, so the last stage is told which one to use.
|
||||
base:
|
||||
needs: release
|
||||
if: ${{ needs.release.outputs.version != '' }}
|
||||
runs-on: docker
|
||||
container:
|
||||
image: gcr.io/go-containerregistry/crane:debug
|
||||
outputs:
|
||||
arm64: ${{ steps.digest.outputs.arm64 }}
|
||||
steps:
|
||||
- id: digest
|
||||
run: echo "arm64=alpine@$(crane digest --platform linux/arm64 alpine:3.22)" >> "$GITHUB_OUTPUT"
|
||||
|
||||
# One image for each architecture. The Go program crosses to the other one with no emulation, and the last stage of the
|
||||
# Dockerfile runs no command (see the Dockerfile).
|
||||
image:
|
||||
needs: [release, base]
|
||||
if: ${{ needs.release.outputs.version != '' }}
|
||||
runs-on: docker
|
||||
strategy:
|
||||
matrix:
|
||||
arch: [amd64, arm64]
|
||||
container:
|
||||
image: gcr.io/kaniko-project/executor:v1.23.2-debug
|
||||
steps:
|
||||
- name: Build the image from the tag and push it
|
||||
- name: Build the image from the tag and push it as X.Y.Z-ARCH
|
||||
env:
|
||||
VERSION: ${{ needs.release.outputs.version }}
|
||||
ARCH: ${{ matrix.arch }}
|
||||
ARM64_BASE: ${{ needs.base.outputs.arm64 }}
|
||||
REGISTRY_USER: squid
|
||||
REGISTRY_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
||||
run: |
|
||||
|
|
@ -75,14 +97,42 @@ jobs:
|
|||
mkdir -p /kaniko/.docker
|
||||
auth="$(printf '%s:%s' "$REGISTRY_USER" "$REGISTRY_TOKEN" | base64 | tr -d '\n')"
|
||||
printf '{"auths":{"git.kmalloc.org":{"auth":"%s"}}}' "$auth" > /kaniko/.docker/config.json
|
||||
image=git.kmalloc.org/squid/sonda
|
||||
minor="${VERSION%.*}"
|
||||
base=alpine:3.22
|
||||
if [ "$ARCH" = arm64 ]; then base="$ARM64_BASE"; fi
|
||||
/kaniko/executor \
|
||||
--dockerfile Dockerfile \
|
||||
--context "git://git.kmalloc.org/squid/sonda.git#refs/tags/v${VERSION}" \
|
||||
--build-arg "VERSION=${VERSION}" \
|
||||
--build-arg "SONDA_ARCH=${ARCH}" \
|
||||
--build-arg "RUNTIME_BASE=${base}" \
|
||||
--label "org.opencontainers.image.version=${VERSION}" \
|
||||
--destination "${image}:${VERSION}" \
|
||||
--destination "${image}:${minor}" \
|
||||
--destination "${image}:latest" \
|
||||
--destination "git.kmalloc.org/squid/sonda:${VERSION}-${ARCH}" \
|
||||
--verbosity info
|
||||
|
||||
# The tags that people use (X.Y.Z, X.Y, latest) point at a list of the two images, so that each machine takes its own.
|
||||
manifest:
|
||||
needs: [release, image]
|
||||
if: ${{ needs.release.outputs.version != '' }}
|
||||
runs-on: docker
|
||||
container:
|
||||
image: gcr.io/go-containerregistry/crane:debug
|
||||
steps:
|
||||
- name: Join the images under X.Y.Z, X.Y and latest
|
||||
env:
|
||||
VERSION: ${{ needs.release.outputs.version }}
|
||||
REGISTRY_USER: squid
|
||||
REGISTRY_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
||||
run: |
|
||||
set -eu
|
||||
image=git.kmalloc.org/squid/sonda
|
||||
crane auth login git.kmalloc.org -u "$REGISTRY_USER" -p "$REGISTRY_TOKEN"
|
||||
# Kaniko writes the architecture of the runner in both images: say the right one for each.
|
||||
for arch in amd64 arm64; do
|
||||
crane mutate "${image}:${VERSION}-${arch}" --set-platform "linux/${arch}" --tag "${image}:${VERSION}-${arch}"
|
||||
done
|
||||
crane index append \
|
||||
--tag "${image}:${VERSION}" \
|
||||
--manifest "${image}:${VERSION}-amd64" \
|
||||
--manifest "${image}:${VERSION}-arm64"
|
||||
crane tag "${image}:${VERSION}" "${VERSION%.*}"
|
||||
crane tag "${image}:${VERSION}" latest
|
||||
|
|
|
|||
Loading…
Reference in a new issue