47 lines
1.0 KiB
Bash
47 lines
1.0 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
file_env() {
|
|
# 3wc: Load $VAR_FILE into $VAR - useful for secrets. See
|
|
# https://medium.com/@adrian.gheorghe.dev/using-docker-secrets-in-your-environment-variables-7a0609659aab
|
|
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"
|
|
}
|
|
|
|
load_vars() {
|
|
file_env "CMD_DB_PASSWORD"
|
|
file_env "CMD_OAUTH2_CLIENT_SECRET"
|
|
}
|
|
|
|
main() {
|
|
set -eu
|
|
|
|
load_vars
|
|
}
|
|
|
|
main
|
|
|
|
export CMD_DB_URL=postgres://$CMD_DB_USER:$CMD_DB_PASSWORD@$CMD_DB_HOST:5432/$CMD_DB_NAME
|
|
|
|
# 3wc: `source /docker-entrypoint2.sh -e` to load CMD_DB_URL for CLI scripts
|
|
if [ ! "${1-}" == "-e" ]; then
|
|
# 3wc: upstream ENTRYPOINT
|
|
# https://github.com/hedgedoc/container/blob/master/alpine/Dockerfile
|
|
/usr/local/bin/docker-entrypoint.sh npm start
|
|
fi
|
|
|
|
set +eu
|