# ---- build stage ----
FROM golang:1.22-alpine AS build
RUN apk add --no-cache ca-certificates
WORKDIR /src
COPY go.mod ./
COPY main.go index.html ./
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /mcimport .

# ---- runtime stage ----
FROM scratch
# CA bundle so HTTPS to mailcow (Let's Encrypt) validates
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=build /mcimport /mcimport
EXPOSE 8080
USER 65534:65534
ENTRYPOINT ["/mcimport"]
