Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate if all required env vars are supplied. #12879

Merged
merged 7 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
chainchad marked this conversation as resolved.
Show resolved Hide resolved

# 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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might not be obvious to someone what vars they need to set from this message. WDYT about printing the $required_vars here or printing the path to the .env.example file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, I updated the script to print more instructions

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
Loading