# 第一阶段：构建
FROM golang:1.24.0 AS builder

ENV GOPROXY=https://goproxy.cn,direct

WORKDIR /build

# 复制Go模块文件
COPY go.mod go.sum ./
RUN go mod download

# 复制源代码
COPY . .

# 编译
RUN GOOS=linux GOARCH=amd64 go build -ldflags '-w -s' -o bin/proxy_linux_amd64 cmd/main/main.go

# 第二阶段：运行环境
FROM ubuntu:24.04 AS runner

WORKDIR /app

RUN apt-get update && apt-get install -y ca-certificates

# 从构建阶段复制编译好的二进制文件
COPY --from=builder /build/bin/proxy_linux_amd64 /app/proxy
COPY cmd/gateway/ip2region.xdb /app/id2region.xdb

# 设置可执行权限
RUN chmod +x /app/proxy

# 锁定文件
VOLUME /app/proxy.lock

# 声明暴露端口
EXPOSE 8080

# 启动平台服务
CMD ["/app/proxy"]