0
0
Fork 0
mirror of https://github.com/nextcloud/docker.git synced 2024-11-19 19:46:42 +01:00

docker-entrypoint.sh: exit if DB host not set

Since all DB variables but the host can be set using secrets (by
appending '_FILE' to the variable name), it can be easy for a user to
mis-configure their DB host variable by storing them in
MYSQL_HOST_FILE or POSTGRESQL_HOST_FILE (which is not supported).
When that happens, the auto configuration is skipped.
Such a situation is a bit cumbersome to figure out as nothing
indicates why the auto configuration is skipped.
To make to make it obvious to the user, exit early if DB variables
have been set (using secrets or not), but the host has not been
set (for example, because it was set in MYSQL_HOST_FILE).

Signed-off-by: Raphaël Mélotte <raphael.melotte@mind.be>
This commit is contained in:
Raphaël Mélotte 2023-09-26 13:23:50 +02:00
parent f4429bb0ff
commit 70358187fd

View file

@ -207,12 +207,20 @@ if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UP
# shellcheck disable=SC2016 # shellcheck disable=SC2016
install_options=$install_options' --database-name "$SQLITE_DATABASE"' install_options=$install_options' --database-name "$SQLITE_DATABASE"'
install=true install=true
elif [ -n "${MYSQL_DATABASE+x}" ] && [ -n "${MYSQL_USER+x}" ] && [ -n "${MYSQL_PASSWORD+x}" ] && [ -n "${MYSQL_HOST+x}" ]; then elif [ -n "${MYSQL_DATABASE+x}" ] && [ -n "${MYSQL_USER+x}" ] && [ -n "${MYSQL_PASSWORD+x}" ]; then
if [ -z "${MYSQL_HOST}" ] ; then
echo "MySQL credentials set but no MySQL host set. Please make sure \$MYSQL_HOST is set."
exit 1
fi
echo "Installing with MySQL database" echo "Installing with MySQL database"
# shellcheck disable=SC2016 # shellcheck disable=SC2016
install_options=$install_options' --database mysql --database-name "$MYSQL_DATABASE" --database-user "$MYSQL_USER" --database-pass "$MYSQL_PASSWORD" --database-host "$MYSQL_HOST"' install_options=$install_options' --database mysql --database-name "$MYSQL_DATABASE" --database-user "$MYSQL_USER" --database-pass "$MYSQL_PASSWORD" --database-host "$MYSQL_HOST"'
install=true install=true
elif [ -n "${POSTGRES_DB+x}" ] && [ -n "${POSTGRES_USER+x}" ] && [ -n "${POSTGRES_PASSWORD+x}" ] && [ -n "${POSTGRES_HOST+x}" ]; then elif [ -n "${POSTGRES_DB+x}" ] && [ -n "${POSTGRES_USER+x}" ] && [ -n "${POSTGRES_PASSWORD+x}" ]; then
if [ -z "${POSTGRES_HOST}" ] ; then
echo "PostgreSQL credentials set but no PostgreSQL host set. Please make sure \$POSTGRES_HOST is set."
exit 1
fi
echo "Installing with PostgreSQL database" echo "Installing with PostgreSQL database"
# shellcheck disable=SC2016 # shellcheck disable=SC2016
install_options=$install_options' --database pgsql --database-name "$POSTGRES_DB" --database-user "$POSTGRES_USER" --database-pass "$POSTGRES_PASSWORD" --database-host "$POSTGRES_HOST"' install_options=$install_options' --database pgsql --database-name "$POSTGRES_DB" --database-user "$POSTGRES_USER" --database-pass "$POSTGRES_PASSWORD" --database-host "$POSTGRES_HOST"'