2024-06-27 13:35:20 +08:00
|
|
|
|
#
|
|
|
|
|
## 使用官方Go镜像作为构建环境
|
2024-06-27 11:55:34 +08:00
|
|
|
|
#FROM golang:1.21.0 AS builder
|
|
|
|
|
#
|
2024-06-27 13:35:20 +08:00
|
|
|
|
#
|
2024-06-27 11:55:34 +08:00
|
|
|
|
#
|
|
|
|
|
## 设置工作目录
|
|
|
|
|
#WORKDIR /app
|
|
|
|
|
#
|
|
|
|
|
## 设置环境变量
|
|
|
|
|
#RUN go env -w GOPROXY=https://goproxy.cn,direct
|
|
|
|
|
#ENV GOPROXY=https://goproxy.cn,direct
|
|
|
|
|
#
|
|
|
|
|
## 复制项目源码
|
|
|
|
|
#COPY . .
|
|
|
|
|
## 安装snow-core
|
|
|
|
|
#RUN go get github.com/qit-team/snow-core/kernel/server@v0.1.28
|
|
|
|
|
## 安装go模块依赖
|
|
|
|
|
#RUN go mod tidy
|
|
|
|
|
#
|
|
|
|
|
## 编译Go应用程序,生成静态链接的二进制文件
|
|
|
|
|
#RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o server main.go
|
2024-06-24 11:44:38 +08:00
|
|
|
|
|
|
|
|
|
# 创建最终镜像,用于运行编译后的Go程序
|
2024-06-27 15:37:54 +08:00
|
|
|
|
FROM alpine
|
2024-06-27 15:08:31 +08:00
|
|
|
|
#设置时区
|
2024-06-27 15:37:54 +08:00
|
|
|
|
ENV TimeZone=Asia/Shanghai
|
2024-06-24 11:44:38 +08:00
|
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
# 将编译好的二进制文件从构建阶段复制到运行阶段
|
2024-06-27 13:35:20 +08:00
|
|
|
|
#COPY --from=builder /app/server /app/server
|
|
|
|
|
#COPY --from=builder /app/.env /app/.env
|
|
|
|
|
# 将编译好的二进制文件从构建阶段复制到运行阶段
|
|
|
|
|
COPY /server .
|
|
|
|
|
#COPY --from=builder /app/server .
|
|
|
|
|
COPY .env .
|
|
|
|
|
#RUN chmod +x /app/server
|
|
|
|
|
# 设置环境变量的默认值
|
|
|
|
|
ENV SERVER=api
|
2024-06-24 11:44:38 +08:00
|
|
|
|
|
|
|
|
|
# 暴露容器的端口
|
|
|
|
|
EXPOSE 443 8083 8082
|
|
|
|
|
|
|
|
|
|
# 设置容器启动时运行的命令
|
2024-06-27 13:35:20 +08:00
|
|
|
|
ENTRYPOINT ["/app/server", "-a", "$server"]
|