# Use the automatic platform ARG `BUILDPLATFORM` from Buildx to stick the builder on the native platform,
# so that we do not use emulation mechanism to build, which is VERY SLOW.
# Please refer to `https://docs.docker.com/engine/reference/builder/#from` for more info.
FROM --platform=$BUILDPLATFORM gcr.io/pingcap-public/third-party/baseimage/golang:1.25.5 AS builder

ARG GITHUB_TOKEN=ghp_LxxxxxF
RUN git config --global url."https://${GITHUB_TOKEN}@github.com/".insteadOf "https://github.com/"
WORKDIR /build

COPY . ./
# Activate the automatic platform ARG `TARGETOS` and `TARGETARCH` from Buildx,
# so that we can build different binaries for different OSes and archs.
# Please refer to `https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope` for more info.
ARG TARGETOS TARGETARCH
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build-dataflow-agent

# make sure the base image is multiarch.
# docker buildx imagetools inspect gcr.io/pingcap-public/pingcap/alpine-glibc:alpine-3.14.3
FROM gcr.io/pingcap-public/pingcap/alpine-glibc:alpine-3.14.3
COPY --from=builder /build/dist/dataflow-agent /dataflow-agent

CMD ["/dataflow-agent"]
