FROM golang:1.20-alpine AS builder

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

COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /out/sproutgate-backend .

FROM alpine:3.19
RUN apk add --no-cache ca-certificates tzdata

WORKDIR /app
ENV PORT=8080
ENV DATA_DIR=/data

COPY --from=builder /out/sproutgate-backend /usr/local/bin/sproutgate-backend
COPY API_DOCS.md /app/API_DOCS.md

EXPOSE 8080
VOLUME ["/data"]

ENTRYPOINT ["sproutgate-backend"]
