kitsune/k8s/commander.sh

63 строки
2.2 KiB
Bash
Исходник Обычный вид История

#!/bin/bash
set -exo pipefail
2018-03-15 14:51:59 +03:00
GREEN='\033[1;32m'
NC='\033[0m' # No Color
SLACK_CHANNEL=sumodev
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}
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
echo "Applying secrets";
${KUBECTL_BIN} -n "${K8S_NAMESPACE}" apply -f "regions/${REGION}/${REGION_ENV}-secrets.yaml"
else
2018-06-28 23:41:59 +03:00
echo "Secrets will *NOT* be applied";
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
post-deploy $@
if command -v slack-cli > /dev/null; then
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}>"
fi
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"
# 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 }')
${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 $@