Skip to content

Commit

Permalink
Merge pull request #26 from Agreena-ApS/add-kubernetes-version
Browse files Browse the repository at this point in the history
Add new variable kubernetes_version
  • Loading branch information
ianbelcher authored Jun 2, 2023
2 parents 843a952 + d5e5266 commit 7cfe323
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 19 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/build-docker-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}"
5 changes: 1 addition & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
ENTRYPOINT ["/entrypoint.sh"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
# --- #
```
Expand Down Expand Up @@ -58,7 +59,6 @@ jobs:
```

### Outputs

The action exports the following outputs:
- `kubectl-out`: The output of `kubectl`.

Expand Down
13 changes: 8 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
28 changes: 21 additions & 7 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,26 +43,26 @@ 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}"

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
fi

0 comments on commit 7cfe323

Please sign in to comment.