From 01b645115536418ce695444aed1a4e9f05b16f7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E6=98=BE=E4=BC=98?= <237809796@qq.com> Date: Sun, 9 Jul 2023 03:44:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9ADockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 40 ++++++++++++++++++++++++++++++++++++++++ go.mod | 11 +++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..82c751e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +# 阶段一:构建阶段 +FROM golang:alpine AS builder + +WORKDIR /opt/zhub + +# 复制 go.mod 文件 +COPY go.mod . + +# 下载并缓存依赖包 +RUN go mod download + +# 将源代码复制到容器中 +COPY . . + +# 运行 go get 命令以确保所有需要的包都被获取和更新 +#RUN go get zhub/internal/monitor +#RUN go get zhub/cmd +#RUN go get zhub/internal/zsub +#RUN go get zhub/internal/config + +# 构建可执行文件 +RUN go build -o zhub.sh -ldflags "-s -w" + + +# 阶段二:运行阶段 +FROM alpine:latest + +# 设置工作目录 +WORKDIR /opt/zhub + +# 从构建阶段复制可执行文件到当前阶段 +COPY --from=builder /opt/zhub . + +# 复制 app.ini 配置文件到容器中 +COPY app.ini . + +EXPOSE 711 1216 + +# 设置容器启动时要执行的命令 +CMD ["./zhub.sh"] diff --git a/go.mod b/go.mod index 930a18b..4d9aa9e 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,9 @@ module zhub -go 1.18 +go 1.20 require ( - github.com/gin-gonic/gin v1.9.1 + github.com/gin-gonic/gin v1.9.0 github.com/go-basic/uuid v1.0.0 github.com/go-sql-driver/mysql v1.5.0 github.com/robfig/cron v1.2.0 @@ -46,3 +46,10 @@ require ( gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) + +replace ( + zhub/cmd => ./zhub/cmd + zhub/internal/config => ./zhub/internal/config + zhub/internal/monitor => ./zhub/internal/monitor + zhub/internal/zsub => ./zhub/internal/zsub +)