Commit 48caeb10 authored by Andrew Newdigate's avatar Andrew Newdigate
Browse files

Structure only

parent 7fb32ab3
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# shellcheck disable=SC1091,SC1090
source "${SCRIPT_DIR}/workflow-script-commons.sh"
# --------------------------------------------------------------
echo "Success, you're ready to failover."
......@@ -38,33 +38,43 @@ function gnu_readlink() {
}
function ensure_valid() {
source_vars_file=$(gnu_readlink -f "${SOURCE_VARS_DIR}/source_vars")
grep -Eho '(\w+)="__REQUIRED__"' ./bin/source_vars_template.sh |cut -d= -f1 | while read -r i; do
if [[ ${!i:=__REQUIRED__} = "__REQUIRED__" ]]; then
die "Variable ${i} has not been configured. You may need to update your 'source_vars'"
die "Variable ${i} has not been configured. You may need to update ${source_vars_file}"
fi
done
case ${FAILOVER_ENVIRONMENT} in
"prd") ;;
"stg") ;;
*) die "Unknown environment. Must be 'prd' or 'std': update ${source_vars_file}";;
esac
FAILOVER_DATE=$(gnu_date --date="$FAILOVER_DATE" "+%Y-%m-%d")
TODAY=$(gnu_date "+%Y-%m-%d")
if [[ "${FAILOVER_DATE}" < "${TODAY}" ]]; then
die "Failover date is in the past ${FAILOVER_DATE}. Have you updated 'source_vars'?"
die "Failover date is in the past ${FAILOVER_DATE}. Have you updated ${source_vars_file}?"
fi
case $(hostname -f) in
"deploy.gitlab.com")
"deploy-01-sv-gprd.c.gitlab-production.internal")
if [[ ${FAILOVER_ENVIRONMENT} != "prd" ]]; then
die "FAILOVER_ENVIRONMENT is ${FAILOVER_ENVIRONMENT}, but environment is detected as production. Have you updated 'source_vars'?"
die "FAILOVER_ENVIRONMENT is ${FAILOVER_ENVIRONMENT}, but environment is detected as production. Have you updated ${source_vars_file}?"
fi
;;
"deploy.stg.gitlab.com")
"deploy-01-sv-gstg.c.gitlab-staging-1.internal")
if [[ ${FAILOVER_ENVIRONMENT} != "stg" ]]; then
die "FAILOVER_ENVIRONMENT is ${FAILOVER_ENVIRONMENT}, but environment is detected as staging. Have you updated 'source_vars'?"
die "FAILOVER_ENVIRONMENT is ${FAILOVER_ENVIRONMENT}, but environment is detected as staging. Have you updated ${source_vars_file}?"
fi
;;
*)
if [[ ${SKIP_HOST_CHECK:=} != "true" ]]; then
die "Unknown host: please run this from a deploy host "
case ${FAILOVER_ENVIRONMENT} in
"prd") die "Unrecognised $(hostname -f): please run this from the GCP deploy host: deploy-01-sv-gprd.c.gitlab-production.internal. Set SKIP_HOST_CHECK=true if you know what you're doing." ;;
"stg") die "Unrecognised $(hostname -f): please run this from the GCP deploy host: deploy-01-sv-gstg.c.gitlab-staging-1.internal. Set SKIP_HOST_CHECK=true if you know what you're doing." ;;
*) die "Unrecognised $(hostname -f). Please review ${source_vars_file}" ;;
esac
fi
;;
esac
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment