yangjianchuan
commited on
Commit
•
3dba640
1
Parent(s):
01606dc
Create Dockerfile
Browse files- Dockerfile +34 -0
Dockerfile
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Build Stage
|
2 |
+
# 使用 golang:alpine 作为构建阶段的基础镜像
|
3 |
+
FROM golang:alpine AS builder
|
4 |
+
|
5 |
+
# 添加 git,以便之后能从GitHub克隆项目
|
6 |
+
RUN apk --no-cache add git
|
7 |
+
|
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="kJs8hD92ncMzLaoQWYtX5rG6bE3fZ4iOqie"
|
29 |
+
|
30 |
+
# 暴露8080端口
|
31 |
+
EXPOSE 8080
|
32 |
+
|
33 |
+
# 容器启动时运行的命令
|
34 |
+
CMD ["/workspace/app/go-proxy-bingai"]
|