docker-entrypoint.sh31 lines · main
| 1 | #!/usr/bin/env bash |
| 2 | set -Eeuo pipefail |
| 3 | |
| 4 | # usage: file_env VAR [DEFAULT] |
| 5 | # ie: file_env 'XYZ_DB_PASSWORD' 'example' |
| 6 | # (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of |
| 7 | # "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature) |
| 8 | file_env() { |
| 9 | local var="$1" |
| 10 | local fileVar="${var}_FILE" |
| 11 | local def="${2:-}" |
| 12 | if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then |
| 13 | echo >&2 "error: both $var and $fileVar are set (but are exclusive)" |
| 14 | exit 1 |
| 15 | fi |
| 16 | local val="$def" |
| 17 | if [ "${!var:-}" ]; then |
| 18 | val="${!var}" |
| 19 | elif [ "${!fileVar:-}" ]; then |
| 20 | val="$(< "${!fileVar}")" |
| 21 | fi |
| 22 | export "$var"="$val" |
| 23 | unset "$fileVar" |
| 24 | } |
| 25 | |
| 26 | # load secrets either from environment variables or files |
| 27 | file_env 'POSTGRES_PASSWORD' |
| 28 | file_env 'BRIVEN_ANON_KEY' |
| 29 | file_env 'BRIVEN_SERVICE_KEY' |
| 30 | |
| 31 | exec "${@}" |