diff options
| author | zwlucas <lucas.fariamo08@gmail.com> | 2026-05-29 21:24:59 +0000 |
|---|---|---|
| committer | zwlucas <lucas.fariamo08@gmail.com> | 2026-05-29 21:24:59 +0000 |
| commit | bf8b1d0d49703e82cf8162399405984bd0b3fe88 (patch) | |
| tree | af4ed5fb7feae49cb3ebe1c8c3f87831e53b8273 /Dockerfile | |
| parent | 17b159c563278c3b3b8b3884be37f8d5025ce0c7 (diff) | |
| download | yaum-bf8b1d0d49703e82cf8162399405984bd0b3fe88.tar.gz yaum-bf8b1d0d49703e82cf8162399405984bd0b3fe88.zip | |
feat: implement static file serving and Docker support, update frontend build process
Signed-off-by: zwlucas <lucas.fariamo08@gmail.com>
Diffstat (limited to 'Dockerfile')
| -rw-r--r-- | Dockerfile | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..48979be --- /dev/null +++ b/Dockerfile @@ -0,0 +1,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"] |