File size: 1,165 Bytes
77241ac
6e45654
41142e5
77241ac
41142e5
 
77241ac
 
 
 
508e14d
77241ac
 
 
a3ed433
 
 
6e45654
 
77241ac
 
6e45654
77241ac
6e45654
422d4e7
 
 
 
77241ac
 
 
6e45654
77241ac
 
 
f35c422
77241ac
f35c422
 
77241ac
 
f35c422
77241ac
 
 
 
 
b512abb
41142e5
77241ac
6e45654
77241ac
 
 
6e45654
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
# Go版本的高性能API代理服务器Dockerfile
FROM golang:alpine AS builder

# 设置工作目录
WORKDIR /app

# 复制go模块文件
COPY go.mod go.sum ./

# 下载依赖
RUN go mod download

# 复制源代码
COPY *.go ./
# 复制静态文件和HTML文件
COPY index.html ./
COPY static/ ./static/
# 编译应用
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o api-proxy .

# 运行阶段
FROM alpine:latest

# 安装CA证书
RUN apk --no-cache add ca-certificates tzdata

# 设置时区
ENV TZ=Asia/Shanghai

# 创建非root用户
RUN addgroup -g 1001 -S apiproxy && \
    adduser -u 1001 -S apiproxy -G apiproxy

WORKDIR /home/apiproxy/

# 从构建阶段复制二进制文件和静态文件
COPY --from=builder /app/api-proxy .
COPY --from=builder /app/index.html ./
COPY --from=builder /app/static/ ./static/

# 设置文件权限
RUN chown -R apiproxy:apiproxy .

# 切换到非root用户
USER apiproxy

# 暴露端口
EXPOSE 8000

# 健康检查
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
    CMD wget --no-verbose --tries=1 --spider http://localhost:8000/stats || exit 1

# 启动应用
CMD ["./api-proxy"]