新增:Dockerfile

This commit is contained in:
2023-07-09 03:44:23 +08:00
parent 0fe8370704
commit 01b6451155
2 changed files with 49 additions and 2 deletions

40
Dockerfile Normal file
View File

@@ -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"]

11
go.mod
View File

@@ -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
)