diff --git a/Dockerfile b/Dockerfile index f8e24d0..3f9224d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,7 @@ ARG HELM_VERSION=3.2.1 ARG KUBECTL_VERSION=1.17.5 ARG KUSTOMIZE_VERSION=v3.8.1 ARG KUBESEAL_VERSION=v0.15.0 +ARG AWS_CLI_VERSION=2.1.39 # Install helm (latest release) # ENV BASE_URL="https://storage.googleapis.com/kubernetes-helm" @@ -42,17 +43,28 @@ RUN curl -sL "https://github.com/weaveworks/eksctl/releases/latest/download/eksc mv /tmp/eksctl /usr/bin && \ chmod +x /usr/bin/eksctl -# Install awscli +# Install awscli v1 RUN apk add --update --no-cache python3 && \ - python3 -m ensurepip && \ - pip3 install --upgrade pip && \ - pip3 install awscli && \ - pip3 cache purge + ln -s /usr/bin/python3 /usr/bin/python && \ + curl -sL "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscliv1.zip" && \ + unzip awscliv1.zip && \ + ./awscli-bundle/install -i /usr/local/aws-cli-v1 -b /usr/local/bin/awsv1 && \ + chmod +x /usr/local/bin/awsv1 && \ + rm -rf awscliv1.zip awscli-bundle + +# Install awscli v2 +RUN apk add --update --no-cache gcompat groff && \ + curl -sL "https://awscli.amazonaws.com/awscli-exe-linux-x86_64-${AWS_CLI_VERSION}.zip" -o "awscliv2.zip" && \ + unzip awscliv2.zip && \ + ./aws/install -i /usr/local/aws-cli-v2 -b /usr/local/bin && \ + chmod +x /usr/local/bin/aws && \ + mv /usr/local/bin/aws /usr/local/bin/awsv2 && \ + rm -rf awscliv2.zip aws # https://docs.aws.amazon.com/eks/latest/userguide/install-aws-iam-authenticator.html # Install aws-iam-authenticator -RUN authenticator=$(aws --no-sign-request s3 ls s3://amazon-eks --recursive |grep aws-iam-authenticator$|grep amd64 |awk '{print $NF}' |sort -V|tail -1) && \ - aws --no-sign-request s3 cp s3://amazon-eks/${authenticator} /usr/bin/aws-iam-authenticator && \ +RUN authenticator=$(awsv1 --no-sign-request s3 ls s3://amazon-eks --recursive |grep aws-iam-authenticator$|grep amd64 |awk '{print $NF}' |sort -V|tail -1) && \ + awsv1 --no-sign-request s3 cp s3://amazon-eks/${authenticator} /usr/bin/aws-iam-authenticator && \ chmod +x /usr/bin/aws-iam-authenticator # Install jq @@ -66,4 +78,8 @@ RUN curl -sL https://github.com/bitnami-labs/sealed-secrets/releases/download/${ mv kubeseal /usr/bin/kubeseal && \ chmod +x /usr/bin/kubeseal +COPY entrypoint.sh entrypoint.sh + WORKDIR /apps + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md index c1d7105..9673c21 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,8 @@ There is no `latest` tag for this image - [helm-push](https://github.com/chartmuseum/helm-push) (latest commit) - [aws-iam-authenticator](https://github.com/kubernetes-sigs/aws-iam-authenticator) (latest version when run the build) - [eksctl](https://github.com/weaveworks/eksctl) (latest version when run the build) -- [awscli v1](https://github.com/aws/aws-cli) (latest version when run the build) +- [awscliv1](https://github.com/aws/aws-cli) (latest version when run the build) +- [awscliv2](https://github.com/aws/aws-cli) (v2.1.39) - [kubeseal](https://github.com/bitnami-labs/sealed-secrets) (latest version when run the build) - General tools, such as bash, curl @@ -34,6 +35,15 @@ https://app.circleci.com/pipelines/github/alpine-docker/k8s https://hub.docker.com/r/alpine/k8s/tags/ +# Quick start +Set environmental variable `awscli` to `v2` to use awscliv2 by default, otherwise awscliv1 is used. + +To pass an environmental variable to a docker image use the `-e` option: + +``` +docker -e awscli=v2 ... +``` + # Why we need it Mostly it is used during CI/CD (continuous integration and continuous delivery) or as part of an automated build/deployment diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..59d696b --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,4 @@ +#!/bin/sh +[ "v2" == "$awscli" ] && ln -s /usr/local/bin/awsv2 /usr/bin/aws || ln -s /usr/local/bin/awsv1 /usr/bin/aws + +exec "$@" \ No newline at end of file