Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POSTGRES_* are ignored when NEXTCLOUD_ADMIN_* are omitted. #1228

Closed
raldone01 opened this issue Aug 29, 2020 · 4 comments
Closed

POSTGRES_* are ignored when NEXTCLOUD_ADMIN_* are omitted. #1228

raldone01 opened this issue Aug 29, 2020 · 4 comments
Labels
bug docs feature: auto config (Docker secrets) feature: auto config (environment variables) Auto configuring via environment variables needs review Needs confirmation this is still happening or relevant

Comments

@raldone01
Copy link

What is happening?

The postgresql database configuration values are ignored.

What should happen?

The postgresql database configuration should be used.

Setup

Docu:

If you set any values, they will not be asked in the install page on first run. With a complete configuration by using all variables for your database type, you can additionally configure your Nextcloud instance by setting admin user and password (only works if you set both):
    NEXTCLOUD_ADMIN_USER Name of the Nextcloud admin user.
    NEXTCLOUD_ADMIN_PASSWORD Password for the Nextcloud admin user.

Example docker-compose: (I omitted my reverse proxy)

version: '3.2'
services:
    nextcloud-db:
        image: postgres
        restart: unless-stopped
        volumes:
         - ${CONTAINERP}/nextcloud-db:/var/lib/postgresql/data
        environment:
         - POSTGRES_DB_FILE=/run/secrets/postgres_db
         - POSTGRES_USER_FILE=/run/secrets/postgres_user
         - POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
        secrets:
         - postgres_db
         - postgres_password
         - postgres_user
        networks:
         - back-nextcloud
    nextcloud:
        restart: unless-stopped
        image: nextcloud
        volumes:
         - ${CONTAINERP}/nextcloud/nextcloud:/var/www/html
         - ${CONTAINERP}/nextcloud/apps:/var/www/html/custom_apps
         - ${CONTAINERP}/nextcloud/config:/var/www/html/config
         - ${CONTAINERP}/nextcloud/data:/var/www/html/data
        environment:
          - POSTGRES_HOST=nextcloud-db
          - POSTGRES_DB_FILE=/run/secrets/postgres_db
          - POSTGRES_USER_FILE=/run/secrets/postgres_user
          - POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
#          - NEXTCLOUD_ADMIN_PASSWORD=pwd # REQUIRED?
#          - NEXTCLOUD_ADMIN_USER=admin
        secrets:
         - postgres_db
         - postgres_password
         - postgres_user
        ports:
         - 8080:80
        networks:
         - front
         - back-nextcloud
        depends_on:
         - nextcloud-db
networks:
    front:
    back-nextcloud:
secrets:
  postgres_db:
    file: ./secrets/postgres_db.txt # put postgresql db name to this file
  postgres_password:
    file: ./secrets/postgres_password.txt # put postgresql password to this file
  postgres_user:
    file: ./secrets/postgres_user.txt # put postgresql username to this file

Repository to reproduce.

@dermalikmann
Copy link

Interesting...
I can confirm this!
Usually autoconfig.php should handle this, but as you did not configure the Postgresconfig via the "normal" var, but instead used the secrets autoconfig did not work.
The fix should be easy though... 😅

@BorjaEst
Copy link

The documentation is wrong, it says to write the env variables:

You should use this env variables instead:

  • POSTGRES_DB
  • POSTGRES_USER
  • POSTGRES_PASSWORD

@J0WI
Copy link
Contributor

J0WI commented Nov 7, 2020

It depends whether you use a docker secret or a env:

# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
local varValue=$(env | grep -E "^${var}=" | sed -E -e "s/^${var}=//")
local fileVarValue=$(env | grep -E "^${fileVar}=" | sed -E -e "s/^${fileVar}=//")
if [ -n "${varValue}" ] && [ -n "${fileVarValue}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
if [ -n "${varValue}" ]; then
export "$var"="${varValue}"
elif [ -n "${fileVarValue}" ]; then
export "$var"="$(cat "${fileVarValue}")"
elif [ -n "${def}" ]; then
export "$var"="$def"
fi
unset "$fileVar"
}

I guess the docs are a bit misleading here. The auto configuration is only working if a admin user and database is configured.

if [ -n "${NEXTCLOUD_ADMIN_USER+x}" ] && [ -n "${NEXTCLOUD_ADMIN_PASSWORD+x}" ]; then

@joshtrichards joshtrichards added the needs review Needs confirmation this is still happening or relevant label Jun 19, 2024
@joshtrichards
Copy link
Member

This will further clarified in the docs via #2224 so closing.

@joshtrichards joshtrichards closed this as not planned Won't fix, can't repro, duplicate, stale Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug docs feature: auto config (Docker secrets) feature: auto config (environment variables) Auto configuring via environment variables needs review Needs confirmation this is still happening or relevant
Projects
None yet
Development

No branches or pull requests

5 participants