Created
April 17, 2024 01:34
-
-
Save hungtcs/09209f96bbe58d9eee59d1e093562cbc to your computer and use it in GitHub Desktop.
docker 支持使用 ENV_FILE 环境变量
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 bash | |
# set -v | |
set -e | |
file_env() { | |
local var="$1" | |
local fileVar="${var}_FILE" | |
local def="${2:-}" | |
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then | |
echo >&2 "error: both $var and $fileVar are set (but are exclusive)" | |
exit 1 | |
fi | |
local val="$def" | |
if [ "${!var:-}" ]; then | |
val="${!var}" | |
elif [ "${!fileVar:-}" ]; then | |
val="$(< "${!fileVar}")" | |
fi | |
export "$var"="$val" | |
unset "$fileVar" | |
} | |
docker_setup_env() { | |
file_env "DATABASE_USERNAME" | |
file_env "DATABASE_PASSWORD" | |
} | |
docker_setup_env | |
exec /opt/datadata/_datadata "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment