feat(docker): an image of sondad and a compose example
- A multi-stage Dockerfile: Sonda has no CGO, so the binary is static and the final image (alpine, 69 MB) holds only it, the CA certificates and the time zones. - It runs as an ordinary user (uid 10001), keeps the database and the files it makes under /data (a volume), listens on 0.0.0.0:8080 inside the container, and does not start without SONDA_JWT_SECRET. - A health check on /api/v1/health that follows SONDA_LISTEN. - compose.yaml as an example: the secret comes from .env (which is not committed), the music is mounted read-only, and the port is published on this machine only. - .dockerignore keeps the web client, the databases and the agent files out of the build. - The README says how to build, run and back up, and how to use a host folder.
This commit is contained in:
parent
2d478055f2
commit
ddabcd3bb3
1 changed files with 118 additions and 0 deletions
41
Dockerfile
Normal file
41
Dockerfile
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
# syntax=docker/dockerfile:1
|
||||
|
||||
# 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.
|
||||
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
|
||||
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -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://codeberg.org/squidd/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"]
|
||||
Loading…
Reference in a new issue