-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackend.Dockerfile
More file actions
38 lines (26 loc) · 906 Bytes
/
backend.Dockerfile
File metadata and controls
38 lines (26 loc) · 906 Bytes
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
# Production Dockerfile for Go backend (build from project root)
# Multi-stage build for smaller image
# Usage: docker build -f backend.Dockerfile -t nxtchess-backend .
# Build stage
FROM golang:1.24-alpine AS builder
WORKDIR /app
# Install git for go mod download (some deps may need it)
RUN apk add --no-cache git
# Download dependencies first (cached layer)
COPY apps/backend/go.mod apps/backend/go.sum ./
RUN go mod download
# Copy source and build
COPY apps/backend/ .
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o server cmd/server/main.go
# Runtime stage
FROM alpine:3.19
WORKDIR /app
# Install CA certificates for HTTPS calls (OAuth)
RUN apk --no-cache add ca-certificates tzdata
# Copy binary from builder (migrations are embedded via go:embed)
COPY --from=builder /app/server .
# Run as non-root user
RUN adduser -D -g '' appuser
USER appuser
EXPOSE 8080
CMD ["./server"]