Skip to content

Commit

Permalink
Validate if all required env vars are supplied. (#12879)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
scheibinger authored Apr 24, 2024
1 parent f78f0b5 commit 0f28e36
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions crib/devspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions crib/scripts/check_env_vars.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0f28e36

Please sign in to comment.