Skip to content

Instantly share code, notes, and snippets.

@hungtcs
Created April 17, 2024 01:34
Show Gist options
  • Save hungtcs/09209f96bbe58d9eee59d1e093562cbc to your computer and use it in GitHub Desktop.
Save hungtcs/09209f96bbe58d9eee59d1e093562cbc to your computer and use it in GitHub Desktop.
docker 支持使用 ENV_FILE 环境变量
#!/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