Squarespace / pgbedrock

Manage a Postgres cluster's roles, role memberships, schema ownership, and privileges
https://pgbedrock.readthedocs.io/en/latest/
Other
311 stars 35 forks source link

Add documentation about how to use pgbedrock in a docker compose setup #48

Closed alexlenail closed 5 years ago

alexlenail commented 5 years ago

I have

version: '3'
services:
  postgres:
    container_name: postgres
    image: postgres
    restart: always
    ports:
      - "5432:5432"
    environment:
      POSTGRES_DB: DB
      POSTGRES_USER: user
      POSTGRES_PASSWORD: password
    volumes:
      - "./pgdata:/var/lib/postgresql/data"

How do I properly add pgbedrock to my compose setup?

zcmarine commented 5 years ago

Hi @zfrenchee, this is really more a question on how to manage docker compose's container startup order. While we could add this to pgbedrock's documentation (and if you put in a PR for it it probably would be accepted), it seems superfluous given that there's a lot of examples of this out there already, including one in the docker compose docs themselves.

What I've typically done with "wait for db to be up" problems in the past is the same as what they show in that link: create a tiny wrapper script that accepts extra commands and then runs them after the db is up. To be specific, in that linked example they get the host from the arguments passed in ($1), pop that argument (shift), and then set all the other arguments to the script as the additional command to subsequently run (cmd="$@"). Put all together:

host="$1"
shift
cmd="$@"

So you'd have a pgbedrock container in your docker compose setup that would use a wrapper script like that: keep seeing if postgres is up, and once it is run pgbedrock.

I'm going to close this issue, but let me know if you want to try to add a more detailed write-up to the docs and I can re-open this issue for reference.

Hope that helps!