Skip to content

Commit efe3cae

Browse files
ekhodargmuesli
andauthored
Compatibility with docker secrets (#560)
* Read passwords from files specified with *_PASSWORD_FILE variables (docker secrets) Fixes #731 Signed-off-by: Boris Gorbylev <ekho@ekho.name> Signed-off-by: Jonas Thelemann <e-mail@jonas-thelemann.de> * Add NEXTCLOUD_ADMIN_USER, POSTGRES_DB, POSTGRES_USER Signed-off-by: Jonas Thelemann <e-mail@jonas-thelemann.de> * Fix Variables Signed-off-by: Jonas Thelemann <e-mail@jonas-thelemann.de> Co-authored-by: Jonas Thelemann <e-mail@jonas-thelemann.de>
1 parent cf3476d commit efe3cae

File tree

11 files changed

+402
-0
lines changed

11 files changed

+402
-0
lines changed

16.0/apache/entrypoint.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,30 @@ run_as() {
1919
fi
2020
}
2121

22+
# usage: file_env VAR [DEFAULT]
23+
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
24+
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
25+
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
26+
file_env() {
27+
local var="$1"
28+
local fileVar="${var}_FILE"
29+
local def="${2:-}"
30+
local varValue=$(env | grep -E "^${var}=" | sed -E -e "s/^${var}=//")
31+
local fileVarValue=$(env | grep -E "^${fileVar}=" | sed -E -e "s/^${fileVar}=//")
32+
if [ -n "${varValue}" ] && [ -n "${fileVarValue}" ]; then
33+
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
34+
exit 1
35+
fi
36+
if [ -n "${varValue}" ]; then
37+
export "$var"="${varValue}"
38+
elif [ -n "${fileVarValue}" ]; then
39+
export "$var"="$(cat "${fileVarValue}")"
40+
elif [ -n "${def}" ]; then
41+
export "$var"="$def"
42+
fi
43+
unset "$fileVar"
44+
}
45+
2246
if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UPDATE:-0}" -eq 1 ]; then
2347
if [ -n "${REDIS_HOST+x}" ]; then
2448

@@ -79,6 +103,9 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
79103
if [ "$installed_version" = "0.0.0.0" ]; then
80104
echo "New nextcloud instance"
81105

106+
file_env NEXTCLOUD_ADMIN_PASSWORD
107+
file_env NEXTCLOUD_ADMIN_USER
108+
82109
if [ -n "${NEXTCLOUD_ADMIN_USER+x}" ] && [ -n "${NEXTCLOUD_ADMIN_PASSWORD+x}" ]; then
83110
# shellcheck disable=SC2016
84111
install_options='-n --admin-user "$NEXTCLOUD_ADMIN_USER" --admin-pass "$NEXTCLOUD_ADMIN_PASSWORD"'
@@ -91,6 +118,13 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
91118
install_options=$install_options' --data-dir "$NEXTCLOUD_DATA_DIR"'
92119
fi
93120

121+
file_env MYSQL_DATABASE
122+
file_env MYSQL_PASSWORD
123+
file_env MYSQL_USER
124+
file_env POSTGRES_DB
125+
file_env POSTGRES_PASSWORD
126+
file_env POSTGRES_USER
127+
94128
install=false
95129
if [ -n "${SQLITE_DATABASE+x}" ]; then
96130
echo "Installing with SQLite database"

16.0/fpm-alpine/entrypoint.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,30 @@ run_as() {
1919
fi
2020
}
2121

22+
# usage: file_env VAR [DEFAULT]
23+
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
24+
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
25+
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
26+
file_env() {
27+
local var="$1"
28+
local fileVar="${var}_FILE"
29+
local def="${2:-}"
30+
local varValue=$(env | grep -E "^${var}=" | sed -E -e "s/^${var}=//")
31+
local fileVarValue=$(env | grep -E "^${fileVar}=" | sed -E -e "s/^${fileVar}=//")
32+
if [ -n "${varValue}" ] && [ -n "${fileVarValue}" ]; then
33+
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
34+
exit 1
35+
fi
36+
if [ -n "${varValue}" ]; then
37+
export "$var"="${varValue}"
38+
elif [ -n "${fileVarValue}" ]; then
39+
export "$var"="$(cat "${fileVarValue}")"
40+
elif [ -n "${def}" ]; then
41+
export "$var"="$def"
42+
fi
43+
unset "$fileVar"
44+
}
45+
2246
if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UPDATE:-0}" -eq 1 ]; then
2347
if [ -n "${REDIS_HOST+x}" ]; then
2448

@@ -79,6 +103,9 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
79103
if [ "$installed_version" = "0.0.0.0" ]; then
80104
echo "New nextcloud instance"
81105

106+
file_env NEXTCLOUD_ADMIN_PASSWORD
107+
file_env NEXTCLOUD_ADMIN_USER
108+
82109
if [ -n "${NEXTCLOUD_ADMIN_USER+x}" ] && [ -n "${NEXTCLOUD_ADMIN_PASSWORD+x}" ]; then
83110
# shellcheck disable=SC2016
84111
install_options='-n --admin-user "$NEXTCLOUD_ADMIN_USER" --admin-pass "$NEXTCLOUD_ADMIN_PASSWORD"'
@@ -91,6 +118,13 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
91118
install_options=$install_options' --data-dir "$NEXTCLOUD_DATA_DIR"'
92119
fi
93120

121+
file_env MYSQL_DATABASE
122+
file_env MYSQL_PASSWORD
123+
file_env MYSQL_USER
124+
file_env POSTGRES_DB
125+
file_env POSTGRES_PASSWORD
126+
file_env POSTGRES_USER
127+
94128
install=false
95129
if [ -n "${SQLITE_DATABASE+x}" ]; then
96130
echo "Installing with SQLite database"

16.0/fpm/entrypoint.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,30 @@ run_as() {
1919
fi
2020
}
2121

22+
# usage: file_env VAR [DEFAULT]
23+
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
24+
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
25+
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
26+
file_env() {
27+
local var="$1"
28+
local fileVar="${var}_FILE"
29+
local def="${2:-}"
30+
local varValue=$(env | grep -E "^${var}=" | sed -E -e "s/^${var}=//")
31+
local fileVarValue=$(env | grep -E "^${fileVar}=" | sed -E -e "s/^${fileVar}=//")
32+
if [ -n "${varValue}" ] && [ -n "${fileVarValue}" ]; then
33+
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
34+
exit 1
35+
fi
36+
if [ -n "${varValue}" ]; then
37+
export "$var"="${varValue}"
38+
elif [ -n "${fileVarValue}" ]; then
39+
export "$var"="$(cat "${fileVarValue}")"
40+
elif [ -n "${def}" ]; then
41+
export "$var"="$def"
42+
fi
43+
unset "$fileVar"
44+
}
45+
2246
if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UPDATE:-0}" -eq 1 ]; then
2347
if [ -n "${REDIS_HOST+x}" ]; then
2448

@@ -79,6 +103,9 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
79103
if [ "$installed_version" = "0.0.0.0" ]; then
80104
echo "New nextcloud instance"
81105

106+
file_env NEXTCLOUD_ADMIN_PASSWORD
107+
file_env NEXTCLOUD_ADMIN_USER
108+
82109
if [ -n "${NEXTCLOUD_ADMIN_USER+x}" ] && [ -n "${NEXTCLOUD_ADMIN_PASSWORD+x}" ]; then
83110
# shellcheck disable=SC2016
84111
install_options='-n --admin-user "$NEXTCLOUD_ADMIN_USER" --admin-pass "$NEXTCLOUD_ADMIN_PASSWORD"'
@@ -91,6 +118,13 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
91118
install_options=$install_options' --data-dir "$NEXTCLOUD_DATA_DIR"'
92119
fi
93120

121+
file_env MYSQL_DATABASE
122+
file_env MYSQL_PASSWORD
123+
file_env MYSQL_USER
124+
file_env POSTGRES_DB
125+
file_env POSTGRES_PASSWORD
126+
file_env POSTGRES_USER
127+
94128
install=false
95129
if [ -n "${SQLITE_DATABASE+x}" ]; then
96130
echo "Installing with SQLite database"

17.0/apache/entrypoint.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,30 @@ run_as() {
1919
fi
2020
}
2121

22+
# usage: file_env VAR [DEFAULT]
23+
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
24+
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
25+
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
26+
file_env() {
27+
local var="$1"
28+
local fileVar="${var}_FILE"
29+
local def="${2:-}"
30+
local varValue=$(env | grep -E "^${var}=" | sed -E -e "s/^${var}=//")
31+
local fileVarValue=$(env | grep -E "^${fileVar}=" | sed -E -e "s/^${fileVar}=//")
32+
if [ -n "${varValue}" ] && [ -n "${fileVarValue}" ]; then
33+
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
34+
exit 1
35+
fi
36+
if [ -n "${varValue}" ]; then
37+
export "$var"="${varValue}"
38+
elif [ -n "${fileVarValue}" ]; then
39+
export "$var"="$(cat "${fileVarValue}")"
40+
elif [ -n "${def}" ]; then
41+
export "$var"="$def"
42+
fi
43+
unset "$fileVar"
44+
}
45+
2246
if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UPDATE:-0}" -eq 1 ]; then
2347
if [ -n "${REDIS_HOST+x}" ]; then
2448

@@ -79,6 +103,9 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
79103
if [ "$installed_version" = "0.0.0.0" ]; then
80104
echo "New nextcloud instance"
81105

106+
file_env NEXTCLOUD_ADMIN_PASSWORD
107+
file_env NEXTCLOUD_ADMIN_USER
108+
82109
if [ -n "${NEXTCLOUD_ADMIN_USER+x}" ] && [ -n "${NEXTCLOUD_ADMIN_PASSWORD+x}" ]; then
83110
# shellcheck disable=SC2016
84111
install_options='-n --admin-user "$NEXTCLOUD_ADMIN_USER" --admin-pass "$NEXTCLOUD_ADMIN_PASSWORD"'
@@ -91,6 +118,13 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
91118
install_options=$install_options' --data-dir "$NEXTCLOUD_DATA_DIR"'
92119
fi
93120

121+
file_env MYSQL_DATABASE
122+
file_env MYSQL_PASSWORD
123+
file_env MYSQL_USER
124+
file_env POSTGRES_DB
125+
file_env POSTGRES_PASSWORD
126+
file_env POSTGRES_USER
127+
94128
install=false
95129
if [ -n "${SQLITE_DATABASE+x}" ]; then
96130
echo "Installing with SQLite database"

17.0/fpm-alpine/entrypoint.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,30 @@ run_as() {
1919
fi
2020
}
2121

22+
# usage: file_env VAR [DEFAULT]
23+
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
24+
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
25+
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
26+
file_env() {
27+
local var="$1"
28+
local fileVar="${var}_FILE"
29+
local def="${2:-}"
30+
local varValue=$(env | grep -E "^${var}=" | sed -E -e "s/^${var}=//")
31+
local fileVarValue=$(env | grep -E "^${fileVar}=" | sed -E -e "s/^${fileVar}=//")
32+
if [ -n "${varValue}" ] && [ -n "${fileVarValue}" ]; then
33+
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
34+
exit 1
35+
fi
36+
if [ -n "${varValue}" ]; then
37+
export "$var"="${varValue}"
38+
elif [ -n "${fileVarValue}" ]; then
39+
export "$var"="$(cat "${fileVarValue}")"
40+
elif [ -n "${def}" ]; then
41+
export "$var"="$def"
42+
fi
43+
unset "$fileVar"
44+
}
45+
2246
if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UPDATE:-0}" -eq 1 ]; then
2347
if [ -n "${REDIS_HOST+x}" ]; then
2448

@@ -79,6 +103,9 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
79103
if [ "$installed_version" = "0.0.0.0" ]; then
80104
echo "New nextcloud instance"
81105

106+
file_env NEXTCLOUD_ADMIN_PASSWORD
107+
file_env NEXTCLOUD_ADMIN_USER
108+
82109
if [ -n "${NEXTCLOUD_ADMIN_USER+x}" ] && [ -n "${NEXTCLOUD_ADMIN_PASSWORD+x}" ]; then
83110
# shellcheck disable=SC2016
84111
install_options='-n --admin-user "$NEXTCLOUD_ADMIN_USER" --admin-pass "$NEXTCLOUD_ADMIN_PASSWORD"'
@@ -91,6 +118,13 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
91118
install_options=$install_options' --data-dir "$NEXTCLOUD_DATA_DIR"'
92119
fi
93120

121+
file_env MYSQL_DATABASE
122+
file_env MYSQL_PASSWORD
123+
file_env MYSQL_USER
124+
file_env POSTGRES_DB
125+
file_env POSTGRES_PASSWORD
126+
file_env POSTGRES_USER
127+
94128
install=false
95129
if [ -n "${SQLITE_DATABASE+x}" ]; then
96130
echo "Installing with SQLite database"

17.0/fpm/entrypoint.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,30 @@ run_as() {
1919
fi
2020
}
2121

22+
# usage: file_env VAR [DEFAULT]
23+
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
24+
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
25+
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
26+
file_env() {
27+
local var="$1"
28+
local fileVar="${var}_FILE"
29+
local def="${2:-}"
30+
local varValue=$(env | grep -E "^${var}=" | sed -E -e "s/^${var}=//")
31+
local fileVarValue=$(env | grep -E "^${fileVar}=" | sed -E -e "s/^${fileVar}=//")
32+
if [ -n "${varValue}" ] && [ -n "${fileVarValue}" ]; then
33+
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
34+
exit 1
35+
fi
36+
if [ -n "${varValue}" ]; then
37+
export "$var"="${varValue}"
38+
elif [ -n "${fileVarValue}" ]; then
39+
export "$var"="$(cat "${fileVarValue}")"
40+
elif [ -n "${def}" ]; then
41+
export "$var"="$def"
42+
fi
43+
unset "$fileVar"
44+
}
45+
2246
if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UPDATE:-0}" -eq 1 ]; then
2347
if [ -n "${REDIS_HOST+x}" ]; then
2448

@@ -79,6 +103,9 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
79103
if [ "$installed_version" = "0.0.0.0" ]; then
80104
echo "New nextcloud instance"
81105

106+
file_env NEXTCLOUD_ADMIN_PASSWORD
107+
file_env NEXTCLOUD_ADMIN_USER
108+
82109
if [ -n "${NEXTCLOUD_ADMIN_USER+x}" ] && [ -n "${NEXTCLOUD_ADMIN_PASSWORD+x}" ]; then
83110
# shellcheck disable=SC2016
84111
install_options='-n --admin-user "$NEXTCLOUD_ADMIN_USER" --admin-pass "$NEXTCLOUD_ADMIN_PASSWORD"'
@@ -91,6 +118,13 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
91118
install_options=$install_options' --data-dir "$NEXTCLOUD_DATA_DIR"'
92119
fi
93120

121+
file_env MYSQL_DATABASE
122+
file_env MYSQL_PASSWORD
123+
file_env MYSQL_USER
124+
file_env POSTGRES_DB
125+
file_env POSTGRES_PASSWORD
126+
file_env POSTGRES_USER
127+
94128
install=false
95129
if [ -n "${SQLITE_DATABASE+x}" ]; then
96130
echo "Installing with SQLite database"

18.0/apache/entrypoint.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,30 @@ run_as() {
1919
fi
2020
}
2121

22+
# usage: file_env VAR [DEFAULT]
23+
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
24+
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
25+
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
26+
file_env() {
27+
local var="$1"
28+
local fileVar="${var}_FILE"
29+
local def="${2:-}"
30+
local varValue=$(env | grep -E "^${var}=" | sed -E -e "s/^${var}=//")
31+
local fileVarValue=$(env | grep -E "^${fileVar}=" | sed -E -e "s/^${fileVar}=//")
32+
if [ -n "${varValue}" ] && [ -n "${fileVarValue}" ]; then
33+
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
34+
exit 1
35+
fi
36+
if [ -n "${varValue}" ]; then
37+
export "$var"="${varValue}"
38+
elif [ -n "${fileVarValue}" ]; then
39+
export "$var"="$(cat "${fileVarValue}")"
40+
elif [ -n "${def}" ]; then
41+
export "$var"="$def"
42+
fi
43+
unset "$fileVar"
44+
}
45+
2246
if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UPDATE:-0}" -eq 1 ]; then
2347
if [ -n "${REDIS_HOST+x}" ]; then
2448

@@ -79,6 +103,9 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
79103
if [ "$installed_version" = "0.0.0.0" ]; then
80104
echo "New nextcloud instance"
81105

106+
file_env NEXTCLOUD_ADMIN_PASSWORD
107+
file_env NEXTCLOUD_ADMIN_USER
108+
82109
if [ -n "${NEXTCLOUD_ADMIN_USER+x}" ] && [ -n "${NEXTCLOUD_ADMIN_PASSWORD+x}" ]; then
83110
# shellcheck disable=SC2016
84111
install_options='-n --admin-user "$NEXTCLOUD_ADMIN_USER" --admin-pass "$NEXTCLOUD_ADMIN_PASSWORD"'
@@ -91,6 +118,13 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
91118
install_options=$install_options' --data-dir "$NEXTCLOUD_DATA_DIR"'
92119
fi
93120

121+
file_env MYSQL_DATABASE
122+
file_env MYSQL_PASSWORD
123+
file_env MYSQL_USER
124+
file_env POSTGRES_DB
125+
file_env POSTGRES_PASSWORD
126+
file_env POSTGRES_USER
127+
94128
install=false
95129
if [ -n "${SQLITE_DATABASE+x}" ]; then
96130
echo "Installing with SQLite database"

0 commit comments

Comments
 (0)