From e3553370b6e4518122a9d14000fb1b87e6f73d8e Mon Sep 17 00:00:00 2001 From: Jan <59206115+Threated@users.noreply.github.com> Date: Wed, 29 Jan 2025 13:17:59 +0100 Subject: [PATCH] feat: unify version handeling (#265) --- bridgehead | 49 ++++++++++++++++++++++++++++--------------------- versions/prod | 2 ++ versions/test | 2 ++ 3 files changed, 32 insertions(+), 21 deletions(-) create mode 100644 versions/prod create mode 100644 versions/test diff --git a/bridgehead b/bridgehead index d5d3a20..cbe7527 100755 --- a/bridgehead +++ b/bridgehead @@ -53,17 +53,44 @@ case "$PROJECT" in ;; esac +# Loads config variables and runs the projects setup script loadVars() { - # Load variables from /etc/bridgehead and /srv/docker/bridgehead set -a + # Source the project specific config file source /etc/bridgehead/$PROJECT.conf || fail_and_report 1 "/etc/bridgehead/$PROJECT.conf not found" + # Source the project specific local config file if present + # This file is ignored by git as oposed to the regular config file as it contains private site information like etl auth data if [ -e /etc/bridgehead/$PROJECT.local.conf ]; then log INFO "Applying /etc/bridgehead/$PROJECT.local.conf" source /etc/bridgehead/$PROJECT.local.conf || fail_and_report 1 "Found /etc/bridgehead/$PROJECT.local.conf but failed to import" fi + # Set execution environment on main default to prod else test + if [[ -z "${ENVIRONMENT+x}" ]]; then + if [ "$(git rev-parse --abbrev-ref HEAD)" == "main" ]; then + ENVIRONMENT="production" + else + ENVIRONMENT="test" + fi + fi + # Source the versions of the images components + case "$ENVIRONMENT" in + "production") + source ./versions/prod + ;; + "test") + source ./versions/test + ;; + *) + report_error 7 "Environment \"$ENVIRONMENT\" is unknown. Assuming production. FIX THIS!" + source ./versions/prod + ;; + esac fetchVarsFromVaultByFile /etc/bridgehead/$PROJECT.conf || fail_and_report 1 "Unable to fetchVarsFromVaultByFile" setHostname optimizeBlazeMemoryUsage + # Run project specific setup if it exists + # This will ususally modiy the `OVERRIDE` to include all the compose files that the project depends on + # This is also where projects specify which modules to load [ -e ./$PROJECT/vars ] && source ./$PROJECT/vars set +a @@ -79,26 +106,6 @@ loadVars() { fi detectCompose setupProxy - - # Set some project-independent default values - : ${ENVIRONMENT:=production} - export ENVIRONMENT - - case "$ENVIRONMENT" in - "production") - export FOCUS_TAG=main - export BEAM_TAG=main - ;; - "test") - export FOCUS_TAG=develop - export BEAM_TAG=develop - ;; - *) - report_error 7 "Environment \"$ENVIRONMENT\" is unknown. Assuming production. FIX THIS!" - export FOCUS_TAG=main - export BEAM_TAG=main - ;; - esac } case "$ACTION" in diff --git a/versions/prod b/versions/prod new file mode 100644 index 0000000..1dd754f --- /dev/null +++ b/versions/prod @@ -0,0 +1,2 @@ +FOCUS_TAG=main +BEAM_TAG=main \ No newline at end of file diff --git a/versions/test b/versions/test new file mode 100644 index 0000000..10ae062 --- /dev/null +++ b/versions/test @@ -0,0 +1,2 @@ +FOCUS_TAG=develop +BEAM_TAG=develop \ No newline at end of file