添加docker及修改docker中读取配置文件信息代码
This commit is contained in:
parent
47288cf2fb
commit
5ec40b4501
|
|
@ -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"]
|
||||
6
main.go
6
main.go
|
|
@ -68,12 +68,12 @@ func init() {
|
|||
//系统是linux、macos还是windows
|
||||
var configPath string
|
||||
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" {
|
||||
//文件地址/home/saw-ai/saw-ai.conf
|
||||
configPath = "/home/saw/saw-ai-go/saw-ai.conf"
|
||||
configPath = "/home/saw/saw-ai.conf"
|
||||
} else {
|
||||
configPath = "/home/saw/saw-ai-go/saw-ai.conf"
|
||||
configPath = "/home/saw/saw-ai.conf"
|
||||
}
|
||||
//读取配置文件
|
||||
err := proto.ReadConfig(configPath)
|
||||
|
|
|
|||
Loading…
Reference in New Issue