This commit is contained in:
root
2026-09-19 20:21:47 +02:00
commit 0798933b05
62 changed files with 7658 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
# syntax=docker/dockerfile:1
# ---- deps: module download, cached until go.mod/go.sum change ----------------
FROM golang:1.25-alpine AS deps
WORKDIR /src
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod go mod download
# ---- test: `docker build --target test .` runs the test suite ----------------
FROM deps AS test
COPY . .
RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build \
go vet ./... && go test ./...
# ---- build: static binaries (SQLite and Postgres drivers are pure Go) --------
FROM deps AS build
COPY . .
ENV CGO_ENABLED=0
RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build \
go build -trimpath -ldflags="-s -w" -o /out/ ./cmd/server ./cmd/daily ./cmd/asm
# ---- final: small runtime image ----------------------------------------------
FROM alpine:3.20
RUN addgroup -S -g 10001 wh && adduser -S -u 10001 -G wh wh \
&& mkdir /data && chown wh:wh /data
COPY --from=build /out/server /out/daily /out/asm /usr/local/bin/
USER wh
WORKDIR /data
# Where the world lives: "sqlite:<path>" or "postgres://user:pass@host/db".
# The default is a SQLite file on the /data volume; override it at run time,
# e.g. -e DATABASE_URL=postgres://... (the -db flag also overrides it).
ENV DATABASE_URL=sqlite:/data/wh.db
VOLUME /data
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s \
CMD wget -q -O /dev/null http://127.0.0.1:8080/info || exit 1
# Default: the API and website. Run one simulated day with:
# docker run --rm -e DATABASE_URL=... <image> daily
CMD ["server"]