FROM golang:1.24 as builder

# pass GITHUB_TOKEN from command-line argument --build-arg
ARG GITHUB_TOKEN=ghp_replace_me
RUN apk update && apk add --no-cache git make
RUN git config --global url."https://${GITHUB_TOKEN}@github.com/".insteadOf "https://github.com/"
RUN go env -w GOPRIVATE=github.com/tidbcloud/*

WORKDIR /ecosystem-service
COPY go.mod go.sum /ecosystem-service/

RUN go mod download

COPY . /ecosystem-service
RUN GO111MODULE=on CGO_ENABLED=0 go build -o /ecosystem-service/build/server/server /ecosystem-service/cmd/server/
RUN GO111MODULE=on CGO_ENABLED=0 go build -o /ecosystem-service/build/server/worker /ecosystem-service/cmd/worker/


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

COPY --from=builder /ecosystem-service/build/server/server /ecosystem-service
COPY --from=builder /ecosystem-service/build/server/worker /ecosystem-service-worker

COPY api/v1/connect/connect_info.yaml /connect_info.yaml
