40 lines
1.4 KiB
Docker
40 lines
1.4 KiB
Docker
# syntax=docker/dockerfile:1
|
|
|
|
# --- Stage 1: build the web frontend (web/dist) -----------------------------
|
|
FROM node:22-bookworm-slim AS web
|
|
WORKDIR /web
|
|
# Install deps first for better layer caching. --include=dev is explicit so the
|
|
# build works even if NODE_ENV=production leaks in (vite/tsc are devDependencies).
|
|
COPY web/package.json web/package-lock.json ./
|
|
RUN npm ci --include=dev
|
|
COPY web/ ./
|
|
RUN npm run build
|
|
|
|
# --- Stage 2: build the Go server binary ------------------------------------
|
|
FROM golang:1.25-bookworm AS go
|
|
WORKDIR /src
|
|
# Cache module downloads separately from the source.
|
|
COPY go.mod go.sum ./
|
|
RUN go mod download
|
|
COPY . .
|
|
# modernc.org/sqlite is pure Go, so we can build a fully static binary.
|
|
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/server ./cmd/server
|
|
|
|
# --- Stage 3: minimal runtime image -----------------------------------------
|
|
FROM debian:bookworm-slim AS runtime
|
|
RUN apt-get update \
|
|
&& apt-get install -y --no-install-recommends ca-certificates \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
WORKDIR /app
|
|
COPY --from=go /out/server /app/server
|
|
COPY --from=web /web/dist /app/web/dist
|
|
|
|
# The server reads these at runtime (see cmd/server/main.go). DATA_DIR should be
|
|
# backed by a Dokku persistent volume so the SQLite DB survives redeploys.
|
|
ENV STATIC_DIR=/app/web/dist \
|
|
DATA_DIR=/app/data \
|
|
PORT=8080
|
|
EXPOSE 8080
|
|
|
|
CMD ["/app/server"]
|