2026-04-22 15:41:08 +08:00
|
|
|
|
# 多阶段构建 - 第一阶段:编译(使用已安装的镜像)
|
|
|
|
|
|
FROM golang:1.26-alpine3.23 AS builder
|
2026-01-31 18:37:54 +08:00
|
|
|
|
|
2026-04-22 15:41:08 +08:00
|
|
|
|
RUN apk add --no-cache git ca-certificates tzdata
|
|
|
|
|
|
|
|
|
|
|
|
ENV GO111MODULE=on
|
|
|
|
|
|
ENV GOPROXY=https://goproxy.cn,direct
|
|
|
|
|
|
ENV CGO_ENABLED=0
|
|
|
|
|
|
ENV GOTOOLCHAIN=auto
|
|
|
|
|
|
ENV GOPRIVATE=gitea.com/red-future/common
|
|
|
|
|
|
|
|
|
|
|
|
# 配置git使用私有Gitea仓库(带Token认证)
|
2026-04-24 08:57:28 +08:00
|
|
|
|
RUN git config --global url."http://x-token-auth:619679cd366aefea3a50f0622d842a41f2209e08595767bba49c3836ef57d415@116.204.74.41:3000/red-future/common.git".insteadOf "https://gitea.com/red-future/common.git" && \
|
2026-04-22 15:41:08 +08:00
|
|
|
|
git config --global credential.helper store
|
|
|
|
|
|
|
|
|
|
|
|
WORKDIR /build
|
|
|
|
|
|
|
|
|
|
|
|
# 复制父目录的 common 模块(因为 go.mod 中使用了本地 replace)
|
|
|
|
|
|
#COPY ../common /build/common
|
|
|
|
|
|
COPY . .
|
2026-01-31 18:37:54 +08:00
|
|
|
|
|
2026-04-22 15:41:08 +08:00
|
|
|
|
RUN go mod download && go mod tidy
|
2026-03-16 11:02:37 +08:00
|
|
|
|
|
2026-04-22 15:41:08 +08:00
|
|
|
|
RUN go build -ldflags="-s -w" -o main ./main.go
|
|
|
|
|
|
|
|
|
|
|
|
# 第二阶段:运行
|
|
|
|
|
|
FROM alpine:3.23
|
|
|
|
|
|
|
|
|
|
|
|
ENV TIME_ZONE=Asia/Shanghai
|
|
|
|
|
|
RUN apk add --no-cache ca-certificates tzdata && \
|
|
|
|
|
|
ln -sf /usr/share/zoneinfo/$TIME_ZONE /etc/localtime
|
|
|
|
|
|
|
|
|
|
|
|
WORKDIR /app
|
2026-01-31 18:37:54 +08:00
|
|
|
|
|
2026-04-22 15:41:08 +08:00
|
|
|
|
# 复制编译好的二进制文件
|
|
|
|
|
|
COPY --from=builder /build/main .
|
|
|
|
|
|
COPY --from=builder /build/config.yml ./
|
2026-04-08 22:14:21 +08:00
|
|
|
|
|
2026-04-08 21:48:19 +08:00
|
|
|
|
# 创建日志目录
|
|
|
|
|
|
RUN mkdir -p /logs /app/resource/log/run /app/resource/log/server
|
2026-01-31 18:37:54 +08:00
|
|
|
|
|
|
|
|
|
|
EXPOSE 8000
|
|
|
|
|
|
|
2026-03-16 11:02:37 +08:00
|
|
|
|
CMD ["./main"]
|