Update Dockerfile
Browse files- Dockerfile +35 -11
Dockerfile
CHANGED
@@ -1,17 +1,41 @@
|
|
1 |
-
# 使用
|
2 |
-
FROM
|
3 |
|
4 |
-
#
|
5 |
-
|
|
|
|
|
6 |
|
7 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
COPY . .
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
#
|
11 |
-
RUN
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
|
16 |
-
#
|
17 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
# 使用 Golang 镜像作为构建阶段
|
2 |
+
FROM golang AS builder
|
3 |
|
4 |
+
# 设置环境变量
|
5 |
+
ENV GO111MODULE=on \
|
6 |
+
CGO_ENABLED=0 \
|
7 |
+
GOOS=linux
|
8 |
|
9 |
+
# 设置工作目录
|
10 |
+
WORKDIR /build
|
11 |
+
|
12 |
+
# 安装 git
|
13 |
+
RUN apk add --no-cache git
|
14 |
+
|
15 |
+
# 克隆项目仓库
|
16 |
+
RUN git clone https://github.com/deanxv/genspark2api.git .
|
17 |
+
|
18 |
+
# 复制 go.mod 和 go.sum 文件,先下载依赖
|
19 |
+
COPY go.mod go.sum ./
|
20 |
+
#ENV GOPROXY=https://goproxy.cn,direct
|
21 |
+
RUN go mod download
|
22 |
+
|
23 |
+
# 复制整个项目并构建可执行文件
|
24 |
COPY . .
|
25 |
+
RUN go build -o /genspark2api
|
26 |
+
|
27 |
+
# 使用 Alpine 镜像作为最终镜像
|
28 |
+
FROM alpine
|
29 |
|
30 |
+
# 安装基本的运行时依赖
|
31 |
+
RUN apk --no-cache add ca-certificates tzdata
|
32 |
|
33 |
+
# 从构建阶段复制可执行文件
|
34 |
+
COPY --from=builder /genspark2api .
|
35 |
|
36 |
+
# 暴露端口
|
37 |
+
EXPOSE 7055
|
38 |
+
# 工作目录
|
39 |
+
WORKDIR /app/genspark2api/data
|
40 |
+
# 设置入口命令
|
41 |
+
ENTRYPOINT ["/genspark2api"]
|