FROM golang:1.25-alpine AS builder

ARG USE_PROXY
WORKDIR /build
COPY ./ /build/

# 根据USE_PROXY参数设置环境变量
RUN export GO111MODULE=on GOOS=linux GOARCH=amd64 && \
    go mod tidy && go build -ldflags "-s -w" -o main main.go

FROM alpine:latest

WORKDIR /app
ENV TZ=Asia/Shanghai
# 定义参数
ARG USE_PROXY
ENV serverName="测试"

COPY --from=builder /build/main /app/
COPY --from=builder /build/resource/public/ /app/resource/public/
COPY --from=builder /build/manifest/config/ /app/manifest/config/

#设置国内镜像源，时区
RUN apk update && \
    apk upgrade && \
    apk add --no-cache tzdata && \
    cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    echo "Asia/Shanghai" > /etc/timezone

#安装curl
RUN apk add --no-cache curl && chmod +x /app/main

#添加health检查
HEALTHCHECK --interval=60s --timeout=3s --retries=3 CMD curl -f http://127.0.0.1:12401/api/monitor/heathcheck || exit 1
# 启动服务
CMD ["./main"]

EXPOSE 12401