Merge pull request 'Docker image for ARM as well' (#40) from feat/arm64-image into main
All checks were successful
release / release (push) Successful in 36s
release / base (push) Successful in 2s
release / image (amd64) (push) Successful in 3m11s
release / image (arm64) (push) Successful in 3m11s
release / manifest (push) Successful in 2s

This commit is contained in:
squid 2026-11-16 13:33:56 +00:00
commit 2e194da4e3
3 changed files with 89 additions and 23 deletions

View file

@ -2,9 +2,10 @@
# 1. semantic-release reads the commits since the last release (Conventional Commits), works out the next version, # 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) # writes CHANGELOG.md, makes the release on the forge and tags it. A merge with nothing to release (docs, tests, ci)
# makes none. # makes none.
# 2. When there is a release, the image is built from the tag and pushed to git.kmalloc.org/squid/sonda as # 2. When there is a release, the image is built from the tag, for amd64 and for arm64, and pushed to
# X.Y.Z, X.Y and latest. # 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, so the image is built with kaniko, which needs no daemon. # 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. # Secret needed: FORGEJO_TOKEN, a token of the owner with the scopes write:repository and write:package.
name: release name: release
@ -58,16 +59,37 @@ jobs:
echo "version=${tag#v}" >> "$GITHUB_OUTPUT" echo "version=${tag#v}" >> "$GITHUB_OUTPUT"
echo "released: ${tag:-nothing}" 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 needs: release
if: ${{ needs.release.outputs.version != '' }} if: ${{ needs.release.outputs.version != '' }}
runs-on: docker 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: container:
image: gcr.io/kaniko-project/executor:v1.23.2-debug image: gcr.io/kaniko-project/executor:v1.23.2-debug
steps: 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: env:
VERSION: ${{ needs.release.outputs.version }} VERSION: ${{ needs.release.outputs.version }}
ARCH: ${{ matrix.arch }}
ARM64_BASE: ${{ needs.base.outputs.arm64 }}
REGISTRY_USER: squid REGISTRY_USER: squid
REGISTRY_TOKEN: ${{ secrets.FORGEJO_TOKEN }} REGISTRY_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
run: | run: |
@ -75,14 +97,42 @@ jobs:
mkdir -p /kaniko/.docker mkdir -p /kaniko/.docker
auth="$(printf '%s:%s' "$REGISTRY_USER" "$REGISTRY_TOKEN" | base64 | tr -d '\n')" auth="$(printf '%s:%s' "$REGISTRY_USER" "$REGISTRY_TOKEN" | base64 | tr -d '\n')"
printf '{"auths":{"git.kmalloc.org":{"auth":"%s"}}}' "$auth" > /kaniko/.docker/config.json printf '{"auths":{"git.kmalloc.org":{"auth":"%s"}}}' "$auth" > /kaniko/.docker/config.json
image=git.kmalloc.org/squid/sonda base=alpine:3.22
minor="${VERSION%.*}" if [ "$ARCH" = arm64 ]; then base="$ARM64_BASE"; fi
/kaniko/executor \ /kaniko/executor \
--dockerfile Dockerfile \ --dockerfile Dockerfile \
--context "git://git.kmalloc.org/squid/sonda.git#refs/tags/v${VERSION}" \ --context "git://git.kmalloc.org/squid/sonda.git#refs/tags/v${VERSION}" \
--build-arg "VERSION=${VERSION}" \ --build-arg "VERSION=${VERSION}" \
--build-arg "SONDA_ARCH=${ARCH}" \
--build-arg "RUNTIME_BASE=${base}" \
--label "org.opencontainers.image.version=${VERSION}" \ --label "org.opencontainers.image.version=${VERSION}" \
--destination "${image}:${VERSION}" \ --destination "git.kmalloc.org/squid/sonda:${VERSION}-${ARCH}" \
--destination "${image}:${minor}" \
--destination "${image}:latest" \
--verbosity info --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

View file

@ -1,8 +1,11 @@
# syntax=docker/dockerfile:1 # syntax=docker/dockerfile:1
# RUNTIME_BASE is alpine:3.22 unless the CI release asks for another architecture, with the digest of that one.
ARG RUNTIME_BASE=alpine:3.22
# The web app: built once here, written (by its Vite config) to /src/internal/webui/dist, where the Go # The web app: built once here, written (by its Vite config) to /src/internal/webui/dist, where the Go
# build below embeds it. Nothing of Node reaches the final image. # build below embeds it. Nothing of Node reaches the final image.
FROM node:24-alpine AS web FROM --platform=$BUILDPLATFORM node:24-alpine AS web
WORKDIR /src/web WORKDIR /src/web
COPY web/package.json web/package-lock.json ./ COPY web/package.json web/package-lock.json ./
RUN npm ci RUN npm ci
@ -12,7 +15,13 @@ RUN npm run build
# Build: Sonda has no CGO (SQLite, PostgreSQL and the tag reader are pure Go), so the binary # Build: Sonda has no CGO (SQLite, PostgreSQL and the tag reader are pure Go), so the binary
# is static and the final image needs nothing but it and the CA certificates. The web app is inside it # is static and the final image needs nothing but it and the CA certificates. The web app is inside it
# (-tags webui), so sondad serves it on / and the API on /api. # (-tags webui), so sondad serves it on / and the API on /api.
FROM golang:1.27-alpine AS build FROM --platform=$BUILDPLATFORM golang:1.27-alpine AS build
# Built on the machine that builds, for the machine that runs: Go crosses to another architecture with no emulation
# (TARGETOS and TARGETARCH come from the platform asked for).
ARG TARGETOS
ARG TARGETARCH
# SONDA_ARCH is for a builder that cannot say TARGETARCH (the CI release, see .forgejo/workflows/release.yml).
ARG SONDA_ARCH
WORKDIR /src WORKDIR /src
COPY go.mod go.sum ./ COPY go.mod go.sum ./
RUN go mod download RUN go mod download
@ -22,19 +31,26 @@ COPY migrations ./migrations
COPY --from=web /src/internal/webui/dist ./internal/webui/dist COPY --from=web /src/internal/webui/dist ./internal/webui/dist
# The version of the release (see .releaserc.json), as GET /version and the User-Agent of the providers say it. # The version of the release (see .releaserc.json), as GET /version and the User-Agent of the providers say it.
ARG VERSION=dev ARG VERSION=dev
RUN CGO_ENABLED=0 go build -tags webui -trimpath -ldflags="-s -w -X main.version=${VERSION}" -o /out/sondad ./cmd/sondad RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${SONDA_ARCH:-${TARGETARCH:-amd64}} go build -tags webui -trimpath -ldflags="-s -w -X main.version=${VERSION}" -o /out/sondad ./cmd/sondad
FROM alpine:3.22 # What the image has besides the program (the zones of tzdata, the user, the folders) is made here, on the machine that
# builds. The last stage then runs no command, so it can be built for another architecture with no emulation.
FROM --platform=$BUILDPLATFORM alpine:3.22 AS rootfs
RUN apk add --no-cache tzdata \
&& addgroup -S -g 10001 sonda \
&& adduser -S -u 10001 -G sonda -h /data -H sonda \
&& mkdir -p /out/data /out/music
FROM ${RUNTIME_BASE}
LABEL org.opencontainers.image.title="Sonda" \ LABEL org.opencontainers.image.title="Sonda" \
org.opencontainers.image.description="A privacy-first, self-hosted music server" \ org.opencontainers.image.description="A privacy-first, self-hosted music server" \
org.opencontainers.image.source="https://git.kmalloc.org/squid/sonda" org.opencontainers.image.source="https://git.kmalloc.org/squid/sonda"
# ca-certificates: the providers an admin may switch on are reached over https. # The certificates of alpine (ca-certificates-bundle) are what the providers an admin may switch on are reached with,
# tzdata: log times in the zone the operator sets with TZ. # over https. tzdata is for the log times in the zone the operator sets with TZ.
RUN apk add --no-cache ca-certificates tzdata \ COPY --from=rootfs /usr/share/zoneinfo /usr/share/zoneinfo
&& addgroup -S -g 10001 sonda \ COPY --from=rootfs /etc/passwd /etc/group /etc/shadow /etc/
&& adduser -S -u 10001 -G sonda -h /data -H sonda \ COPY --from=rootfs --chown=10001:10001 /out/data /data
&& mkdir -p /data /music \ COPY --from=rootfs /out/music /music
&& chown sonda:sonda /data
COPY --from=build /out/sondad /usr/local/bin/sondad COPY --from=build /out/sondad /usr/local/bin/sondad
# Everything Sonda writes is under /data: the database and the files it makes (covers, pictures). # Everything Sonda writes is under /data: the database and the files it makes (covers, pictures).

View file

@ -65,7 +65,7 @@ A plain `go build -o bin/sondad ./cmd/sondad` needs no Node and gives the API on
The image holds `sondad` with the web app inside, and nothing else: it builds the app itself, so you need no Node on your machine. It runs as an ordinary user, keeps the database and the files Sonda makes under `/data`, listens on port 8080 inside the container, and does not start without `SONDA_JWT_SECRET`. The image holds `sondad` with the web app inside, and nothing else: it builds the app itself, so you need no Node on your machine. It runs as an ordinary user, keeps the database and the files Sonda makes under `/data`, listens on port 8080 inside the container, and does not start without `SONDA_JWT_SECRET`.
The image is published on the registry of git.kmalloc.org, so you do not have to build it: `git.kmalloc.org/squid/sonda:latest` is the last one, and `git.kmalloc.org/squid/sonda:<commit>` (the first seven characters of a commit of `main`) is one you can stay on. Anyone can pull it, with no login. To build it yourself instead, run `docker build -t sonda .` and use `sonda` where the commands below say `git.kmalloc.org/squid/sonda:latest`. The image is published on the registry of git.kmalloc.org, so you do not have to build it: `git.kmalloc.org/squid/sonda:latest` is the last one, and `git.kmalloc.org/squid/sonda:0.3.0` (a version from [CHANGELOG.md](CHANGELOG.md)) is one you can stay on. It runs on amd64 and on arm64 (a Raspberry Pi, an ARM NAS): one tag gives each machine its own. Anyone can pull it, with no login. To build it yourself instead, run `docker build -t sonda .` and use `sonda` where the commands below say `git.kmalloc.org/squid/sonda:latest`.
```bash ```bash
docker pull git.kmalloc.org/squid/sonda:latest docker pull git.kmalloc.org/squid/sonda:latest
@ -415,7 +415,7 @@ Every merge into `main` can make a release, by itself (`.forgejo/workflows/relea
| `feat!: ...`, or `BREAKING CHANGE:` in the body | major (0.2.0 to 1.0.0) | | `feat!: ...`, or `BREAKING CHANGE:` in the body | major (0.2.0 to 1.0.0) |
| `docs:`, `test:`, `chore:`, `ci:`, `style:` | none by themselves | | `docs:`, `test:`, `chore:`, `ci:`, `style:` | none by themselves |
A release adds its entry to [CHANGELOG.md](CHANGELOG.md), tags the commit (`v0.3.0`), makes the release on the forge, and the image is built from the tag and pushed to `git.kmalloc.org/squid/sonda` as `0.3.0`, `0.3` and `latest`. The version is inside the binary: `GET /version` and the User-Agent of the providers say it (a build that no release made says `dev`). The commit that writes `CHANGELOG.md` says `[skip ci]`. The runner has no Docker, so the image is built with [kaniko](https://github.com/GoogleContainerTools/kaniko). The workflow needs the secret `FORGEJO_TOKEN`: a token of the owner with the scopes `write:repository` and `write:package`. A release adds its entry to [CHANGELOG.md](CHANGELOG.md), tags the commit (`v0.3.0`), makes the release on the forge, and the image is built from the tag and pushed to `git.kmalloc.org/squid/sonda` as `0.3.0`, `0.3` and `latest`. The version is inside the binary: `GET /version` and the User-Agent of the providers say it (a build that no release made says `dev`). The commit that writes `CHANGELOG.md` says `[skip ci]`. The image is made for amd64 and for arm64, and each tag points at both. The runner has no Docker and cannot emulate ARM, so the images are built with [kaniko](https://github.com/GoogleContainerTools/kaniko): the Go program is compiled for ARM with no emulation, the last stage of the Dockerfile runs no command, and a last job (with [crane](https://github.com/google/go-containerregistry)) says the architecture of each image and joins them. The workflow needs the secret `FORGEJO_TOKEN`: a token of the owner with the scopes `write:repository` and `write:package`.
## Development ## Development