From 5cb54c76375d585eb97f21a7b3599671d9d5fd7c Mon Sep 17 00:00:00 2001 From: Erick Navarro Date: Tue, 12 Mar 2024 23:10:06 -0600 Subject: [PATCH] Replace cert, server and token with a single input (#2) kube_config input will be used now, it will contains a regular kubeconfig file and all the required information will be extracted from there --- Dockerfile | 2 +- README.md | 16 +++++++++++++--- action.yml | 11 +++-------- entrypoint.sh | 8 +++++--- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1e4426e..e247259 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM alpine:3.17 -RUN apk --update add curl bash jq +RUN apk --update add curl bash jq yq # Download kubectl binary RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" diff --git a/README.md b/README.md index 97a9de9..408706a 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,7 @@ This action will run `kubectl` to update the given deployment container with a n | Input | Required | Description | |-----------------|----------|--------------------------------------------------------------------------------------------------------------------------| -| cert | yes | base64 encoded certificate | -| server | yes | server host | -| token | yes | authentication token | +| kube_config | yes | cluster kubeconfig file, encoded in base64 | | namespace | yes | deployment's namespace to be updated | | name | yes | deployment's name to be updated | | image | yes | image name what will be used in the update, example: `org/repo:version` | @@ -31,4 +29,16 @@ This action will run `kubectl` to update the given deployment container with a n external_secret: app-external-secret ``` +```yaml +- name: Update deployment container image + uses: resuelve/deploy-to-kubernetes-action@v2 + with: + kube_config: ${{ secrets.KUBERNETES_KUBE_CONFIG }} + namespace: default + name: my_project + image: new_image_name + container: backend + external_secret: app-external-secret +``` + Enjoy 🎉 diff --git a/action.yml b/action.yml index 7df5aa3..b7fcf85 100644 --- a/action.yml +++ b/action.yml @@ -1,14 +1,9 @@ +--- name: "Update kubernetes deployment image" description: "Update kubernetes deployment image" inputs: - cert: - description: "k8s cluster certificate" - required: true - server: - description: "k8s cluster server" - required: true - token: - description: "k8s cluster token" + kube_config: + description: "Kube config, regular kubeconfig file enccoded in base64" required: true namespace: description: "Namespace where deployment is located" diff --git a/entrypoint.sh b/entrypoint.sh index 686f486..a77fa63 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,9 +2,6 @@ # exit on any error set -e -KUBERNETES_CERT="${INPUT_CERT}" -KUBERNETES_SERVER="${INPUT_SERVER}" -KUBERNETES_TOKEN="${INPUT_TOKEN}" KUBERNETES_USER="default" CONTEXT="default" CLUSTER_NAME="default" @@ -13,6 +10,11 @@ DEPLOYMENT="${INPUT_NAME}" IMAGE="${INPUT_IMAGE}" CONTAINER="${INPUT_CONTAINER}" EXTERNAL_SECRET="${INPUT_EXTERNAL_SECRET}" +KUBE_CONFIG="${INPUT_KUBE_CONFIG}" + +KUBERNETES_CERT=$(echo "$KUBE_CONFIG" | base64 -d | yq .clusters.0.cluster.certificate-authority-data) +KUBERNETES_SERVER=$(echo "$KUBE_CONFIG" | base64 -d | yq .clusters.0.cluster.server) +KUBERNETES_TOKEN=$(echo "$KUBE_CONFIG" | base64 -d | yq .users.0.user.token) echo "${KUBERNETES_CERT}" | base64 -d >ca.crt