File size: 932 Bytes
55066b7
a364ccb
55066b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
# Stage 1: Build binary Go
FROM golang:alpine AS builder

WORKDIR /app

# Install git, ca-certificates, and tzdata
RUN apk add --no-cache git ca-certificates tzdata

# Cache dependencies
COPY go.mod go.sum ./
RUN go mod download

# Copy source code and frontend
COPY . .

# Build statically linked binary
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o server .

# Stage 2: Minimal runtime container
FROM alpine:latest

# Install runtime SSL certificates & timezone data
RUN apk add --no-cache ca-certificates tzdata

# Setup non-root user for Hugging Face Spaces (UID 1000)
RUN adduser -D -u 1000 user
USER user

ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH \
    PORT=7860

WORKDIR /home/user/app

# Copy binary and frontend assets
COPY --chown=user:user --from=builder /app/server .
COPY --chown=user:user --from=builder /app/frontend ./frontend

# Hugging Face default port
EXPOSE 7860

CMD ["./server"]