From f4fe314109753c651244279a7939c7450cbdc11a Mon Sep 17 00:00:00 2001 From: David Makin Date: Thu, 1 Jun 2023 13:26:04 +0100 Subject: [PATCH 1/2] Add new variable kubernetes_version --- .github/workflows/build-docker-image.yaml | 7 +++++-- Dockerfile | 5 +---- README.md | 2 +- action.yml | 13 +++++++----- entrypoint.sh | 25 ++++++++++++++++------- 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build-docker-image.yaml b/.github/workflows/build-docker-image.yaml index bf180a8..d8049a0 100644 --- a/.github/workflows/build-docker-image.yaml +++ b/.github/workflows/build-docker-image.yaml @@ -15,11 +15,14 @@ jobs: steps: - uses: actions/checkout@v2 - name: Login to GitHub Container Registry - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: "⛛ downcase GITHUB_REPOSITORY" + run: | + echo "GITHUB_REPOSITORY=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV} - name: Build docker image run: | if [[ ${{ github.ref }} == 'refs/heads/master' ]]; then @@ -28,7 +31,7 @@ jobs: tag=${{ github.sha }} fi - image="ghcr.io/${GITHUB_REPOSITORY}:${tag}" + image="ghcr.io/${{ env.GITHUB_REPOSITORY }}:${tag}" docker build -t "${image}" . docker push "${image}" diff --git a/Dockerfile b/Dockerfile index 9782c30..59bd5c1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,11 +7,8 @@ ENV PYTHONIOENCODING=UTF-8 RUN apk add --no-cache curl RUN pip install awscli -RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl -RUN chmod +x ./kubectl -RUN mv ./kubectl /usr/local/bin/kubectl ADD entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md index 91c8927..6d3dd6e 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ jobs: aws_region: ${{ secrets.AWS_REGION }} cluster_name: ${{ secrets.CLUSTER_NAME }} eks_role_arn: ${{ secrets.EKS_ROLE_ARN }} + kubernetes_version: v1.21.0 args: set image --record deployment/pod-name pod-name=${{ steps.build.outputs.IMAGE_URL }} # --- # ``` @@ -58,7 +59,6 @@ jobs: ``` ### Outputs - The action exports the following outputs: - `kubectl-out`: The output of `kubectl`. diff --git a/action.yml b/action.yml index cc1db28..da413b1 100644 --- a/action.yml +++ b/action.yml @@ -1,12 +1,12 @@ -name: 'EKS kubectl' +name: "EKS kubectl" author: Ian Belcher description: An action allowing you to integrate with EKS via kubectl in a Github Action, easily... branding: - color: 'white' - icon: 'command' + color: "white" + icon: "command" runs: - using: 'docker' - image: 'docker://ghcr.io/ianbelcher/eks-kubectl-action:latest' + using: "docker" + image: "docker://ghcr.io/agreena-aps/eks-kubectl-action:latest" inputs: aws_access_key_id: description: Your AWS_ACCESS_KEY_ID @@ -29,6 +29,9 @@ inputs: args: description: The arguments that you want to pass through to the kubectl command required: true + kubernetes_version: + description: Kubernetes version to use for kubectl (ie, v1.21.0) + required: true outputs: kubectl-out: description: The output of the kubectl command diff --git a/entrypoint.sh b/entrypoint.sh index 4fd703e..5a9d7c6 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -21,6 +21,17 @@ if [ -n "${INPUT_AWS_REGION:-}" ]; then export AWS_DEFAULT_REGION="${INPUT_AWS_REGION}" fi +if [ -n "${INPUT_KUBERNETES_VERSION:-}" ]; then + export KUBERNETES_VERSION="${INPUT_KUBERNETES_VERSION}" +fi + +if [ ! -f "kubectl-$KUBERNETES_VERSION" ]; then + echo "Downloading https://storage.googleapis.com/kubernetes-release/release/$KUBERNETES_VERSION/bin/linux/amd64/kubectl" + curl -L "https://storage.googleapis.com/kubernetes-release/release/$KUBERNETES_VERSION/bin/linux/amd64/kubectl" -o "kubectl-$KUBERNETES_VERSION" + chmod +x ./kubectl-"$KUBERNETES_VERSION" +fi +cp ./kubectl-"$KUBERNETES_VERSION" /usr/local/bin/kubectl + echo "aws version" aws --version @@ -29,16 +40,16 @@ echo "Attempting to update kubeconfig for aws" if [ -n "${INPUT_EKS_ROLE_ARN}" ]; then aws eks update-kubeconfig --name "${INPUT_CLUSTER_NAME}" --role-arn "${INPUT_EKS_ROLE_ARN}" -else +else aws eks update-kubeconfig --name "${INPUT_CLUSTER_NAME}" fi debug "Starting kubectl collecting output" if [ -n "${INPUT_STDIN:-}" ]; then - output=$( kubectl "$@" < "${INPUT_STDIN}" ) + output=$(kubectl "$@" <"${INPUT_STDIN}") else - output=$( kubectl "$@" ) + output=$(kubectl "$@") fi debug "${output}" @@ -46,9 +57,9 @@ debug "${output}" if [ -n "${GITHUB_OUTPUT:-}" ]; then delimiter=$(mktemp -u XXXXXX) - echo "kubectl-out<<${delimiter}" >> $GITHUB_OUTPUT - echo "${output}" >> $GITHUB_OUTPUT - echo "${delimiter}" >> $GITHUB_OUTPUT + echo "kubectl-out<<${delimiter}" >>$GITHUB_OUTPUT + echo "${output}" >>$GITHUB_OUTPUT + echo "${delimiter}" >>$GITHUB_OUTPUT else echo ::set-output name=kubectl-out::"${output}" -fi \ No newline at end of file +fi From d5e5266eb043425784f95c5b4f984bb191d6c5da Mon Sep 17 00:00:00 2001 From: David Makin Date: Fri, 2 Jun 2023 10:27:43 +0100 Subject: [PATCH 2/2] Add fallback to latest if KUBERNETES_VERSION not passed --- action.yml | 4 ++-- entrypoint.sh | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index da413b1..c954365 100644 --- a/action.yml +++ b/action.yml @@ -6,7 +6,7 @@ branding: icon: "command" runs: using: "docker" - image: "docker://ghcr.io/agreena-aps/eks-kubectl-action:latest" + image: "docker://ghcr.io/ianbelcher/eks-kubectl-action:latest" inputs: aws_access_key_id: description: Your AWS_ACCESS_KEY_ID @@ -31,7 +31,7 @@ inputs: required: true kubernetes_version: description: Kubernetes version to use for kubectl (ie, v1.21.0) - required: true + required: false outputs: kubectl-out: description: The output of the kubectl command diff --git a/entrypoint.sh b/entrypoint.sh index 5a9d7c6..fa5c239 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -22,8 +22,11 @@ if [ -n "${INPUT_AWS_REGION:-}" ]; then fi if [ -n "${INPUT_KUBERNETES_VERSION:-}" ]; then - export KUBERNETES_VERSION="${INPUT_KUBERNETES_VERSION}" + KUBERNETES_VERSION="${INPUT_KUBERNETES_VERSION}" +else + KUBERNETES_VERSION="$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)" fi +export KUBERNETES_VERSION if [ ! -f "kubectl-$KUBERNETES_VERSION" ]; then echo "Downloading https://storage.googleapis.com/kubernetes-release/release/$KUBERNETES_VERSION/bin/linux/amd64/kubectl"