diff --git a/.forgejo/workflows/release.yml b/.forgejo/workflows/release.yml index 023f628..54ccf33 100644 --- a/.forgejo/workflows/release.yml +++ b/.forgejo/workflows/release.yml @@ -2,10 +2,9 @@ # 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, 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. +# 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. # Secret needed: FORGEJO_TOKEN, a token of the owner with the scopes write:repository and write:package. name: release @@ -59,37 +58,16 @@ jobs: echo "version=${tag#v}" >> "$GITHUB_OUTPUT" echo "released: ${tag:-nothing}" - # 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: + image: 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 as X.Y.Z-ARCH + - name: Build the image from the tag and push it env: VERSION: ${{ needs.release.outputs.version }} - ARCH: ${{ matrix.arch }} - ARM64_BASE: ${{ needs.base.outputs.arm64 }} REGISTRY_USER: squid REGISTRY_TOKEN: ${{ secrets.FORGEJO_TOKEN }} run: | @@ -97,42 +75,14 @@ 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 - base=alpine:3.22 - if [ "$ARCH" = arm64 ]; then base="$ARM64_BASE"; fi + image=git.kmalloc.org/squid/sonda + minor="${VERSION%.*}" /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 "git.kmalloc.org/squid/sonda:${VERSION}-${ARCH}" \ + --destination "${image}:${VERSION}" \ + --destination "${image}:${minor}" \ + --destination "${image}:latest" \ --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 diff --git a/CHANGELOG.md b/CHANGELOG.md index dcd1e3b..2eb38a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,5 @@ # Changelog -## [0.3.0](https://git.kmalloc.org/squid/sonda/compare/v0.2.0...v0.3.0) (2026-11-16) - -### Features - -* publish the Docker image for ARM as well ([b37e3db](https://git.kmalloc.org/squid/sonda/commit/b37e3db037a442af439c5183cf4937a9be630a14)) - ## [0.2.0](https://git.kmalloc.org/squid/sonda/compare/v0.1.0...v0.2.0) (2026-11-16) ### Features diff --git a/Dockerfile b/Dockerfile index 786dc20..6afce61 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,8 @@ # 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 # build below embeds it. Nothing of Node reaches the final image. -FROM --platform=$BUILDPLATFORM node:24-alpine AS web +FROM node:24-alpine AS web WORKDIR /src/web COPY web/package.json web/package-lock.json ./ RUN npm ci @@ -15,13 +12,7 @@ RUN npm run build # 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 # (-tags webui), so sondad serves it on / and the API on /api. -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 +FROM golang:1.27-alpine AS build WORKDIR /src COPY go.mod go.sum ./ RUN go mod download @@ -31,26 +22,19 @@ COPY migrations ./migrations 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. ARG VERSION=dev -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 +RUN CGO_ENABLED=0 go build -tags webui -trimpath -ldflags="-s -w -X main.version=${VERSION}" -o /out/sondad ./cmd/sondad -# 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} +FROM alpine:3.22 LABEL org.opencontainers.image.title="Sonda" \ org.opencontainers.image.description="A privacy-first, self-hosted music server" \ org.opencontainers.image.source="https://git.kmalloc.org/squid/sonda" -# The certificates of alpine (ca-certificates-bundle) are what the providers an admin may switch on are reached with, -# over https. tzdata is for the log times in the zone the operator sets with TZ. -COPY --from=rootfs /usr/share/zoneinfo /usr/share/zoneinfo -COPY --from=rootfs /etc/passwd /etc/group /etc/shadow /etc/ -COPY --from=rootfs --chown=10001:10001 /out/data /data -COPY --from=rootfs /out/music /music +# ca-certificates: the providers an admin may switch on are reached over https. +# tzdata: log times in the zone the operator sets with TZ. +RUN apk add --no-cache ca-certificates tzdata \ + && addgroup -S -g 10001 sonda \ + && adduser -S -u 10001 -G sonda -h /data -H sonda \ + && mkdir -p /data /music \ + && chown sonda:sonda /data COPY --from=build /out/sondad /usr/local/bin/sondad # Everything Sonda writes is under /data: the database and the files it makes (covers, pictures). diff --git a/README.md b/README.md index be49736..6ccb018 100644 --- a/README.md +++ b/README.md @@ -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 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`. +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:` (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`. ```bash 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) | | `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 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`. +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`. ## Development