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..c954365 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/ianbelcher/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: false outputs: kubectl-out: description: The output of the kubectl command diff --git a/entrypoint.sh b/entrypoint.sh index 4fd703e..fa5c239 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -21,6 +21,20 @@ if [ -n "${INPUT_AWS_REGION:-}" ]; then export AWS_DEFAULT_REGION="${INPUT_AWS_REGION}" fi +if [ -n "${INPUT_KUBERNETES_VERSION:-}" ]; then + 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" + 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 +43,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 +60,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