# Base images are build arguments so that make -C deploy release-build can pin
# each one to the digest it resolved; the defaults keep the agreed tags.
ARG GO_IMAGE=golang:1.26.9-alpine
ARG RUNTIME_IMAGE=gcr.io/distroless/static-debian12:nonroot

FROM ${GO_IMAGE} AS build

# Never download another Go toolchain: a go.mod that asks for a newer Go
# fails the build instead of silently replacing 1.26.9.
ENV GOTOOLCHAIN=local

WORKDIR /src/backend
COPY go.mod go.sum ./
RUN go mod download

COPY . ./
RUN CGO_ENABLED=0 GOOS=linux go build -buildvcs=false -trimpath -ldflags="-s -w" -o /out/app ./cmd/app

FROM ${RUNTIME_IMAGE}

WORKDIR /
COPY --from=build /out/app /app
EXPOSE 8080 9090
USER nonroot:nonroot
ENTRYPOINT ["/app"]
