hilloworld commited on
Commit
3aabdac
1 Parent(s): 788f08b

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +11 -2
Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
-
2
  # 使用 golang:alpine 作为构建阶段的基础镜像
3
  FROM golang:alpine AS builder
4
 
@@ -8,18 +8,27 @@ RUN apk --no-cache add git
8
  # 从 GitHub 克隆 go-proxy-bingai 项目到 /workspace/app 目录下
9
  RUN git clone https://github.com/Harry-zklcdc/go-proxy-bingai.git /workspace/app
10
 
 
11
  WORKDIR /workspace/app
12
 
 
13
  RUN go build -ldflags="-s -w" -tags netgo -trimpath -o go-proxy-bingai main.go
14
 
 
 
15
  FROM alpine
16
 
 
17
  WORKDIR /workspace/app
18
 
 
19
  COPY --from=builder /workspace/app/go-proxy-bingai .
20
 
21
- ENV GO_PROXY_BINGAI_USER_TOKEN_1 = "kJs8hD92ncMzlaoQWYtX5rG6bE3fZ4iP"
 
22
 
 
23
  EXPOSE 8080
24
 
 
25
  CMD ["/workspace/app/go-proxy-bingai"]
 
1
+ # Build Stage
2
  # 使用 golang:alpine 作为构建阶段的基础镜像
3
  FROM golang:alpine AS builder
4
 
 
8
  # 从 GitHub 克隆 go-proxy-bingai 项目到 /workspace/app 目录下
9
  RUN git clone https://github.com/Harry-zklcdc/go-proxy-bingai.git /workspace/app
10
 
11
+ # 设置工作目录为之前克隆的项目目录
12
  WORKDIR /workspace/app
13
 
14
+ # 编译 go 项目。-ldflags="-s -w" 是为了减少编译后的二进制大小
15
  RUN go build -ldflags="-s -w" -tags netgo -trimpath -o go-proxy-bingai main.go
16
 
17
+ # Runtime Stage
18
+ # 使用轻量级的 alpine 镜像作为运行时的基础镜像
19
  FROM alpine
20
 
21
+ # 设置工作目录
22
  WORKDIR /workspace/app
23
 
24
+ # 从构建阶段复制编译后的二进制文件到运行时镜像中
25
  COPY --from=builder /workspace/app/go-proxy-bingai .
26
 
27
+ # 设置环境变量,此处为随机字符
28
+ ENV Go_Proxy_BingAI_USER_TOKEN_1="kJs8hD92ncMzLaoQWYtX5rG6bE3fZ4iO"
29
 
30
+ # 暴露8080端口
31
  EXPOSE 8080
32
 
33
+ # 容器启动时运行的命令
34
  CMD ["/workspace/app/go-proxy-bingai"]