2017-02-08 06:04:53 +00:00
|
|
|
#!/bin/bash
|
2017-01-13 10:07:48 +00:00
|
|
|
|
2019-01-08 20:41:10 +00:00
|
|
|
set -euo pipefail
|
2019-01-08 14:37:44 +00:00
|
|
|
|
|
|
|
export KUBECONFIG=/tmp/kubeconfig
|
|
|
|
|
2019-01-08 20:41:10 +00:00
|
|
|
if [ -z "${PLUGIN_KUBERNETES_TOKEN:-}" ]; then
|
|
|
|
echo "ERROR: You must set 'kubernetes_token'"
|
|
|
|
exit 1
|
2017-01-16 02:00:29 +00:00
|
|
|
fi
|
|
|
|
|
2019-01-08 20:41:10 +00:00
|
|
|
if [ -z "${PLUGIN_TAG:-}" ]; then
|
|
|
|
echo "ERROR: You must set 'tag'"
|
|
|
|
exit 1
|
2018-04-06 10:39:06 +00:00
|
|
|
fi
|
|
|
|
|
2019-01-08 20:41:10 +00:00
|
|
|
if [ -z "${PLUGIN_REPO:-}" ]; then
|
|
|
|
echo "ERROR: You must set 'repo'"
|
|
|
|
exit 1
|
2017-02-07 06:09:44 +00:00
|
|
|
fi
|
|
|
|
|
2019-01-08 20:41:10 +00:00
|
|
|
if [ -z "${PLUGIN_KUBERNETES_SERVER:-}" ]; then
|
|
|
|
echo "ERROR: You must set 'kubernetes_server'"
|
|
|
|
exit 1
|
2017-02-07 06:09:44 +00:00
|
|
|
fi
|
|
|
|
|
2019-01-08 20:41:10 +00:00
|
|
|
if [ -z "${PLUGIN_DEPLOYMENT:-}" ]; then
|
|
|
|
echo "ERROR: You must set 'deployment'"
|
|
|
|
exit 1
|
2017-02-20 10:06:46 +00:00
|
|
|
fi
|
|
|
|
|
2019-01-08 20:41:10 +00:00
|
|
|
if [ -z "${PLUGIN_CONTAINER:-}" ]; then
|
|
|
|
echo "ERROR: You must set 'container'"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "${PLUGIN_NAMESPACE:-}" ]; then
|
|
|
|
PLUGIN_NAMESPACE="default"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "${PLUGIN_KUBERNETES_USER:-}" ]; then
|
|
|
|
PLUGIN_KUBERNETES_USER="default"
|
|
|
|
fi
|
|
|
|
|
|
|
|
kubectl config set-credentials default --token=${PLUGIN_KUBERNETES_TOKEN}
|
|
|
|
if [ -z "${PLUGIN_KUBERNETES_CERT:-}" ]; then
|
2017-02-20 10:20:47 +00:00
|
|
|
echo "WARNING: Using insecure connection to cluster"
|
2019-01-08 20:41:10 +00:00
|
|
|
kubectl config set-cluster default --server=${PLUGIN_KUBERNETES_SERVER} --insecure-skip-tls-verify=true
|
|
|
|
else
|
|
|
|
echo "${PLUGIN_KUBERNETES_CERT}" | base64 -d > ca.crt
|
|
|
|
kubectl config set-cluster default --server=${PLUGIN_KUBERNETES_SERVER} --certificate-authority=ca.crt
|
2017-02-20 09:22:24 +00:00
|
|
|
fi
|
|
|
|
|
2018-04-06 10:39:06 +00:00
|
|
|
kubectl config set-context default --cluster=default --user=${PLUGIN_KUBERNETES_USER}
|
2017-01-13 10:07:48 +00:00
|
|
|
kubectl config use-context default
|
2017-02-20 10:20:47 +00:00
|
|
|
|
2019-01-08 20:41:10 +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
|
2019-01-08 20:41:10 +00:00
|
|
|
echo Deploying to $PLUGIN_KUBERNETES_SERVER
|
2017-03-07 09:53:50 +00:00
|
|
|
for CONTAINER in ${CONTAINERS[@]}; do
|
2019-01-08 20:41:10 +00:00
|
|
|
if [ ${PLUGIN_FORCE:-} == "true" ]; then
|
|
|
|
# force changing the image by changing it to the TAG + FORCE then changing it back
|
2018-04-06 10:39:06 +00:00
|
|
|
kubectl -n ${PLUGIN_NAMESPACE} set image deployment/${DEPLOY} \
|
2019-01-08 20:41:10 +00:00
|
|
|
${CONTAINER}=${PLUGIN_REPO}:${PLUGIN_TAG:-}FORCE
|
2018-04-06 10:39:06 +00:00
|
|
|
fi
|
2017-03-07 09:53:50 +00:00
|
|
|
kubectl -n ${PLUGIN_NAMESPACE} set image deployment/${DEPLOY} \
|
2019-01-08 20:41:10 +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
|