saw-go/Dockerfile

33 lines
697 B
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 第一阶段使用最新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 StuAcaWorksAI .
# 第二阶段:生产环境(最小化镜像)
FROM scratch
# 复制配置文件
COPY --from=builder /app/saw-ai.conf /home/saw/saw-ai.conf
# 复制二进制文件
COPY --from=builder /app/StuAcaWorksAI /home/saw/StuAcaWorksAI
# 设置工作目录
WORKDIR /home/saw
# 暴露端口
EXPOSE 8084
# 运行应用
CMD ["./StuAcaWorksAI"]