aboutsummaryrefslogtreecommitdiff
path: root/Dockerfile
blob: 48979be9e240e5f38a3dcb53e37485e62e9b817b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# ============================================================
#   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"]