Bonitasoft-Community / docker_bonita

:whale: Source of the official Bonita Docker image
https://hub.docker.com/_/bonita/
18 stars 16 forks source link

Postgres connection with Postgres user #2

Closed chadyred closed 8 years ago

chadyred commented 8 years ago

Hello !

I have a connection problem here :

psql -U postgres -h 172.17.0.3 -p 5432 -d postgres -t -A -c 'SELECT 1 FROM pg_roles WHERE rolname='\''bonita'\'''
bonita_1   | + grep -q 1
postgres_1 | FATAL:  password authentication failed for user "postgres"

Bad idea: docker create with postgres user but no password is required for it...It has no password by default.

postgres:
    image: postgres:9.3
    environment:
        - POSTGRES_PASSWORD=bonita
        - POSTGRES_USER=bonita
        - POSTGRES_DB=bonitasoft

        - BIZ_DB_NAME=bonitabz_db
        - BIZ_DB_USER=bonitabz
        - BIZ_DB_PASS=bonitabz
    volumes: 
        - "/data/bonita/postgres:/var/lib/postgresql/data:rw"
        - "./docker/postgres/custom/docker-entrypoint.sh:/docker-entrypoint-initdb.d/docker-entrypoint.sh:rw"
JeremJR commented 8 years ago

Hello,

It's described into the documentation available here how to link Bonita container to the Official Postgres Container. This way it will ensure to automatically create the corresponding databases.

Link Bonita BPM to a database

PostgreSQL

PostgreSQL is the recommanded database.

Set max_prepared_transactions to 100:

mkdir -p custom_postgres echo '#!/bin/bash' > custom_postgres/bonita.sh echo 'sed -i "s/^._max_preparedtransactions\s=\s(.)$/max_prepared_transactions = 100/" "$PGDATA"/postgresql.conf' >> custom_postgres/bonita.sh chmod +x custom_postgres/bonita.sh

Mount that directory location as /docker-entrypoint-initdb.d inside the PostgreSQL container:

$ docker run --name mydbpostgres -v "$PWD"/custom_postgres/:/docker-entrypoint-initdb.d -e POSTGRES_PASSWORD=mysecretpassword -d postgres:9.3

See the official PostgreSQL documentation for more details.

$ docker run --name bonita_postgres --link mydbpostgres:postgres -d -p 8080:8080 bonita

If you want to manage it by your own, you can do it by overriding the environment variables like this :

cat > /tmp/env.txt <<- EOM
ENSURE_DB_CHECK_AND_CREATION=false
DB_VENDOR=postgres
DB_HOST=172.17.0.2
DB_PORT=5432
DB_NAME=custombonitadb
DB_USER=custombonitauser
DB_PASS=custombonitapass
BIZ_DB_NAME=custombusinessdb
BIZ_DB_USER=custombusinessuser
BIZ_DB_PASS=custombusinesspass
EOM

docker run --name=bonita_7.0.3_postgres --env-file=/tmp/env.txt -d -p 8080:8080 bonita:7.0.3

This way it will launch the Bonita container with the databases and users previously created. Which means in this example that you already have run the following commands :

export PGPASSWORD=mysecretpassword
psql -U postgres -h 172.17.0.2 -d postgres -c "CREATE USER custombonitauser WITH PASSWORD 'custombonitapass';"
psql -U postgres -h 172.17.0.2 -d postgres -c "CREATE DATABASE custombonitadb OWNER custombonitauser;"
psql -U postgres -h 172.17.0.2 -d postgres -c "CREATE USER custombusinessuser WITH PASSWORD 'custombusinesspass';"
psql -U postgres -h 172.17.0.2 -d postgres -c "CREATE DATABASE custombusinessdb OWNER custombusinessuser;"
chadyred commented 8 years ago

Thank you it's work fine. I download the Bonita Studio and he have standalone portal, so I use it to test and maybe in a future a full docker to publish and managage app.