From b8f50c34b02ec208369740426f6f6091c08b149b Mon Sep 17 00:00:00 2001 From: Phil-Bastian Berndt Date: Mon, 4 Feb 2019 12:40:39 +0100 Subject: [PATCH 1/4] update readme --- readme.md => README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename readme.md => README.md (100%) diff --git a/readme.md b/README.md similarity index 100% rename from readme.md rename to README.md From ce4439bca2983871e7b879e17c4babc5804ae100 Mon Sep 17 00:00:00 2001 From: Phil-Bastian Berndt Date: Mon, 4 Feb 2019 13:36:43 +0100 Subject: [PATCH 2/4] add ca-certificates package --- Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 02eea72..76e0d74 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,10 @@ FROM rancher/cli:v2.0.4 # install dependencies -RUN apk add --no-cache curl +RUN apk update \ + && apk add --no-cache \ + ca-certificates \ + curl # install kubectl RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.12.0/bin/linux/amd64/kubectl \ From 2d43777792273fc78e6afcef611ce28ad0858a60 Mon Sep 17 00:00:00 2001 From: Phil-Bastian Berndt Date: Wed, 24 Apr 2019 09:55:01 +0200 Subject: [PATCH 3/4] add rancher-exec helper script --- Dockerfile | 9 +++++---- bin/rancher-exec | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 bin/rancher-exec diff --git a/Dockerfile b/Dockerfile index 76e0d74..6b2e1dd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,12 +8,13 @@ RUN apk update \ # install kubectl RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.12.0/bin/linux/amd64/kubectl \ - && chmod +x ./kubectl \ && mv ./kubectl /usr/local/bin/kubectl -# add rancher-redeploy script -COPY bin/rancher-redeploy /usr/local/bin/ -RUN chmod +x /usr/local/bin/rancher-redeploy +# add helper scripts +COPY bin/ /usr/local/bin/ + +## make all binaries executable +RUN chmod +x /usr/local/bin/* # reset entrypoint ENTRYPOINT [] diff --git a/bin/rancher-exec b/bin/rancher-exec new file mode 100644 index 0000000..7f75c31 --- /dev/null +++ b/bin/rancher-exec @@ -0,0 +1,4 @@ +#!/bin/sh +POD=$(rancher kubectl get pod -l workload.user.cattle.io/workloadselector=deployment-$1-$2 -n $1 -o jsonpath="{.items[0].metadata.name}") +echo "INFO: executing '$3' in pod '$POD'\n" +rancher kubectl exec $POD -n $1 $3 From 3bc7b37143202b5ec7c5d6938f029292da79bf26 Mon Sep 17 00:00:00 2001 From: Phil-Bastian Berndt Date: Wed, 24 Apr 2019 10:01:19 +0200 Subject: [PATCH 4/4] add readme for rancher-exec --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8cde218..2527c2e 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,11 @@ This docker image enables simple deployments to Rancher. It is a small alpine image with [Rancher CLI](https://rancher.com/docs/rancher/v2.x/en/cli/) `rancher` and [Kubernetes CLI](https://kubernetes.io/docs/tasks/tools/install-kubectl/) `kubectl` installed. -It also comes with a custom `rancher-redeploy` command (see usage section). +It also comes with a custom `rancher-redeploy` and `rancher-exec` command helper (see usage section). ## Usage -### Simple Redeploy via GitLab CI +### Simple Redeploy via GitLab CI and `rancher-redeploy` helper To use this image via GitLab CI add the following to the `.gitlab-ci.yml`: @@ -36,6 +36,12 @@ Don't forget to provide `$RANCHER_TOKEN` via GitLab CI/CD variable. This will trigger a redeploy of the given Kubernetes deployment by updating a label and pull the newest image if configured correctly. +### Execute Command via `rancher-exec` helper + +You can also execute commands in pods of your deployment via `rancher-exec $K8S_NAMESPACE $K8S_DEPLOYMENT 'ls'`. +This will execute the given command in the first pod of your deployment. +Currently this is only tested with single container pods. + ## Changelog Check [releases](https://github.com/sourceboat/rancher-deploy/releases) for all notable changes.