2025-06-11 14:38:34 +08:00
|
|
|
|
# 第一阶段:使用最新Go版本构建
|
2025-06-12 14:28:31 +08:00
|
|
|
|
FROM docker.1ms.run/golang:1.24 AS builder
|
2025-06-11 14:38:34 +08:00
|
|
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
2025-06-12 14:28:31 +08:00
|
|
|
|
ENV GOPROXY=https://goproxy.cn,direct
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-06-11 14:38:34 +08:00
|
|
|
|
# 复制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
|
|
|
|
|
|
|
|
|
|
|
|
# 复制配置文件
|
2025-06-12 18:45:21 +08:00
|
|
|
|
COPY --from=builder /app/saw-ai.conf /home/saw/saw-ai.conf
|
2025-06-11 14:38:34 +08:00
|
|
|
|
|
|
|
|
|
|
# 复制二进制文件
|
|
|
|
|
|
COPY --from=builder /app/videoplayer /home/videoplayer/videoplayer
|
|
|
|
|
|
|
|
|
|
|
|
# 设置工作目录
|
|
|
|
|
|
WORKDIR /home/videoplayer
|
|
|
|
|
|
|
|
|
|
|
|
# 暴露端口
|
|
|
|
|
|
EXPOSE 8083
|
|
|
|
|
|
|
|
|
|
|
|
# 运行应用
|
2025-06-12 14:28:31 +08:00
|
|
|
|
CMD ["./videoplayer"]
|