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

WORKDIR /src

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

COPY shared/ ./shared/
COPY sitesvc/ ./sitesvc/

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

FROM alpine:3.20 AS runner

# Needed to verify the SMTP server's TLS certificate.
RUN apk add --no-cache ca-certificates && \
    addgroup --system --gid 1001 sitesvc && \
    adduser --system --uid 1001 --ingroup sitesvc sitesvc

COPY --from=builder /out/sitesvc /usr/local/bin/sitesvc

USER sitesvc

EXPOSE 8082
ENV PORT=8082

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