FROM gcr.io/pingcap-public/pingcap/alpine:3.15.5 AS builder

WORKDIR /workspace

ARG ACK_RAM_TOOL_VERSION=0.20.0-beta.7

# when supporting arm, modify this
# Download aws-iam-authenticator
# RUN wget -O aws-iam-authenticator https://s3.us-west-2.amazonaws.com/amazon-eks/1.21.2/2021-07-05/bin/linux/amd64/aws-iam-authenticator
RUN wget -O aws-iam-authenticator https://github.com/kubernetes-sigs/aws-iam-authenticator/releases/download/v0.6.11/aws-iam-authenticator_0.6.11_linux_amd64
RUN wget -qO- "https://github.com/AliyunContainerService/ack-ram-tool/releases/download/v${ACK_RAM_TOOL_VERSION}/ack-ram-tool_${ACK_RAM_TOOL_VERSION}_Linux_x86_64.tar.gz" | tar xvz
# RUN wget -O awscliv2.zip https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/pingcap-public/pingcap/alpine-glibc:alpine-3.14.3
WORKDIR /
COPY --from=builder /workspace/aws-iam-authenticator /usr/local/bin/
COPY --from=builder /workspace/ack-ram-tool /usr/local/bin/
RUN chmod +x /usr/local/bin/aws-iam-authenticator
RUN chmod +x /usr/local/bin/ack-ram-tool
COPY bin/manager eks-provider
COPY helm-charts/* /etc/helm

# when supporting arm, modify this
# refer to https://aur.archlinux.org/packages/google-cloud-sdk-gke-gcloud-auth-plugin
RUN wget -qO- https://storage.googleapis.com/cloud-sdk-release/for_packagers/linux/google-cloud-cli-gke-gcloud-auth-plugin_404.0.0.orig_amd64.tar.gz | tar xvz

# install kubelogin
RUN wget -qO- https://github.com/Azure/kubelogin/releases/download/v0.1.4/kubelogin-linux-amd64.zip | busybox unzip -d . - && mv bin/linux_amd64/kubelogin /usr/local/bin/ && chmod +x /usr/local/bin/kubelogin

ENV PATH=$PATH:/google-cloud-sdk/bin
USER 65532:65532
ENTRYPOINT ["/eks-provider"]
