ai_scheduler/Dockerfile

50 lines
1.2 KiB
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 golang:1.24.1-alpine AS builder
# 设置工作目录
WORKDIR /app
# 使用国内镜像源加速APK包下载
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 使用国内镜像源加速依赖下载
ENV GOPROXY=https://goproxy.cn,direct
# 复制项目源码
COPY . .
# 复制go模块依赖文件
COPY go.mod go.sum ./
RUN go mod tidy
RUN go install github.com/google/wire/cmd/wire@latest
RUN wire ./cmd/server
# 编译Go应用程序生成静态链接的二进制文件
RUN go build -ldflags="-s -w" -o server ./cmd/server
# 创建最终镜像用于运行编译后的Go程序
FROM alpine
RUN echo 'http://mirrors.ustc.edu.cn/alpine/v3.5/main' > /etc/apk/repositories \
&& echo 'http://mirrors.ustc.edu.cn/alpine/v3.5/community' >>/etc/apk/repositories \
&& apk update && apk add tzdata \
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone
# 设置工作目录
WORKDIR /app
# 将编译好的二进制文件从构建阶段复制到运行阶段
COPY --from=builder /app/server ./server
# 复制配置文件夹
COPY --from=builder /app/config ./config
ENV TZ=Asia/Shanghai
# 设置容器启动时运行的命令
CMD ["./server"]