Files
asset_helper/backend/gateway/Dockerfile

47 lines
743 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.
FROM golang:1.25.8-alpine3.23 AS builder
# 设置工作目录
WORKDIR /app
# 安装 git
RUN apk add --no-cache git
# 设置 Go 环境变量
ENV GOPROXY=https://goproxy.io,direct
ENV GOSUMDB=off
# 复制共享包
COPY shared/ /shared/
# 复制 go.mod
COPY gateway/go.mod ./
# 复制 go.sum如果存在
COPY gateway/go.sum* ./
# 复制源代码
COPY gateway/ .
# 生成 go.sum 并下载依赖
RUN go mod tidy
# 构建应用
RUN go build -o gateway ./cmd/main.go
# 运行阶段
FROM alpine:3.23
# 安装必要的依赖
RUN apk add --no-cache ca-certificates
# 设置工作目录
WORKDIR /app
# 从构建阶段复制二进制文件
COPY --from=builder /app/gateway .
# 暴露端口
EXPOSE 8000
# 启动应用
CMD ["./gateway"]