| # Stage 1: Build the Go binary | |
| FROM golang:alpine AS builder | |
| # Install build dependencies | |
| RUN apk add --no-cache git | |
| WORKDIR /app | |
| # Copy module files and download dependencies | |
| COPY go.mod go.sum ./ | |
| RUN go mod download | |
| # Copy the rest of the application source code | |
| COPY . . | |
| # Compile a static Go binary optimized for linux | |
| RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o main . | |
| # Stage 2: Create a minimal production container | |
| FROM alpine:3.19 | |
| WORKDIR /app | |
| # Install timezone data and CA certificates (essential for Midtrans/Fonnte HTTPS) | |
| RUN apk --no-cache add ca-certificates tzdata | |
| ENV TZ=Asia/Jakarta | |
| # Copy the compiled binary from the builder stage | |
| COPY --from=builder /app/main . | |
| # Expose port 7860 (Hugging Face Spaces requirement) | |
| ENV PORT=7860 | |
| EXPOSE 7860 | |
| # Run the Go binary | |
| CMD ["./main"] | |