From 0f28e363920a5d07587ed3b3db028ef232b88b6b Mon Sep 17 00:00:00 2001 From: Radek Scheibinger Date: Wed, 24 Apr 2024 16:34:47 +0200 Subject: [PATCH] Validate if all required env vars are supplied. (#12879) * Decouple crib config from cl-cluster helm chart * Validate required env vars Validate if all required env vars are supplied * explain how to fix missing vars * add info about example --- crib/devspace.yaml | 2 ++ crib/scripts/check_env_vars.sh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100755 crib/scripts/check_env_vars.sh diff --git a/crib/devspace.yaml b/crib/devspace.yaml index cc82c6a464c..9c2895e9ac6 100644 --- a/crib/devspace.yaml +++ b/crib/devspace.yaml @@ -73,6 +73,8 @@ images: MACOS_SDK_DIR=$(pwd)/tools/bin/MacOSX12.3.sdk IMAGE=$image ./tools/bin/goreleaser_wrapper release --snapshot --clean --config .goreleaser.devspace.yaml docker push $image hooks: + - command: ./scripts/check_env_vars.sh + events: [ "before:deploy:app" ] - wait: running: true terminatedWithCode: 0 diff --git a/crib/scripts/check_env_vars.sh b/crib/scripts/check_env_vars.sh new file mode 100755 index 00000000000..f26f78e7470 --- /dev/null +++ b/crib/scripts/check_env_vars.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# List of required environment variables +required_vars=( + "DEVSPACE_IMAGE" + "DEVSPACE_INGRESS_CIDRS" + "DEVSPACE_INGRESS_BASE_DOMAIN" + "DEVSPACE_INGRESS_CERT_ARN" + "DEVSPACE_K8S_POD_WAIT_TIMEOUT" + "NS_TTL" + ) + +missing_vars=0 # Counter for missing variables + +# Check each variable +for var in "${required_vars[@]}"; do + if [ -z "${!var}" ]; then # If variable is unset or empty + echo "Error: Environment variable $var is not set." + missing_vars=$((missing_vars + 1)) + fi +done + +# Exit with an error if any variables were missing +if [ $missing_vars -ne 0 ]; then + echo "Total missing environment variables: $missing_vars" + echo "To fix it, add missing variables in the \"crib/.env\" file." + echo "you can find example of the .env config in the \"crib/.env.example\"" + exit 1 +else + echo "All required environment variables are set." +fi \ No newline at end of file