Skip to content

Commit

Permalink
A new start for the kubernetes toolbox github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Bwvolleyball committed Oct 11, 2021
0 parents commit 4df702d
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM alpine

LABEL version="1.0.0"
LABEL name="k8s-toolkit"
LABEL repository="http://github.com/bwvolleyball/k8s-toolkit"
LABEL homepage="http://github.com/bwvolleyball/k8s-toolkit"

LABEL maintainer="Brandon Ward <@bwvolleyball>"
LABEL com.github.actions.name="Kubernetes Toolkit"
LABEL com.github.actions.description="Configures a kubernetes toolkit. The kube config must be provided. Includes kubernetes cli and helm."
LABEL com.github.actions.icon="terminal"
LABEL com.github.actions.color="blue"

RUN apk add --no-cache curl

COPY LICENSE README.md /
COPY entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
CMD ["help"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) [2021] [Brandon Ward]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# GitHub Actions Kubernetes Toolkit
> This action started as a fork of [steebchen/kubectl](https://github.com/steebchen/kubectl), but the solution is now very different.
> If you just need to directly run a single kubernetes command, simply use that action.
>
> If instead, you need to run multiple `kubectl` commands, or `helm`, this action installs these tools _and_ configures them,
> so that they can be used throughout the remaining steps in your job.
This action provides `kubectl` and `helm` for GitHub Actions.

As with the upstream inspiration for this project, please :star: it if you do end up using it!

## Usage

`.github/workflows/push.yml`

```yaml
on: push
name: deploy
jobs:
deploy:
name: deploy to cluster
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: deploy to cluster
uses: bwvolleyball/[email protected]
with: # defaults to latest kubectl & helm binary versions
config: ${{ secrets.KUBE_CONFIG_DATA }}
kubectl_version: v1.21.5
helm_version: v3.7.0
# After it's been configured, you can now freely use kubectl & helm commands the rest of the job.
# This could also be used for multi-cluster deployment, as long as your provided kube config has all required clusters.
- name: Check kubectl version
run: kubectl version
- name: Check helm version
run: helm version
- name: Update Deployment
run: set image --record deployment/my-app container=${{ github.repository }}:${{ github.sha }}
- name: Helm Deployment
run: helm upgrade my-release my/chart --namespace namespace
- name: verify deployment
run: helm test my-release --namespace namespace
```
## Arguments
`config` – **required**: A base64-encoded kubeconfig file with credentials for Kubernetes to access the cluster. You can get it by running the following command:

```bash
cat $HOME/.kube/config | base64
```
**Note**: Do not use kubectl config view as this will hide the certificate-authority-data.

`kubectl_version`: The kubectl version with a 'v' prefix, e.g. `v1.21.0`. It defaults to the latest kubectl binary version available.

`helm_version`: The helm version with a 'v' prefix, e.g. `v3.7.0`. It defaults to the latest helm binary version available.
Since this is read from the GitHub releases, it could easily be a pre-release binary. You are strongly encouraged to explicitly
set the version for this.
24 changes: 24 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: 'kubernetes-toolkit'
description: 'configures a kubernetes toolkit for your actions => Includes: kubectl, helm'
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.kubectl_version }}
- ${{ inputs.config }}
- ${{ inputs.helm_version }}
branding:
icon: 'terminal'
color: 'blue'
inputs:
kubectl_version:
description: 'kubectl version, e.g. `v1.21.0`, defaults to latest'
required: false
default: latest
config:
description: 'kube config data'
required: true
helm_version:
description: 'helm cli version, e.g. `v3.7.0`, defaults to latest. Not necessarily stable.'
required: false
default: latest
37 changes: 37 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh

set -e

kubectl_version="$1"
config="$2"
helm_version="$3"

if [ "$kubectl_version" = "latest" ]; then
kubectl_version=$(curl -Ls https://dl.k8s.io/release/stable.txt)
fi

echo "using kubectl@$kubectl_version"

curl -sLO "https://dl.k8s.io/release/$kubectl_version/bin/linux/amd64/kubectl" -o kubectl
chmod +x kubectl
mv kubectl /usr/local/bin

# Extract the base64 encoded config data and write this to the KUBECONFIG
export KUBE_CONFIG_FOLDER="$GITHUB_WORKSPACE/.kube"
export KUBECONFIG="$KUBE_CONFIG_FOLDER/config"

mkdir -p "$KUBE_CONFIG_FOLDER"

echo "$config" | base64 -d > "$KUBECONFIG"
echo "KUBECONFIG=./.kube/config" >> "$GITHUB_ENV"

# Install helm
if [ "$helm_version" = "latest" ]; then
helm_version=$(curl -s "https://api.github.com/repos/helm/helm/releases/latest" | awk -F '"' '/tag_name/{print $4}')
fi

echo "using helm@$helm_version"

curl -sLO "https://get.helm.sh/helm-$helm_version-linux-amd64.tar.gz" -o "helm-$helm_version-linux-amd64.tar.gz"
tar -zxvf "helm-$helm_version-linux-amd64.tar.gz"
mv linux-amd64/helm /usr/local/bin/helm

0 comments on commit 4df702d

Please sign in to comment.