添加docker及修改docker中读取配置文件信息代码

This commit is contained in:
junleea 2025-06-12 15:02:58 +08:00
parent 47288cf2fb
commit 5ec40b4501
2 changed files with 36 additions and 3 deletions

33
Dockerfile Normal file
View File

@ -0,0 +1,33 @@
# 第一阶段使用最新Go版本构建
FROM docker.1ms.run/golang:1.24 AS builder
WORKDIR /app
ENV GOPROXY=https://goproxy.cn,direct
# 复制go.mod和go.sum以缓存依赖
COPY go.mod go.sum ./
RUN go mod download
# 复制源代码并构建
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags="-s -w" -o videoplayer .
# 第二阶段:生产环境(最小化镜像)
FROM scratch
# 复制配置文件
COPY --from=builder /app/vp.conf /home/saw/saw-ai.conf
# 复制二进制文件
COPY --from=builder /app/StuAcaWorksAI /home/saw/StuAcaWorksAI
# 设置工作目录
WORKDIR /home/saw
# 暴露端口
EXPOSE 8084
# 运行应用
CMD ["./StuAcaWorksAI"]

View File

@ -68,12 +68,12 @@ func init() {
//系统是linux、macos还是windows //系统是linux、macos还是windows
var configPath string var configPath string
if os.Getenv("OS") == "Windows_NT" { if os.Getenv("OS") == "Windows_NT" {
configPath = "E:/Code/saw-ai/saw-ai.conf" configPath = "C:/saw/saw-ai.conf"
} else if os.Getenv("OS") == "linux" { } else if os.Getenv("OS") == "linux" {
//文件地址/home/saw-ai/saw-ai.conf //文件地址/home/saw-ai/saw-ai.conf
configPath = "/home/saw/saw-ai-go/saw-ai.conf" configPath = "/home/saw/saw-ai.conf"
} else { } else {
configPath = "/home/saw/saw-ai-go/saw-ai.conf" configPath = "/home/saw/saw-ai.conf"
} }
//读取配置文件 //读取配置文件
err := proto.ReadConfig(configPath) err := proto.ReadConfig(configPath)