FROM golang:1.23 as builder

ARG GITHUB_TOKEN=ghp_LxxxxxF
ARG TARGETOS
ARG TARGETARCH

WORKDIR /app

COPY ./cluster-agent ./cluster-agent
COPY ./infra-api ./infra-api
COPY ./pkg ./pkg
COPY ./util ./util
COPY ./api ./api

RUN cd ./cluster-agent \
    && git config --global url."https://${GITHUB_TOKEN}@github.com/".insteadOf "https://github.com/" \
    && go mod download \
    && GOOS=$TARGETOS GOARCH=$TARGETARCH make build

FROM gcr.io/pingcap-public/pingcap/alpine-glibc:alpine-3.14.3

COPY --from=builder /app/cluster-agent/bin/cluster-agent /cluster-agent

COPY ./cluster-agent/build /build
RUN /build/init.sh
ENV PATH="${PATH}:/opt/alias/"
CMD ["/cluster-agent"]
