File size: 1,285 Bytes
a356aee | 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 | # Build Stage
FROM golang:1.21-alpine AS builder
WORKDIR /app
# Copy the server and cli source code
COPY main.go go.mod ./
COPY cli/ cli/
# Create directory to store precompiled binaries
RUN mkdir -p bin
# Cross-compile CLI for various target OS and architectures
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o bin/linux-amd64 cli/main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o bin/linux-arm64 cli/main.go
RUN CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -o bin/windows-amd64 cli/main.go
RUN CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o bin/darwin-amd64 cli/main.go
RUN CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w" -o bin/darwin-arm64 cli/main.go
# Build the main server binary statically linked
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o server main.go
# Production Stage
FROM scratch
WORKDIR /app
# Copy the server binary and precompiled CLI binaries
COPY --from=builder /app/server /app/server
COPY --from=builder /app/bin /app/bin
# Environment variables (Can be overridden in HF Spaces configuration)
ENV DATA_DIR=/data
ENV BIN_DIR=/app/bin
ENV PORT=7860
# Expose default HF Spaces port
EXPOSE 7860
# Command to run backend
CMD ["/app/server"]
|