de / Dockerfile
caidaohz's picture
feat: Initialize OnDemand2API with Go, including API key management and chat completion functionality
ebcd387
raw
history blame contribute delete
753 Bytes
# 多阶段构建
FROM golang:1.21-alpine AS builder
# 设置工作目录
WORKDIR /app
# 安装必要的工具
RUN apk add --no-cache git
# 复制go mod文件
COPY go.mod go.sum ./
# 下载依赖
RUN go mod download
# 复制源代码
COPY main.go ./
# 构建应用
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
# 运行阶段
FROM alpine:latest
# 安装ca-certificates用于HTTPS请求
RUN apk --no-cache add ca-certificates curl
WORKDIR /root/
# 从构建阶段复制二进制文件
COPY --from=builder /app/main .
# 暴露端口
EXPOSE 7860
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:7860/v1/models || exit 1
# 运行应用
CMD ["./main"]