# ============================================================ # YAUM — Multistage Docker Build # Produces an ~20 MB single-binary image with zero runtime # dependencies (Go + SvelteKit frontend embedded). # ============================================================ # ───────────────────────────────────────────────────────────── # Stage 1: Build the SvelteKit frontend (static export) # ───────────────────────────────────────────────────────────── FROM node:20-alpine AS frontend-builder WORKDIR /build/frontend # Install dependencies (layer cached while package*.json stay the same) COPY frontend/package.json frontend/package-lock.json* ./ RUN npm ci # Copy source and build COPY frontend/ ./ RUN npm run build # Result: /build/frontend/build/ (200.html, _app/, …) # ───────────────────────────────────────────────────────────── # Stage 2: Compile the Go backend with the frontend embedded # ───────────────────────────────────────────────────────────── FROM golang:1.25-alpine AS backend-builder WORKDIR /build # Copy backend source COPY backend/ ./backend/ # Copy the static export from Stage 1 into the Go embed directory COPY --from=frontend-builder /build/frontend/build/ ./backend/internal/static/build/ # Build a fully static binary (no libc, no external deps) WORKDIR /build/backend RUN CGO_ENABLED=0 \ GOOS=linux \ GOARCH=amd64 \ go build \ -ldflags="-s -w" \ -o /app/yaum \ ./cmd/server/ # ───────────────────────────────────────────────────────────── # Stage 3: Minimal runtime image # ───────────────────────────────────────────────────────────── FROM alpine:3.20 # CA certificates so Go can verify TLS on monitored HTTPS URLs RUN apk add --no-cache ca-certificates tzdata COPY --from=backend-builder /app/yaum /app/yaum # Default port; can be overridden at runtime via config.json or env EXPOSE 8080 WORKDIR /app CMD ["/app/yaum"]