postgresql with multiple users

This commit is contained in:
boyska 2018-09-25 16:35:42 +02:00
parent 952e0270cd
commit c75aede91b
5 changed files with 20 additions and 11 deletions

View file

@ -2,14 +2,14 @@ version: "3.6"
services: services:
db: db:
image: postgres:10 image: postgres:10-alpine
container_name: feedati_db container_name: feedati_db
volumes: volumes:
- postgres_data:/var/lib/postgresql/data - postgres_data:/var/lib/postgresql/data
environment: environment:
- POSTGRES_USER=ttrss - POSTGRES_USER=superadmin
- POSTGRES_PASSWORD=password-dev - POSTGRES_PASSWORD=superpass
- POSTGRES_DB=ttrss - POSTGRES_DB=feeds
ports: ports:
- 5432:5432 - 5432:5432
@ -37,7 +37,7 @@ services:
environment: environment:
- PHP_DISPLAY_ERRORS=stdout - PHP_DISPLAY_ERRORS=stdout
- PHP_DISPLAY_STARTUP_ERROR=1 - 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: [] ports: []
depends_on: depends_on:
- db - db

3
docker/dbconf.sql Normal file
View file

@ -0,0 +1,3 @@
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE USER ttrss WITH PASSWORD 'ttpass';
CREATE USER panel WITH PASSWORD 'panelpass';

View file

@ -6,8 +6,8 @@
define('DB_TYPE', 'pgsql'); define('DB_TYPE', 'pgsql');
define('DB_HOST', 'db'); define('DB_HOST', 'db');
define('DB_USER', 'ttrss'); define('DB_USER', 'ttrss');
define('DB_NAME', 'ttrss'); define('DB_NAME', 'feeds');
define('DB_PASS', 'password-dev'); define('DB_PASS', 'ttpass');
define('DB_PORT', '5432'); define('DB_PORT', '5432');
define('MYSQL_CHARSET', 'UTF8'); define('MYSQL_CHARSET', 'UTF8');

View file

@ -1,7 +1,9 @@
#!/bin/bash #!/bin/bash
### psql configuration parameters must be received as environ vars
### (PGHOST, PGDATABASE, PGUSER, PGPASSWORD)
timeout=60 timeout=60
for _ in $(seq 1 "$timeout"); do 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" echo "DB ready"
exec "$@" exec "$@"
fi fi

10
dodo.py
View file

@ -69,14 +69,18 @@ def task_dbprepare():
'''applica il dump sql al container del db''' '''applica il dump sql al container del db'''
return { return {
'setup': ['_dbprepare_clean', 'build'], 'setup': ['_dbprepare_clean', 'build'],
'file_dep': ['docker/ttrss.sql'], 'file_dep': list(scan_dir('docker', '*.sql')),
'actions': [ 'actions': [
(COMPOSE + ' up -d db').split(), (COMPOSE + ' up -d db').split(),
(wait_net_service, ('localhost', 5432, 300)), (wait_net_service, ('localhost', 5432, 300)),
(wait_pgsql_db, ('feedati_db', 'ttrss', 'ttrss')), (wait_pgsql_db, ('feedati_db', 'feeds', 'superadmin')),
'echo LOADING DB', '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) ' 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', 'echo DB RESTORED',
], ],
'teardown': [(stop, [])], 'teardown': [(stop, [])],