2017-02-08 06:04:53 +00:00
|
|
|
#!/bin/bash
|
2017-12-11 10:10:44 +00:00
|
|
|
set -euo pipefail
|
2017-01-13 10:07:48 +00:00
|
|
|
|
2018-01-09 22:32:29 +00:00
|
|
|
if [ ! -z ${PLUGIN_KUBERNETES_USER} ]; then
|
|
|
|
KUBERNETES_USER=${PLUGIN_KUBERNETES_USER:-default}
|
2017-01-16 02:00:29 +00:00
|
|
|
fi
|
|
|
|
|
2018-01-09 22:32:29 +00:00
|
|
|
if [ ! -z ${PLUGIN_KUBERNETES_ENV} ]; then
|
|
|
|
KUBERNETES_ENV=${PLUGIN_KUBERNETES_ENV}
|
|
|
|
|
|
|
|
KUBERNETES_SERVER_VAR=KUBERNETES_SERVER_${KUBERNETES_ENV}
|
|
|
|
KUBERNETES_CERT_VAR=KUBERNETES_SERVER_CERT_${KUBERNETES_ENV}
|
2017-02-07 06:09:44 +00:00
|
|
|
|
2018-01-09 22:32:29 +00:00
|
|
|
KUBERNETES_SERVER=${!KUBERNETES_SERVER_VAR}
|
|
|
|
KUBERNETES_CERT=${!KUBERNETES_CERT_VAR}
|
|
|
|
|
|
|
|
if [[ -z "${KUBERNETES_SERVER}" ]]; then
|
|
|
|
echo "ERROR: drone secret ${KUBERNETES_SERVER_VAR} not added!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z "${KUBERNETES_CERT}" ]]; then
|
|
|
|
echo "ERROR: drone secret ${KUBERNETES_CERT_VAR} not added!"
|
|
|
|
echo "Inscure connection to the cluster will be used."
|
|
|
|
fi
|
2017-12-11 11:55:48 +00:00
|
|
|
else
|
2018-01-09 22:32:29 +00:00
|
|
|
echo "ERROR: kubernetes_env not provided"
|
|
|
|
exit 1
|
2017-02-20 10:06:46 +00:00
|
|
|
fi
|
|
|
|
|
2018-01-09 22:32:29 +00:00
|
|
|
if [ -z ${PLUGIN_NAMESPACE} ]; then
|
|
|
|
PLUGIN_NAMESPACE="default"
|
2017-12-09 10:18:31 +00:00
|
|
|
fi
|
|
|
|
|
2018-01-09 22:32:29 +00:00
|
|
|
if [[ ! -z "${KUBERNETES_CLIENT_CERT}" ]] && [[ ! -z "${KUBERNETES_CLIENT_KEY}" ]]; then
|
2017-12-09 11:38:57 +00:00
|
|
|
echo "INFO: Setting client credentials with signed-certificate and key."
|
2018-01-09 23:05:00 +00:00
|
|
|
echo ${KUBERNETES_CLIENT_CERT} | base64 -d > client.crt
|
|
|
|
echo ${KUBERNETES_CLIENT_KEY} | base64 -d > client.key
|
2017-12-09 10:18:31 +00:00
|
|
|
kubectl config set-credentials ${KUBERNETES_USER} --client-certificate=client.crt --client-key=client.key
|
2017-12-11 11:55:48 +00:00
|
|
|
else
|
2018-01-09 22:32:29 +00:00
|
|
|
echo "ERROR: Provide the following authentication params:"
|
|
|
|
echo " - kubernetes_client_cert"
|
|
|
|
echo " - kubernetes_client_key"
|
|
|
|
echo "as drone secrets"
|
2017-12-11 11:55:48 +00:00
|
|
|
exit 1
|
2017-12-09 10:18:31 +00:00
|
|
|
fi
|
|
|
|
|
2018-01-09 22:32:29 +00:00
|
|
|
if [ ! -z "${KUBERNETES_CERT}" ]; then
|
2017-12-09 11:38:57 +00:00
|
|
|
echo "INFO: Using secure connection with tls-certificate."
|
2018-01-09 23:05:00 +00:00
|
|
|
echo ${KUBERNETES_CERT} | base64 -d > ca.crt
|
2017-02-20 09:22:24 +00:00
|
|
|
kubectl config set-cluster default --server=${KUBERNETES_SERVER} --certificate-authority=ca.crt
|
|
|
|
else
|
2017-02-20 10:20:47 +00:00
|
|
|
echo "WARNING: Using insecure connection to cluster"
|
2017-02-20 09:22:24 +00:00
|
|
|
kubectl config set-cluster default --server=${KUBERNETES_SERVER} --insecure-skip-tls-verify=true
|
|
|
|
fi
|
|
|
|
|
2018-01-09 22:32:29 +00:00
|
|
|
kubectl config set-context default --cluster=default --user=${KUBERNETES_USER}
|
2017-01-13 10:07:48 +00:00
|
|
|
kubectl config use-context default
|
2017-02-20 10:20:47 +00:00
|
|
|
|
2017-02-20 11:08:45 +00:00
|
|
|
# kubectl version
|
2017-03-07 09:53:50 +00:00
|
|
|
IFS=',' read -r -a DEPLOYMENTS <<< "${PLUGIN_DEPLOYMENT}"
|
|
|
|
IFS=',' read -r -a CONTAINERS <<< "${PLUGIN_CONTAINER}"
|
2017-02-08 06:22:54 +00:00
|
|
|
for DEPLOY in ${DEPLOYMENTS[@]}; do
|
2018-01-09 23:05:00 +00:00
|
|
|
echo Deploying to ${KUBERNETES_ENV}
|
2017-03-07 09:53:50 +00:00
|
|
|
for CONTAINER in ${CONTAINERS[@]}; do
|
|
|
|
kubectl -n ${PLUGIN_NAMESPACE} set image deployment/${DEPLOY} \
|
2017-05-10 02:50:51 +00:00
|
|
|
${CONTAINER}=${PLUGIN_REPO}:${PLUGIN_TAG} --record
|
2017-03-07 09:53:50 +00:00
|
|
|
done
|
2017-02-08 05:45:22 +00:00
|
|
|
done
|