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

Database connection during db:seed on host system #7

Open
Fedcomp opened this issue Nov 27, 2016 · 5 comments
Open

Database connection during db:seed on host system #7

Fedcomp opened this issue Nov 27, 2016 · 5 comments

Comments

@Fedcomp
Copy link

Fedcomp commented Nov 27, 2016

I'm trying to bootstrap thredded with thredded_create_app.
After i noticed how many actions it's trying to do on my host system (updating all gems including rails, which i should do only myself), i decided to dockerize thredded_create_app. After some tries and errors i did it, but stuck at one of the steps.

bundle exec rails db:create db:migrate db:seed --quiet
could not connect to server: Connection refused
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?
could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?
Couldn't create database for {"adapter"=>"postgresql", "min_messages"=>"WARNING", "pool"=>23, "host"=>"localhost", "port"=>5432, "username"=>"igromonik_dev", "password"=>"igromonik", "encoding"=>"utf8", "database"=>"igromonik_dev"}
rails aborted!
PG::ConnectionBad: could not connect to server: Connection refused
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?
could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?

When thredded_create_app run migrations, it does it on host system. So, before you can use docker for development, somehow you need to install postgresql on your host system.
With all this i come to conclusion - with default options installer is completely unusable. I have to use sqlite option, and then edit it back to postgresql after everything is generated, but that defeats the purpose of all-in-one installer.

What is even more funny, i can't run it with docker-compose because it expects to find database on localhost, while docker-compose gives special hostname to each container.

So, the question is - is it expected behavior of installer? it's completely unusable with default options?

@Fedcomp
Copy link
Author

Fedcomp commented Nov 27, 2016

Well, i took a look at database.yml and i see it supports DB_HOST, so i can pass installation.

Still, i wonder why it's trying to run migrations on host system with host postgresql.

During installation in docker i hit:

sudo: unknown user: postgres
sudo: unable to initialize policy plugin

@glebm
Copy link
Contributor

glebm commented Nov 27, 2016

So, the question is - is it expected behavior of installer? it's completely unusable with default options?

The installer does not support a Docker install currently but PRs are welcome. The generated Dockerfile is for other developers

When thredded_create_app run migrations, it does it on host system.

thredded_create_app runs everything in the environment the thredded_create_app command is run in. It is agnostic to VMs/Docker/chroot etc.

Of course, you can try running thredded_create_app within a Docker container. It would need the necessary pre-requisites (Ruby, a PostgreSQL connection, git, build tools, and all the libraries listed here).

During installation in docker i hit:

sudo: unknown user: postgres
sudo: unable to initialize policy plugin

This is because thredded_create_app tries to create the database user here and doesn't respect DB_HOST. Patches are welcome to make it respect DB_HOST or alternatively add a --[no-]create-db-user flag.

@Fedcomp
Copy link
Author

Fedcomp commented Nov 27, 2016

Okay, thank you for the answers!
I have one more question, why won't installer use default container postgres user? instead, as you said, it tries to create user, but it can be done by pg container itself.

@glebm
Copy link
Contributor

glebm commented Nov 27, 2016

The installer assumes there is a PostgreSQL database on 127.0.0.1 that it has superuser access to (and calls sudo -u $PG_DAEMON_USER if it doesn't). It then checks if the user already exists in that database and creates it if it doesn't exist.

The username, password, and database host are not currently configurable but perhaps they should be via installer flags. PRs are welcome!

@snoopiesnax
Copy link

Indeed, the database part of this script needs some fixing. I had to manually create, migrate and seed after running it (https://gist.github.com/snoopiesnax/909ba428ea00a782d5fd5695e294faab).

The username, password, and database host are not currently configurable but perhaps they should be via installer flags. PRs are welcome!

Sounds like that oughta do it!

Also, here on OpenBSD we use doas instead of sudo, and the default PostgreSQL user is _postgresql instead of postgres. Hopefully I'll have a bunch of PRs coming your way soon.

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

No branches or pull requests

3 participants