Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Keep the build context small and avoid copying files the image does not need.
bin/
.git
.golangci.yml
Dockerfile
.dockerignore
36 changes: 36 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# syntax=docker/dockerfile:1

# ---------- Stage 1: build ----------
# Same Go version as backend/go.mod, so no toolchain download at build time.
FROM golang:1.26.11 AS build

WORKDIR /src

# Copy only the dependency files first: this layer is cached until
# go.mod or go.sum change, so rebuilds after a code change are fast.
COPY go.mod go.sum ./
RUN go mod download

COPY . .

# CGO_ENABLED=0 -> static binary (the final image has no libc).
# -trimpath removes local file paths from the binary.
# -s -w strips debug info, which makes the binary smaller.
RUN CGO_ENABLED=0 GOOS=linux go build \
-trimpath -ldflags="-s -w" \
-o /out/api ./cmd/api

# ---------- Stage 2: runtime ----------
# distroless: no shell, no package manager. "nonroot" runs as uid 65532.
FROM gcr.io/distroless/static-debian13:nonroot

COPY --from=build /out/api /api

# Documentation only: the API listens on 8080 (set in cmd/api/main.go).
EXPOSE 8080

USER nonroot:nonroot

# Exec form: the Go binary is PID 1 and receives SIGTERM from "docker stop",
# which triggers the graceful shutdown.
ENTRYPOINT ["/api"]
Loading