File size: 711 Bytes
0c04b4b
 
 
 
 
b05f4b2
 
0c04b4b
 
b05f4b2
 
 
 
0c04b4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# 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"]