FROM hub.pingcap.net/keyspace/tiflash-autoscale-supervisor:tz_builder
RUN apt-get update && apt-get install -y \
    git \
    bash
RUN mkdir /tiflash && mkdir /tiflash/bin
COPY bin  /tiflash/bin/
ARG TARGETPLATFORM
ARG BUILDPLATFORM
RUN cd /tiflash/ && echo $TARGETPLATFORM \
    && if [ "$TARGETPLATFORM" = "linux/arm64" ] ; then SIMPLE_ARCH=arm64 ; else  SIMPLE_ARCH=amd64 ; fi \
    && wget --no-check-certificate https://go.dev/dl/go1.19.5.linux-$SIMPLE_ARCH.tar.gz \
    && pwd && ls -lh \
    && rm -rf /usr/local/go && tar -C /usr/local -xzf /tiflash/go1.19.5.linux-$SIMPLE_ARCH.tar.gz

COPY conf/  /tiflash/conf/
COPY supervisor_proto/ /tiflash/supervisor_proto/
COPY tiflashrpc/ /tiflash/tiflashrpc/
COPY *.go go.* *.yaml *.yml *.sh /tiflash/
RUN ls -lh /tiflash/
WORKDIR /tiflash

RUN if [ "$TARGETPLATFORM" = "linux/arm64" ] ; then SIMPLE_ARCH=aarch64 ; else  SIMPLE_ARCH=x86_64 ; fi \
    && curl "https://awscli.amazonaws.com/awscli-exe-linux-$SIMPLE_ARCH.zip" -o "awscliv2.zip" && unzip awscliv2.zip && ./aws/install

ENV PATH="/usr/local/go/bin:${PATH}"
ENV LD_LIBRARY_PATH="/tiflash/bin:$LD_LIBRARY_PATH"
RUN go mod tidy
RUN go build -o rpc_server
