# Context is the repository root; admin depends on the shared module.
FROM golang:1.26-alpine AS builder

WORKDIR /src

COPY shared/go.mod shared/go.sum ./shared/
COPY admin/go.mod admin/go.sum ./admin/
RUN cd admin && go mod download

COPY shared/ ./shared/
COPY admin/ ./admin/

RUN cd admin && CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /out/admin ./cmd
RUN cd admin && CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /out/adminctl ./cmd/adminctl

FROM alpine:3.20 AS runner

RUN apk add --no-cache ca-certificates && \
    addgroup --system --gid 1001 admin && \
    adduser --system --uid 1001 --ingroup admin admin

COPY --from=builder /out/admin /usr/local/bin/admin
COPY --from=builder /out/adminctl /usr/local/bin/adminctl

USER admin

EXPOSE 8083
ENV PORT=8083

CMD ["/usr/local/bin/admin"]
