# syntax=docker/dockerfile:1

# --- build stage ---
FROM golang:1.26 AS build

WORKDIR /src

# Cached dependency layer.
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod \
    go mod download

# Build the static daemon.
COPY . .
RUN --mount=type=cache,target=/go/pkg/mod \
    --mount=type=cache,target=/root/.cache/go-build \
    CGO_ENABLED=0 GOOS=linux go build \
        -trimpath -ldflags="-s -w" \
        -o /out/scoreboard-apid ./cmd/scoreboard-apid

# --- runtime stage ---
# distroless static includes CA certificates (needed for HTTPS to root-me.org)
# and runs as a non-root user.
FROM gcr.io/distroless/static-debian12:nonroot

COPY --from=build /out/scoreboard-apid /usr/local/bin/scoreboard-apid

EXPOSE 8080 9090

ENV HTTP_ADDR=:8080 \
    GRPC_ADDR=:9090

ENTRYPOINT ["/usr/local/bin/scoreboard-apid"]
