├── Dockerfile ├── README.md ├── action.yml └── entrypoint.sh /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.11 2 | 3 | ARG KUBECTL_VERSION="1.15.10" 4 | 5 | RUN apk add py-pip curl 6 | RUN pip install awscli 7 | RUN curl -L -o /usr/bin/kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.15.10/2020-02-22/bin/linux/amd64/kubectl 8 | RUN chmod +x /usr/bin/kubectl 9 | 10 | COPY entrypoint.sh /entrypoint.sh 11 | ENTRYPOINT ["/entrypoint.sh"] 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | kubernetes-action 2 | ============= 3 | Interacts with kubernetes clusters calling `kubectl` commands. Integrates support for **AWS EKS**. 4 | 5 | ## Usage 6 | 7 | ### Basic Example 8 | 9 | ```yml 10 | name: CI 11 | 12 | on: 13 | - push 14 | 15 | jobs: 16 | deploy: 17 | runs-on: ubuntu-latest 18 | steps: 19 | - uses: actions/checkout@v2 20 | 21 | - name: Trigger deploy 22 | uses: Consensys/kubernetes-action@master 23 | env: 24 | KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }} 25 | with: 26 | args: apply deployment.yaml 27 | ``` 28 | 29 | ### EKS Example 30 | ```yml 31 | name: CI 32 | 33 | on: 34 | - push 35 | 36 | jobs: 37 | deploy: 38 | runs-on: ubuntu-latest 39 | steps: 40 | - uses: actions/checkout@v2 41 | 42 | - name: Configure AWS Credentials 43 | uses: aws-actions/configure-aws-credentials@v1 44 | with: 45 | aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} 46 | aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} 47 | aws-region: us-east-1 48 | 49 | - name: Trigger deploy 50 | uses: Consensys/kubernetes-action@master 51 | env: 52 | KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }} 53 | with: 54 | args: apply deployment.yaml 55 | ``` 56 | 57 | ## Config 58 | 59 | ### Secrets 60 | 61 | One or more **secrets** needs to be created to store cluster credentials. (see [here](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets) for help on creating secrets). 62 | 63 | #### Basic 64 | - **KUBE_CONFIG_DATA**: A `base64` representation of `~/.kube/config` file. 65 | 66 | ##### Example 67 | ```bash 68 | cat ~/.kube/config | base64 | pbcopy # pbcopy will copy the secret to the clipboard (Mac OSX only) 69 | ``` 70 | 71 | #### EKS 72 | - **KUBE_CONFIG_DATA**: Same as Basic configuration above. 73 | 74 | - **AWS_ACCESS_KEY_ID**: AWS_ACCESS_KEY_ID of a IAM user with permissions to access the cluster. 75 | 76 | - **AWS_SECRET_ACCESS_KEY**: AWS_SECRET_ACCESS_KEY of a IAM user with permissions to access the cluster. 77 | 78 | Make sure your users has the proper IAM permissions to access your cluster and that its configured inside kubernetes (more info [here](https://docs.aws.amazon.com/eks/latest/userguide/add-user-role.html)). 79 | 80 | ## Outputs 81 | 82 | - **result**: Output of the `kubectl` command. 83 | 84 | ### Example 85 | ```yaml 86 | - name: Save container image 87 | id: image-save 88 | uses: Consensys/kubernetes-action@master 89 | env: 90 | KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }} 91 | with: 92 | args: get deploy foo -o jsonpath="{..image}" 93 | 94 | - name: Print image 95 | run: 96 | echo ${{ steps.image-save.outputs.result }} 97 | ``` 98 | 99 | More info on how to use outputs [here](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/metadata-syntax-for-github-actions#outputs). 100 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: "Kubernetes Action" 2 | description: "Interacts with kubernetes clusters calling kubectl commands. Integrates support for AWS EKS." 3 | branding: 4 | icon: 'anchor' 5 | color: 'blue' 6 | inputs: 7 | args: 8 | description: "Arguments of kubectl" 9 | required: true 10 | outputs: 11 | result: 12 | description: "Output of the kubectl command run" 13 | runs: 14 | using: "docker" 15 | image: "Dockerfile" 16 | args: 17 | - ${{ inputs.args }} 18 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -l 2 | 3 | echo ${KUBE_CONFIG_DATA} | base64 -d > kubeconfig 4 | export KUBECONFIG=kubeconfig 5 | 6 | result="$(kubectl $1)" 7 | 8 | status=$? 9 | echo ::set-output name=result::$result 10 | echo "$result" 11 | if [[ $status -eq 0 ]]; then exit 0; else exit 1; fi 12 | --------------------------------------------------------------------------------