-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathDockerfile
More file actions
85 lines (60 loc) · 2.05 KB
/
Copy pathDockerfile
File metadata and controls
85 lines (60 loc) · 2.05 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# 多阶段构建 Dockerfile
# 第一阶段:构建
FROM golang:1.22-alpine AS builder
# 安装必要的构建工具
RUN apk add --no-cache git ca-certificates tzdata
# 设置工作目录
WORKDIR /build
# 复制所有源代码和配置
COPY . .
# 下载依赖并构建
RUN go mod download && \
go mod download golang.org/x/net && \
go mod download golang.org/x/text && \
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o factory-proxy-openai main_multimodel.go
# 第二阶段:运行(Anthropic 原生模式)
FROM alpine:latest AS anthropic
# 安装 ca-certificates 用于 HTTPS 请求
RUN apk --no-cache add ca-certificates tzdata
# 创建非 root 用户
RUN addgroup -g 1000 app && \
adduser -D -u 1000 -G app app
WORKDIR /app
# 从构建阶段复制二进制文件和配置文件
COPY --from=builder /build/factory-proxy-openai .
COPY --from=builder /build/config.json .
COPY --from=builder /build/docs.html .
# 设置文件权限
RUN chown -R app:app /app
# 切换到非 root 用户
USER app
# 暴露端口
EXPOSE 8000
# 健康检查
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8000/health || exit 1
# 启动命令
ENTRYPOINT ["./factory-proxy-openai"]
# 第三阶段:运行(OpenAI 兼容模式)
FROM alpine:latest AS openai
# 安装 ca-certificates 用于 HTTPS 请求
RUN apk --no-cache add ca-certificates tzdata
# 创建非 root 用户
RUN addgroup -g 1000 app && \
adduser -D -u 1000 -G app app
WORKDIR /app
# 从构建阶段复制二进制文件和配置文件
COPY --from=builder /build/factory-proxy-openai .
COPY --from=builder /build/config.json .
COPY --from=builder /build/docs.html .
# 设置文件权限
RUN chown -R app:app /app
# 切换到非 root 用户
USER app
# 暴露端口
EXPOSE 8003
# 健康检查
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8003/v1/health || exit 1
# 启动命令
ENTRYPOINT ["./factory-proxy-openai"]