Spaces:
Sleeping
Sleeping
| # Stage 1: Build the Go Binary | |
| FROM golang:1.21 as builder | |
| WORKDIR /app | |
| # 1. Copy ALL files first (including main.go) | |
| # We do this so 'go mod tidy' can see the imports in main.go | |
| COPY . . | |
| # 2. Generate go.sum and download dependencies | |
| RUN go mod tidy | |
| # 3. Build the binary named "server" | |
| RUN CGO_ENABLED=0 GOOS=linux go build -o server main.go | |
| # Stage 2: Run the Binary (Small Image) | |
| FROM alpine:latest | |
| WORKDIR /app | |
| # Install CA certificates for HTTPS calls | |
| RUN apk --no-cache add ca-certificates | |
| # Create a non-root user (Required by HF Spaces) | |
| RUN adduser -D -u 1000 user | |
| USER user | |
| # Copy the binary from builder | |
| COPY --from=builder /app/server . | |
| # Expose HF Port | |
| EXPOSE 7860 | |
| # Run | |
| CMD ["./server"] |