# builder
FROM rockylinux:8 as builder
RUN yum update -y && yum groupinstall 'Development Tools' -y
ARG GOLANG_VERSION=1.19.8
COPY --from=docker.io/golang:$GOLANG_VERSION /usr/local/go /usr/local/go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
ENV GOPATH /go
WORKDIR /pd
COPY . .
ENV GOPROXY http://goproxy.pingcap.net,https://proxy.golang.org,direct
RUN make
RUN /pd/bin/pd-server -V
RUN /pd/bin/pd-ctl -V

#final stage
FROM rockylinux:9
COPY --from=busybox:1.34.1 /bin/busybox /bin/busybox
RUN dnf install bind-utils wget -y && dnf clean all

COPY --from=builder /pd/bin/pd-server /pd-server
COPY --from=builder /pd/bin/pd-ctl /pd-ctl

EXPOSE 2379 2380
ENTRYPOINT ["/pd-server"]
