-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
73 lines (51 loc) · 1.56 KB
/
Dockerfile
File metadata and controls
73 lines (51 loc) · 1.56 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
# ---------- Stage 1: Build Go backend ----------
FROM golang:1.26.2 AS backend-build
WORKDIR /app
# Cache dependencies
COPY backend/go.mod backend/go.sum ./
RUN go mod download
RUN go install github.com/a-h/templ/cmd/templ@latest
RUN go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
# Copy backend source
COPY backend/ .
# Generate code from SQL queries
RUN sqlc generate ./sqlc.yml
# Generate HTML templates
RUN templ generate ./internal/views/
# Build static binary
RUN CGO_ENABLED=0 GOOS=linux go build -o /out/app ./cmd/api/main.go
# ---------- Stage 2: Build React frontend with pnpm ----------
FROM node:24 AS frontend-build
WORKDIR /app
# Enable corepack so pnpm is available
RUN corepack enable
# Copy package manager files
COPY frontend/pnpm-lock.yaml frontend/package.json ./
# Install deps
RUN pnpm install --frozen-lockfile
# Copy source and build
COPY frontend/ .
RUN pnpm build
# ---------- Stage 3: Final runtime ----------
FROM alpine:3.20 AS runtime
WORKDIR /app
# Add certs for HTTPS calls
RUN apk --no-cache add ca-certificates
# Copy Go binary
COPY --from=backend-build /out/app ./app
# Copy frontend build
COPY --from=frontend-build /app/dist ./frontend
# Copy backend/public
COPY backend/public ./public
# Environment variables
ENV FRONTEND_DIR=/app/frontend \
IMAGES_DIR=/app/data/images \
CONNECTION_STRING=/app/data/data.db \
ARTICLES_DIR=/app/data/articles \
AUTH_ENABLED=true \
IS_PROD=true \
PORT=8080
# Create data dirs
RUN mkdir -p /app/data/images /app/data/articles
EXPOSE 8080
CMD ["./app"]