Bonitasoft-Community / docker_bonita

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

library/bonita:7.5.1 (and others probably) doesn't play nice with docker-compose #5

Closed xaduha closed 6 years ago

xaduha commented 7 years ago

When trying to link it with postgres or mysql. I tried all kinds of combinations with legacy https://docs.docker.com/compose/compose-file/#external_links, with normal https://docs.docker.com/compose/compose-file/#links, specifying DB_* variables too.

Would be nice if you could provide an example docker-compose.yml file and improve whatever detection mechanism that you use. It works just fine from command line, but not with docker-compose. Thanks!

JeremJR commented 7 years ago

In fact the detection mechanism of environment variables based on link is deprecated since the version 2 of compose file format https://docs.docker.com/compose/link-env-deprecated/ In version 2 you can use somehing like this :

Prepare the configuration script to set max_prepared_transactions to 100 in Postgres:

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

Note that to avoid issues you may want to wait for postgres startup as described here https://hub.docker.com/_/postgres/

Caveats If there is no database when postgres starts in a container, then postgres will create the default database for you. While this is the expected behavior of postgres, this means that it will not accept incoming connections during that time. This may cause issues when using automation tools, such as docker-compose, that start several containers simultaneously.

https://docs.docker.com/compose/startup-order/

cat > wait-for-postgres.sh <<- EOM
#!/bin/bash
# wait-for-postgres.sh

set -e

host="\$1"
shift
cmd="\$@"
PGPASSWORD=\$POSTGRES_ENV_POSTGRES_PASSWORD
export PGPASSWORD
until psql -h "\$host" -U "postgres" -c '\l'; do
  >&2 echo "Postgres is unavailable - sleeping"
  sleep 1
done

>&2 echo "Postgres is up - executing command"
exec \$cmd
EOM

chmod +x wait-for-postgres.sh

Set the environments variables of Bonita to change the default credentials :

cat > env.txt <<- EOM
TENANT_LOGIN=tech_user
TENANT_PASSWORD=secret
PLATFORM_LOGIN=pfadmin
PLATFORM_PASSWORD=pfsecret
EOM

Create the corresponding docker-compose file :

cat > docker-compose.yml <<- EOM
version: '2'
services:
  db:
    image: postgres:9.3
    environment:
      POSTGRES_PASSWORD: example
    volumes:
      - ./custom_postgres/:/docker-entrypoint-initdb.d
  bonita:
    image: bonita:7.5.1
    ports:
      - 8080:8080
    env_file:
      - ./env.txt
    environment:
      - POSTGRES_ENV_POSTGRES_PASSWORD=example
      - DB_VENDOR=postgres
      - DB_HOST=db
    volumes:
      - ./wait-for-postgres.sh:/wait-for-postgres.sh
    depends_on:
      - db
    command: ["/wait-for-postgres.sh", "db", "/opt/files/startup.sh"]
EOM

docker-compose up should work fine with this example.

xaduha commented 7 years ago

thanks!

JeremJR commented 6 years ago

stack.yml example added into the doc