File size: 822 Bytes
edcf070 12c85ed edcf070 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | # 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"]
|