Created
April 6, 2021 21:30
-
-
Save lgaticaq/95005595d6ceb08f071a568f23541d39 to your computer and use it in GitHub Desktop.
Docker entrypoint to add docker secrets to environment variables
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
#!/usr/bin/env sh | |
set -e | |
file_env() { | |
envName=$1 | |
secretName="${1}_FILE" | |
eval var=\$"$envName" | |
eval fileVar=\$"$secretName" | |
def="${2:-}" | |
# shellcheck disable=SC2154 | |
if [ "$var" != "" ] && [ "$fileVar" != "" ]; then | |
echo "error: both $envName and $secretName are set (but are exclusive)" | |
exit 1 | |
fi | |
val="$def" | |
if [ "$var" != "" ]; then | |
val="${var}" | |
elif [ "$fileVar" != "" ]; then | |
val="$(cat "$fileVar")" | |
fi | |
export "$envName"="$val" | |
unset "$secretName" | |
} | |
file_env "AWS_ACCESS_KEY_ID" | |
file_env "AWS_REGION" | |
file_env "AWS_SECRET_ACCESS_KEY" | |
# Add extra environment variables | |
exec "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment