Files
api-go/Dockerfile
T

31 lines
784 B
Docker

# syntax=docker/dockerfile:1
FROM golang:1.27-alpine AS build
WORKDIR /src
# Dependencies are only the standard library today; the explicit copy keeps
# the module cache layer stable when that changes.
COPY go.mod ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build \
-trimpath -ldflags="-s -w" \
-o /out/api ./cmd/api
FROM gcr.io/distroless/static-debian12:nonroot
WORKDIR /app
COPY --from=build /out/api /app/api
# No data is baked into the image. The API fetches FastAPI /bootstrap at
# startup, caches the snapshot in memory, and refreshes it in the background.
ENV PORT=8080
EXPOSE 8080
# Numeric UID/GID: the kubelet cannot verify named users for runAsNonRoot.
# 65532 is the distroless "nonroot" user.
USER 65532:65532
ENTRYPOINT ["/app/api"]