#FROM 172.20.32.187/pipeline-service/pipeline-convert:running
##FROM ccr.ccs.tencentyun.com/somunslotus/pipeline-covert:running
#WORKDIR /app
#RUN go build -o remote-task-excutor-cli
#COPY ./remote-task-excutor-cli  /app/remote-task-excutor-cli
##COPY ./internal/config/config.yaml /usr/local/argo-pipeline-manager/
#RUN chmod a+x /app/remote-task-excutor-cli
#ENTRYPOINT ["/app/remote-task-excutor-cli", "run"]


# 第一阶段：构建阶段
FROM 172.20.32.159/pipeline-service/golang:1.24.5-alpine3.22 AS builder

WORKDIR /app

# 先复制依赖文件，利用缓存
COPY go.mod go.sum ./
# 复制源代码
COPY . .
RUN go env -w  GOPROXY=https://goproxy.cn,direct
#RUN go env -w  GOPROXY=http://172.20.32.233:30005/repository/hnxjy-goproxy/
RUN go mod tidy && go mod download
# 构建应用
RUN CGO_ENABLED=0 GOOS=linux go build -o remote-task-executor-cli

# 第二阶段：运行阶段
FROM 172.20.32.159/pipeline-service/pipeline-convert:running

WORKDIR /app


#RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
#    && apk update \
#    && apk add python3 py3-pip

# 接收构建参数
ARG NACOS_HOST=172.20.32.121
ARG NACOS_PORT=31203


ARG HTTP_PROXY
ARG HTTPS_PROXY
ARG NO_PROXY

# 设置代理（如果传入）
ENV http_proxy=${HTTP_PROXY}
ENV https_proxy=${HTTPS_PROXY}
ENV no_proxy=${NO_PROXY}


# 从构建阶段复制可执行文件
COPY --from=builder /app/remote-task-executor-cli /app/
COPY --from=builder /app/merge_aim.py /app/

# 设置执行权限
RUN chmod a+x /app/remote-task-executor-cli && chmod a+x /app/merge_aim.py

# 设置 Nacos 环境变量（构建时必需，从 ARG 传递）
ENV NACOS_HOST=${NACOS_HOST}
ENV NACOS_PORT=${NACOS_PORT}

# 设置非 root 用户
#RUN addgroup -S appgroup && adduser -S appuser -G appgroup
# 健康检查


# 入口点
ENTRYPOINT ["/app/remote-task-executor-cli", "train"]
