├── Dockerfile ├── LICENSE ├── README.md ├── action.yml └── entrypoint.sh /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine 2 | 3 | LABEL version="2.0.0" 4 | LABEL name="kubectl" 5 | LABEL repository="http://github.com/steebchen/kubectl" 6 | LABEL homepage="http://github.com/steebchen/kubectl" 7 | 8 | LABEL maintainer="Luca Steeb " 9 | LABEL com.github.actions.name="Kubernetes CLI - kubectl" 10 | LABEL com.github.actions.description="Runs kubectl. The config can be provided with the secret KUBE_CONFIG_DATA." 11 | LABEL com.github.actions.icon="terminal" 12 | LABEL com.github.actions.color="blue" 13 | 14 | RUN apk add --no-cache curl 15 | 16 | COPY LICENSE README.md / 17 | COPY entrypoint.sh /entrypoint.sh 18 | 19 | ENTRYPOINT ["/entrypoint.sh"] 20 | CMD ["help"] 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Luca Steeb 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GitHub Action for Kubernetes CLI 2 | 3 | This action provides `kubectl` for GitHub Actions. 4 | 5 | ## Upgrading from v1 to v2 6 | 7 | If you upgrade from v1 to v2, note that you need to specify new variables via `with`, namely `version`, `config`, and `command`. See below for an example. 8 | 9 | ## Usage 10 | 11 | `.github/workflows/push.yml` 12 | 13 | ```yaml 14 | on: push 15 | name: deploy 16 | jobs: 17 | deploy: 18 | name: deploy to cluster 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@master 22 | - name: deploy to cluster 23 | uses: steebchen/kubectl@v2.0.0 24 | with: # defaults to latest kubectl binary version 25 | config: ${{ secrets.KUBE_CONFIG_DATA }} 26 | command: set image --record deployment/my-app container=${{ github.repository }}:${{ github.sha }} 27 | - name: verify deployment 28 | uses: steebchen/kubectl@v2.0.0 29 | with: 30 | config: ${{ secrets.KUBE_CONFIG_DATA }} 31 | version: v1.21.0 # specify kubectl binary version explicitly 32 | binaries-url: "https://dl.k8s.io/release/v1.21.0/bin/linux/amd64/kubectl" # specify the download url explicitly 33 | command: rollout status deployment/my-app 34 | ``` 35 | 36 | ## Arguments 37 | 38 | `command` – **required**: The command you want to run, without `kubectl`, e.g. `get pods` 39 | 40 | `config` – **required**: A base64-encoded kubeconfig file with credentials for Kubernetes to access the cluster. You can get it by running the following command: 41 | 42 | ```bash 43 | cat $HOME/.kube/config | base64 44 | ``` 45 | 46 | `version`: The kubectl version with a 'v' prefix, e.g. `v1.21.0`. It defaults to the latest kubectl binary version available. 47 | 48 | `binaries-url`: The url to download the binaries from. It defaults to the official release page if empty. 49 | 50 | **Note**: Do not use kubectl config view as this will hide the certificate-authority-data. 51 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'kubectl-simple' 2 | description: 'The kubectl command line program as a GitHub Action' 3 | runs: 4 | using: 'docker' 5 | image: 'Dockerfile' 6 | args: 7 | - ${{ inputs.version }} 8 | - ${{ inputs.config }} 9 | - ${{ inputs.command }} 10 | - ${{ inputs.binaries-url }} 11 | branding: 12 | icon: 'terminal' 13 | color: 'blue' 14 | inputs: 15 | version: 16 | description: 'kubectl version, e.g. `v1.21.0`, defaults to latest' 17 | required: false 18 | default: latest 19 | config: 20 | description: 'kube config data' 21 | required: true 22 | command: 23 | description: 'kubectl command to run, without the kubectl, e.g. `get pods`' 24 | required: true 25 | binaries-url: 26 | description: 'Url to download the binaries from, defaults to the official dl.k8s.io url' 27 | required: false 28 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | version="$1" 6 | config="$2" 7 | command="$3" 8 | binaries_url="$4" 9 | 10 | if [ -z "$binaries_url" ]; then 11 | if [ "$version" = "latest" ]; then 12 | version=$(curl -Ls https://dl.k8s.io/release/stable.txt) 13 | fi 14 | 15 | echo "using kubectl@$version" 16 | 17 | curl -sLO "https://dl.k8s.io/release/$version/bin/linux/amd64/kubectl" -o kubectl 18 | else 19 | echo "downloading kubectl binaries from $binaries_url" 20 | curl -sLO $binaries_url -o kubectl 21 | fi 22 | 23 | chmod +x kubectl 24 | mv kubectl /usr/local/bin 25 | 26 | # Extract the base64 encoded config data and write this to the KUBECONFIG 27 | echo "$config" | base64 -d > /tmp/config 28 | export KUBECONFIG=/tmp/config 29 | 30 | sh -c "kubectl $command" 31 | --------------------------------------------------------------------------------