# ---- Stage 1: Build Go binaries ---- FROM docker.io/golang:1.25-bookworm AS go-builder WORKDIR /build # Copy module files first for layer caching COPY go.mod go.sum ./ RUN go mod download # Copy source and build COPY templates templates COPY handlers handlers COPY internal internal COPY *.go ./ COPY cmd cmd RUN CGO_ENABLED=1 go build -o /app ./main.go \ && CGO_ENABLED=1 go build -o /orgadmin ./cmd/orgadmin # ---- Stage 2: Build frontend ---- FROM docker.io/node:22-bookworm AS frontend-builder WORKDIR /build # Copy package files first for layer caching COPY frontend/package.json frontend/package-lock.json ./ RUN npm ci --ignore-scripts COPY frontend ./ RUN npm run build # ---- Stage 3: Runtime ---- FROM docker.io/debian:bookworm-slim RUN apt-get update && \ apt-get install -y --no-install-recommends \ ca-certificates \ poppler-utils \ imagemagick \ libgs10 \ libgomp1 \ && rm -rf /var/lib/apt/lists/* WORKDIR /app # Copy built artifacts from earlier stages COPY --from=go-builder /app ./app COPY --from=go-builder /orgadmin ./orgadmin COPY --from=frontend-builder /build/dist ./frontend/dist # Copy non-binary assets COPY templates ./templates COPY static ./static COPY prompts ./prompts EXPOSE 8080 VOLUME ["/app/data"] CMD ["./app"]