FROM golang:1.26-alpine AS builder

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download

COPY . .

RUN 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"]
