build(docker): run as a non-root user with a read-only root filesystem

- Use the distroless nonroot image and USER 65532
- Make /data the only writable path, owned by the unprivileged user
- Read the config from /etc/parsimony/parsimony.yaml, mounted read-only
- Expose the three listener ports
- Document the run command in the README
This commit is contained in:
tgiachi 2026-11-09 16:11:55 +01:00
commit ccb2940d6e

View file

@ -12,9 +12,16 @@ COPY go.mod go.sum ./
RUN go mod download
COPY . .
COPY --from=admin /src/internal/adminui/dist ./internal/adminui/dist
RUN CGO_ENABLED=0 go build -o /parsimony ./cmd/parsimony
RUN CGO_ENABLED=0 go build -o /parsimony ./cmd/parsimony && mkdir /data
FROM gcr.io/distroless/static-debian12
# Run as the unprivileged "nonroot" user (uid 65532). /data is the only writable path:
# the database and its WAL files live there. A new named volume inherits this ownership;
# for a bind mount, make the host directory writable by uid 65532.
FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /parsimony /parsimony
COPY --from=build --chown=65532:65532 /data /data
VOLUME /data
ENTRYPOINT ["/parsimony", "-config", "/data/parsimony.yaml"]
EXPOSE 2424 8080 8081
USER 65532:65532
# Mount the config read-only at /etc/parsimony/parsimony.yaml; keep "db: /data/parsimony.db" in it.
ENTRYPOINT ["/parsimony", "-config", "/etc/parsimony/parsimony.yaml"]