Last active
November 17, 2021 17:44
-
-
Save gtoselli/b3598f6ca413442663f979ba45938bd0 to your computer and use it in GitHub Desktop.
Docker ENTRYPOINT for env check before container start
This file contains 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/bash | |
echo "Environment variables check:" | |
declare -a unset=() | |
while IFS= read -r line | |
do | |
var_name="${line//=}" | |
if [[ -z "${!var_name+x}" ]]; then | |
echo "- $var_name is unset." | |
unset+=($var_name) | |
fi | |
done < ".env" | |
if (( ${#unset[@]} > 0)); then | |
echo "${#unset[@]} unset vars. Exit! 🛑" | |
exit 1 | |
else | |
echo "All vars set. Continue! ✅" | |
fi |
This file contains 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
APP_NAME= | |
ENV_NAME= | |
APP_PORT= |
This file contains 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 | |
set -e | |
./check_env.sh | |
exec "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment