From 30427273626962e8e9aed108c86a180922b182ac Mon Sep 17 00:00:00 2001 From: Charles Martinot Date: Tue, 7 Feb 2017 14:09:44 +0800 Subject: [PATCH] Add handling environments --- README.md | 28 +++++++++++++++++++++++++++- update.sh | 12 ++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1c19708..8f24034 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,35 @@ This pipeline will update the `my-deployment` deployment with the image tagged ` deployment: my-deployment repo: myorg/myrepo container: my-container - namespace: default tag: ${DRONE_COMMIT_SHA:8} +This more complex example demonstrates how to deploy to several environments based on the branch, in a `app` namespace + + pipeline: + deploy-staging: + image: quay.io/honestbee/drone-kubernetes + kubernetes_server: ${KUBERNETES_SERVER_STAGING} + kubernetes_token: ${KUBERNETES_TOKEN_STAGING} + deployment: my-deployment + repo: myorg/myrepo + container: my-container + namespace: app + tag: ${DRONE_COMMIT_SHA:8} + when: + branch: [ staging ] + + deploy-prod: + image: quay.io/honestbee/drone-kubernetes + kubernetes_server: ${KUBERNETES_SERVER_PROD} + kubernetes_token: ${KUBERNETES_TOKEN_PROD} + deployment: my-deployment + repo: myorg/myrepo + container: my-container + namespace: app + tag: ${DRONE_COMMIT_SHA:8} + when: + branch: [ master ] + ## Required secrets drone secret add --image=honestbee/drone-kubernetes \ diff --git a/update.sh b/update.sh index ef7c2c4..9b2f74d 100644 --- a/update.sh +++ b/update.sh @@ -4,8 +4,16 @@ if [ -z ${PLUGIN_NAMESPACE} ]; then PLUGIN_NAMESPACE="default" fi -kubectl config set-credentials default --token=${KUBERNETES_TOKEN} -kubectl config set-cluster default --server=${KUBERNETES_SERVER} --insecure-skip-tls-verify=true +if [ -z PLUGIN_KUBERNETES_TOKEN ]; then + PLUGIN_KUBERNETES_TOKEN = $KUBERNETES_TOKEN +fi + +if [ -z PLUGIN_KUBERNETES_SERVER ]; then + PLUGIN_KUBERNETES_SERVER = $KUBERNETES_SERVER +fi + +kubectl config set-credentials default --token=${PLUGIN_KUBERNETES_TOKEN} +kubectl config set-cluster default --server=${PLUGIN_KUBERNETES_SERVER} --insecure-skip-tls-verify=true kubectl config set-context default --cluster=default --user=default kubectl config use-context default kubectl -n ${PLUGIN_NAMESPACE} set image deployment/${PLUGIN_DEPLOYMENT} ${PLUGIN_CONTAINER}=${PLUGIN_REPO}:${PLUGIN_TAG}