# syntax=docker/dockerfile:1.7
# AGENT: Two-stage build. The final image contains only the static binary and a
# CA bundle, runs as a non-root user and keeps the server as PID 1 for signals.
FROM golang:1.27.1-alpine AS build

WORKDIR /src
COPY app/go.mod app/go.sum ./
RUN go mod download
COPY app/ ./
RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/server ./cmd/server

FROM alpine:3.22

RUN addgroup -S -g 10001 app && adduser -S -u 10001 -G app app

COPY --from=build /out/server /usr/local/bin/server

USER app
EXPOSE 8080
ENTRYPOINT ["/usr/local/bin/server"]
