# Stage 1: Build the Go binary FROM golang:1.21-alpine AS builder WORKDIR /app # Copy source code and mod files COPY go.mod ./ COPY main.go . # Download dependencies # Note: main.go must be present for 'go mod tidy' to detect imports correctly RUN go mod tidy # Build the application # CGO_ENABLED=0 ensures a static binary RUN CGO_ENABLED=0 GOOS=linux go build -o ctf-server main.go # Stage 2: Create the runtime image FROM alpine:latest WORKDIR /root/ # Copy the binary from the builder stage COPY --from=builder /app/ctf-server . # CRITICAL: Copy the source code so /source endpoint can serve it COPY --from=builder /app/main.go . # Expose the port Hugging Face Spaces expects (7860) EXPOSE 7860 # Run the binary CMD ["./ctf-server"]