sonda/Dockerfile
tgiachi a478c95536 ci: release by itself at every merge, with semantic-release
At every merge into main a workflow reads the Conventional Commits since the last release,
works out the version, writes CHANGELOG.md, tags the commit and makes the release on the
forge; when there is a release it builds the image from the tag and pushes it 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.

The version is no longer written in the code: the release sets it (-X main.version) in the
Dockerfile and the Makefile, and a build that no release made says dev.
2026-11-16 13:07:17 +01:00

54 lines
2.3 KiB
Docker

# syntax=docker/dockerfile:1
# 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
WORKDIR /src/web
COPY web/package.json web/package-lock.json ./
RUN npm ci
COPY web ./
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
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY cmd ./cmd
COPY internal ./internal
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
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"
# 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).
# The music is mounted, read-only, wherever you like (/music is a convention); a library is added
# through the API with its path inside the container. SONDA_JWT_SECRET has no default and is
# required: the server does not start without it.
ENV SONDA_LISTEN=0.0.0.0:8080 \
SONDA_DB_PATH=/data/sonda.db \
SONDA_DATA_DIR=/data/files \
SONDA_ENV=production
WORKDIR /data
USER sonda
VOLUME /data
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=3s --start-period=15s --retries=3 \
CMD wget -qO /dev/null "http://127.0.0.1:${SONDA_LISTEN##*:}/api/v1/health" || exit 1
ENTRYPOINT ["sondad"]