Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
56 lines (45 loc) · 2.03 KB
/
Copy pathDockerfile
File metadata and controls
56 lines (45 loc) · 2.03 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
# Stage 1: Build frontend
FROM node:22.23.1-alpine AS frontend
WORKDIR /app/client/web
COPY client/web/package.json client/web/package-lock.json ./
RUN npm ci
COPY client/web/ ./
# Shown in the Settings dialog; vite.config.ts reads it from the repo root.
COPY version.txt /app/version.txt
ARG VITE_GOOGLE_AUTH_ENABLED=true
ENV VITE_GOOGLE_AUTH_ENABLED=$VITE_GOOGLE_AUTH_ENABLED
RUN npm run build
# Stage 2: Build backend
FROM golang:1.27.3 AS builder
WORKDIR /app
COPY go.mod go.sum ./
# proxy.golang.org intermittently resets HTTP/2 streams mid-zip from Cloud
# Build's egress, failing the deploy on whichever module was in flight
# ("stream error: stream ID N; INTERNAL_ERROR; received from peer"). The
# trigger builds with --no-cache, so every deploy refetches the whole module
# graph and gets hundreds of chances to hit it. HTTP/1.1 gives each fetch its
# own connection so there are no shared streams to reset, GOMAXPROCS caps how
# many run at once (go mod download sizes its worker pool from it), and the
# retry covers whatever still slips through.
ENV GODEBUG=http2client=0
RUN for i in 1 2 3; do \
if GOMAXPROCS=4 go mod download; then break; fi; \
echo "go mod download failed (attempt $i), retrying" >&2; \
[ "$i" = 3 ] && exit 1; \
sleep $((i * 5)); \
done
COPY . .
# docs/docs.go is gitignored; generate the Swagger spec served at /v1/swagger/.
# swag is a go.mod tool, so its version and modules come from go.mod/go.sum
# and were fetched by the download above.
RUN go tool swag init -d cmd/api,internal/store -g main.go -o docs --outputTypes go --parseDependency
RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w -X main.version=$(cat version.txt)" -o /app/api ./cmd/api
# Stage 3: Main container
FROM scratch
WORKDIR /app
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /app/api ./api
COPY --from=frontend /app/client/web/dist ./static
COPY --from=frontend /app/client/web/public/pwa-192x192.png ./client/web/public/pwa-192x192.png
EXPOSE 8080
CMD ["./api"]