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
38
Dockerfile
38
Dockerfile
|
|
@ -1,8 +1,11 @@
|
|||
# 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 node:24-alpine AS web
|
||||
FROM --platform=$BUILDPLATFORM node:24-alpine AS web
|
||||
WORKDIR /src/web
|
||||
COPY web/package.json web/package-lock.json ./
|
||||
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
|
||||
# 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 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
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
|
@ -22,19 +31,26 @@ 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 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" \
|
||||
org.opencontainers.image.description="A privacy-first, self-hosted music server" \
|
||||
org.opencontainers.image.source="https://git.kmalloc.org/squid/sonda"
|
||||
# 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
|
||||
# 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
|
||||
COPY --from=build /out/sondad /usr/local/bin/sondad
|
||||
|
||||
# Everything Sonda writes is under /data: the database and the files it makes (covers, pictures).
|
||||
|
|
|
|||
Loading…
Reference in a new issue