2018-10-09 23:22:29 +03:00
#!/bin/bash
set -exo pipefail
2018-03-15 14:51:59 +03:00
GREEN = '\033[1;32m'
NC = '\033[0m' # No Color
2019-06-05 19:45:07 +03:00
SLACK_CHANNEL = sumodev
2019-05-11 01:28:20 +03:00
DOCKER_HUB = "https://hub.docker.com/r/itsre/sumo-kitsune/tags/"
2018-03-15 14:51:59 +03:00
function whatsdeployed {
xdg-open "https://whatsdeployed.io/s-iiX"
}
function deploy {
2018-06-28 23:41:59 +03:00
REGION = ${ 2 }
REGION_ENV = ${ 3 }
COMMIT_HASH = ${ 4 }
DEPLOY_SECRETS = ${ 5 :- NO }
2018-10-03 22:10:10 +03:00
K8S_NAMESPACE = " sumo- ${ REGION_ENV } "
2018-06-28 23:41:59 +03:00
export KUBECTL_BIN = " ./regions/ ${ REGION } /kubectl "
export KUBECONFIG = " ./regions/ ${ REGION } /kubeconfig "
if [ [ " ${ DEPLOY_SECRETS } " = = "secrets" ] ] ; then
2018-07-27 22:19:45 +03:00
echo "Applying secrets" ;
2018-10-03 22:10:10 +03:00
${ KUBECTL_BIN } -n " ${ K8S_NAMESPACE } " apply -f " regions/ ${ REGION } / ${ REGION_ENV } -secrets.yaml "
2018-07-27 22:19:45 +03:00
else
2018-06-28 23:41:59 +03:00
echo "Secrets will *NOT* be applied" ;
2018-07-27 22:19:45 +03:00
fi
2018-06-28 23:41:59 +03:00
invoke -f " regions/ ${ REGION } / ${ REGION_ENV } .yaml " deployments.create-celery --apply --tag full-${ COMMIT_HASH }
invoke -f " regions/ ${ REGION } / ${ REGION_ENV } .yaml " rollouts.status-celery
invoke -f " regions/ ${ REGION } / ${ REGION_ENV } .yaml " deployments.create-cron --apply --tag full-${ COMMIT_HASH }
invoke -f " regions/ ${ REGION } / ${ REGION_ENV } .yaml " rollouts.status-cron
invoke -f " regions/ ${ REGION } / ${ REGION_ENV } .yaml " deployments.create-web --apply --tag full-${ COMMIT_HASH }
invoke -f " regions/ ${ REGION } / ${ REGION_ENV } .yaml " rollouts.status-web
2018-10-03 22:10:10 +03:00
2018-10-09 23:22:29 +03:00
post-deploy $@
2018-10-03 22:10:10 +03:00
2018-07-27 22:19:45 +03:00
if command -v slack-cli > /dev/null; then
2019-05-11 02:12:08 +03:00
slack-cli -d " ${ SLACK_CHANNEL } " " :tada: Successfully deployed < ${ DOCKER_HUB } |full- ${ COMMIT_HASH } > to <https:// ${ REGION_ENV } - ${ REGION } .sumo.mozit.cloud/|SUMO- ${ REGION_ENV } in ${ REGION } > "
2018-07-27 22:19:45 +03:00
fi
2018-10-09 23:22:29 +03:00
printf " ${ GREEN } OK ${ NC } \n "
}
function post-deploy {
REGION = ${ 2 }
REGION_ENV = ${ 3 }
K8S_NAMESPACE = " sumo- ${ REGION_ENV } "
export KUBECTL_BIN = " ./regions/ ${ REGION } /kubectl "
export KUBECONFIG = " ./regions/ ${ REGION } /kubeconfig "
# run post-deployment tasks
echo "Running post-deployment tasks"
2019-08-26 22:47:20 +03:00
# Get the name of a running web pod on which we can run the post-deploy script
2019-09-05 17:39:36 +03:00
SUMO_POD = $( ${ KUBECTL_BIN } -n " ${ K8S_NAMESPACE } " get pods | egrep 'sumo-.*-web' | grep Running | head -1 | awk '{ print $1 }' )
2018-10-09 23:22:29 +03:00
${ KUBECTL_BIN } -n " ${ K8S_NAMESPACE } " exec " ${ SUMO_POD } " bin/run-post-deploy.sh
2018-03-15 14:51:59 +03:00
}
source venv/bin/activate
$1 $@