From c75aede91be92f8182320e93417fb03617940620 Mon Sep 17 00:00:00 2001 From: boyska Date: Tue, 25 Sep 2018 16:35:42 +0200 Subject: [PATCH] postgresql with multiple users --- docker-compose.yml | 10 +++++----- docker/dbconf.sql | 3 +++ docker/ttrss-config.php | 4 ++-- docker/wait-db | 4 +++- dodo.py | 10 +++++++--- 5 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 docker/dbconf.sql diff --git a/docker-compose.yml b/docker-compose.yml index 416c9bf..b4754e6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,14 +2,14 @@ version: "3.6" services: db: - image: postgres:10 + image: postgres:10-alpine container_name: feedati_db volumes: - postgres_data:/var/lib/postgresql/data environment: - - POSTGRES_USER=ttrss - - POSTGRES_PASSWORD=password-dev - - POSTGRES_DB=ttrss + - POSTGRES_USER=superadmin + - POSTGRES_PASSWORD=superpass + - POSTGRES_DB=feeds ports: - 5432:5432 @@ -37,7 +37,7 @@ services: environment: - PHP_DISPLAY_ERRORS=stdout - PHP_DISPLAY_STARTUP_ERROR=1 - entrypoint: 'wait-db php7 /app/public/tt-rss/update.php --daemon' + entrypoint: 'env PGHOST=db PGDATABASE=feeds PGUSER=ttrss PGPASSWORD=ttpass wait-db php7 /app/public/tt-rss/update.php --daemon' ports: [] depends_on: - db diff --git a/docker/dbconf.sql b/docker/dbconf.sql new file mode 100644 index 0000000..ac880ba --- /dev/null +++ b/docker/dbconf.sql @@ -0,0 +1,3 @@ +CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; +CREATE USER ttrss WITH PASSWORD 'ttpass'; +CREATE USER panel WITH PASSWORD 'panelpass'; diff --git a/docker/ttrss-config.php b/docker/ttrss-config.php index 2cf3e36..ec230b6 100644 --- a/docker/ttrss-config.php +++ b/docker/ttrss-config.php @@ -6,8 +6,8 @@ define('DB_TYPE', 'pgsql'); define('DB_HOST', 'db'); define('DB_USER', 'ttrss'); - define('DB_NAME', 'ttrss'); - define('DB_PASS', 'password-dev'); + define('DB_NAME', 'feeds'); + define('DB_PASS', 'ttpass'); define('DB_PORT', '5432'); define('MYSQL_CHARSET', 'UTF8'); diff --git a/docker/wait-db b/docker/wait-db index 3fa5627..94cd98a 100755 --- a/docker/wait-db +++ b/docker/wait-db @@ -1,7 +1,9 @@ #!/bin/bash +### psql configuration parameters must be received as environ vars +### (PGHOST, PGDATABASE, PGUSER, PGPASSWORD) timeout=60 for _ in $(seq 1 "$timeout"); do - if env PGPASSWORD=password-dev psql -h db -U ttrss -w ttrss -c "" -q 2> /dev/null; then + if psql -w -c "" -q 2> /dev/null; then echo "DB ready" exec "$@" fi diff --git a/dodo.py b/dodo.py index 83d0c21..1a99626 100644 --- a/dodo.py +++ b/dodo.py @@ -69,14 +69,18 @@ def task_dbprepare(): '''applica il dump sql al container del db''' return { 'setup': ['_dbprepare_clean', 'build'], - 'file_dep': ['docker/ttrss.sql'], + 'file_dep': list(scan_dir('docker', '*.sql')), 'actions': [ (COMPOSE + ' up -d db').split(), (wait_net_service, ('localhost', 5432, 300)), - (wait_pgsql_db, ('feedati_db', 'ttrss', 'ttrss')), + (wait_pgsql_db, ('feedati_db', 'feeds', 'superadmin')), 'echo LOADING DB', + # dbconf.sql would be better put in /docker-entrypoint-initdb.d/init-user-db.sh + # (see https://hub.docker.com/r/library/postgres/ ) r'docker exec -i $(docker ps -aqf name=feedati_db) ' - 'psql -h 127.0.0.1 -f - -d ttrss ttrss < docker/ttrss.sql', + 'env PGPASSWORD=superpass psql -h 127.0.0.1 -f - -d feeds superadmin < docker/dbconf.sql', + r'docker exec -i $(docker ps -aqf name=feedati_db) ' + 'env PGPASSWORD=ttpass psql -h 127.0.0.1 -f - -d feeds ttrss < docker/ttrss.sql', 'echo DB RESTORED', ], 'teardown': [(stop, [])],