Skip to content

Instantly share code, notes, and snippets.

@lgaticaq
Created April 6, 2021 21:30
Show Gist options
  • Save lgaticaq/95005595d6ceb08f071a568f23541d39 to your computer and use it in GitHub Desktop.
Save lgaticaq/95005595d6ceb08f071a568f23541d39 to your computer and use it in GitHub Desktop.
Docker entrypoint to add docker secrets to environment variables
#!/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