Skip to content

Commit da754e6

Browse files
committed
Added support for reading the default password from a file (i.e. docker secret)
1 parent bded33b commit da754e6

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

alpine/docker-entrypoint.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
#!/bin/bash
22
set -eu
33

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+
file_env 'RABBITMQ_DEFAULT_PASS'
27+
428
# allow the container to be started with `--user`
529
if [[ "$1" == rabbitmq* ]] && [ "$(id -u)" = '0' ]; then
630
if [ "$1" = 'rabbitmq-server' ]; then

debian/docker-entrypoint.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
#!/bin/bash
22
set -eu
33

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+
file_env 'RABBITMQ_DEFAULT_PASS'
27+
428
# allow the container to be started with `--user`
529
if [[ "$1" == rabbitmq* ]] && [ "$(id -u)" = '0' ]; then
630
if [ "$1" = 'rabbitmq-server' ]; then

0 commit comments

Comments
 (0)