-
-
Save simbo1905/d38a27b785878ac1dac1e789b4361d22 to your computer and use it in GitHub Desktop.
OKD openshift randomise which database portal host to use for compose.com high availability
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
if [[ ! -z ${DB_HOST_LIST} ]]; then | |
echo "Selecting DB_HOST from ${DB_HOST_LIST}" | |
SELECT_LIST_SEPERATOR="," | |
SELECT_ARRAY=( ${DB_HOST_LIST//$SELECT_LIST_SEPERATOR/ } ) | |
export DB_HOST="${SELECT_ARRAY[$RANDOM % ${#SELECT_ARRAY[@]}]}" | |
echo "DB_HOST=${DB_HOST}" | |
fi | |
source ${STI_SCRIPTS_PATH}/run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
At compose.com they give you two entrypoints to your high availability database cluster such as:
aws-eu-west-1-portal.2.dblayer.com:18686
aws-eu-west-1-portal.0.dblayer.com:18686
if you hard configure your DB_HOST to one or the other hostname then you have a single point of failure at the portal entry point. You may then need to manually reconfigure to use the surviving portal (aka HAProxy fronting your db as a TCP proxy).
with this snippet executable at
.s2i/bin/run
you can set DB_HOST_LIST as a comma-separated list like:docker run -u 100000 -p 8080:8080 --env-file=./.env.staging -e DB_HOST_LIST="aws-eu-west-1-portal.0.dblayer.com,aws-eu-west-1-portal.2.dblayer.com" uniqkey-backend-app
and it will log:
DB_HOST=aws-eu-west-1-portal.0.dblayer.com
or:
DB_HOST=aws-eu-west-1-portal.2.dblayer.com
selected at random.
Note that if the DB_HOST is still being set as an env var when you login on the terminal you see what is set for the whole environment not how it is has been overridden in the script that launches php. The randomly selected value can be confirmed by looking at the
/proc/1/environ
(the environment of the process that docker launched):This means that when we set this new code and the new env var
DB_HOST_LIST
we should delete the oldDB_HOST
that is ignored else it will cause confusion by being visible in the terminal and web console of openshift.