File size: 746 Bytes
83597a3
 
 
 
 
dc15350
83597a3
 
 
dc15350
 
 
 
83597a3
 
 
 
 
 
 
 
 
 
 
 
ef44f53
 
 
83597a3
 
 
 
 
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
# 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"]