FROM golang:1.21-alpine AS builder WORKDIR /app # 配置中国镜像源 RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories # 安装构建依赖 RUN apk add --no-cache git # 配置 Go 模块代理为国内镜像 ENV GOPROXY=https://goproxy.cn,direct ENV GOSUMDB=sum.golang.google.cn # 复制源码 COPY . . # 初始化模块并下载依赖 RUN go mod tidy # 构建应用 RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o giteapm cmd/main.go # 使用最小镜像 FROM alpine:latest # 配置中国镜像源 RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories RUN apk --no-cache add ca-certificates WORKDIR /root/ # 从构建阶段复制二进制文件 COPY --from=builder /app/giteapm . COPY --from=builder /app/config ./config COPY --from=builder /app/web ./web # 暴露端口 EXPOSE 8080 # 运行应用 CMD ["./giteapm"]