Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exposing postgres to hosts #4294

Merged
merged 3 commits into from
Mar 5, 2020
Merged

exposing postgres to hosts #4294

merged 3 commits into from
Mar 5, 2020

Conversation

Pomax
Copy link
Contributor

@Pomax Pomax commented Mar 4, 2020

Closes #4269 by adding explicit credentials and a host mapping to the docker compose yaml config.

This will keep everything running on 5432 as far as anything inside Docker knows, with docker-new-env updating the .env file with the user/pass/dbname from docker-compose.yml (if set; If not set, they default to the string postgres).

However, postgres is now also accessible on port 5678 from the host OS so that psql postgresql://username:password@localhost:5678/dbname gets you into the Docker-hosted postgres instance, to allow for things like importing a copy of the staging/production db to debug problems associated with real data.

@Pomax Pomax requested review from cadecairos and patjouk March 4, 2020 21:40
@patjouk patjouk temporarily deployed to foundation-s-postgres4a-lnjo5o March 4, 2020 21:40 Inactive
@Pomax Pomax temporarily deployed to foundation-s-postgres4a-lnjo5o March 4, 2020 21:51 Inactive
Copy link

@cadecairos cadecairos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Ran locally with no issues.

@Pomax
Copy link
Contributor Author

Pomax commented Mar 4, 2020

Of course the one challenge now is to allow for dropdb/createdb, because during a normal docker-compose run, the db is locked due to wagtail being connected to it...

@Pomax
Copy link
Contributor Author

Pomax commented Mar 4, 2020

sorted:

SET ROLE_NAME=......
SET PGPASSWORD=mozilla
pg_dump -F c prodOrStageDATABASE_URL > foundation.db.archive
dropdb -h localhost -p 5678 -U foundation wagtail
createdb -h localhost -p 5678 -U foundation wagtail
createuser -h localhost -p 5678 -U foundation -s $ROLE_NAME
createuser -h localhost -p 5678 -U foundation -s datastudio
pg_restore -d "postgresql://foundation:mozilla@localhost:5678/wagtail" foundation.db.archive

Where ROLE_NAME is the username from the DATABASE_URL

(I have this in a .bat file that is on a completely different drive, in a non-git-managed dir so I can't ever accidentally check it in, with some automated prompts for whether to redownload a db dump, and if so, whether to use staging or prod)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

expose postgresql so that it can be accessed outside of Docker
3 participants