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

Docker image does not start when using external PostgreSQL #1921

Closed
ckir opened this issue Mar 5, 2017 · 8 comments
Closed

Docker image does not start when using external PostgreSQL #1921

ckir opened this issue Mar 5, 2017 · 8 comments
Labels

Comments

@ckir
Copy link

ckir commented Mar 5, 2017

When I start the image using external MySql like

docker run --rm --name huginn \
    -p 3000:3000 \
    -e DATABASE_ADAPTER=mysql2 \
    -e DATABASE_HOST=db4free.net \
    -e DATABASE_PORT=3306 \
    -e DATABASE_NAME=d2i454kcn7i0kp \
    -e DATABASE_USERNAME=pofjnbukbwemck \
    -e DATABASE_PASSWORD=<don't give your password away>\
    cantino/huginn

works fine, but when I use external PostgreSQL like

docker run --rm --name huginn \
    -p 3000:3000 \
    -e DATABASE_ADAPTER=postgresql \
    -e DATABASE_HOST=ec2-54-197-230-161.compute-1.amazonaws.com \
    -e DATABASE_PORT=5432 \
    -e DATABASE_NAME=d2i454kcn7i0kp \
    -e DATABASE_USERNAME=pofjnbukbwemck \
    -e DATABASE_PASSWORD=<don't give your password away> \
    -e DATABASE_ENCODING=utf8 \
    -e DATABASE_RECONNECT=true \
    -e DATABASE_POOL=5 \
    -e ON_HEROKU=true \
    cantino/huginn

It gives me

2017-03-05 09:36:53,194 CRIT Set uid to user 0
2017-03-05 09:36:53,194 WARN Included extra file "/etc/supervisor/conf.d/bootstrap.conf" during parsing
2017-03-05 09:36:53,194 WARN Included extra file "/etc/supervisor/conf.d/foreman.conf" during parsing
2017-03-05 09:36:53,228 INFO RPC interface 'supervisor' initialized
2017-03-05 09:36:53,228 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2017-03-05 09:36:53,228 INFO supervisord started with pid 1
2017-03-05 09:36:54,232 INFO spawned: 'stdout' with pid 193
2017-03-05 09:36:54,234 INFO spawned: 'bootstrap' with pid 194
2017-03-05 09:36:54,241 INFO success: bootstrap entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2017-03-05 09:36:54,243 INFO exited: bootstrap (exit status 1; not expected)
2017-03-05 09:36:55,309 INFO success: stdout entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
bootstrap stdout | DATABASE_HOST=ec2-54-197-230-161.compute-1.amazonaws.com
bootstrap stdout | DATABASE_ADAPTER 'postgresql' is not supported internally. Please provide DATABASE_HOST.

Any ideas ?

@0xdevalias
Copy link
Member

0xdevalias commented Mar 5, 2017 via email

@dsander
Copy link
Collaborator

dsander commented Mar 5, 2017

Hi @ckir,

you are right, this is a bug in the multi process image, for now your can work around it by using POSTGRES_PORT_5432_TCP_ADDR instead of DATABASE_HOST.

@dsander dsander added the bug label Mar 5, 2017
dsander added a commit to dsander/huginn that referenced this issue Mar 5, 2017
When `DATABASE_ADAPTER` is set to `postgresql` we do not need to start
the internal mysql daemon. The same is true when `DATABASE_ADAPTER` is
set to `mysql2` and `DATABASE_HOST` is set.

Fixes huginn#1921
@ckir
Copy link
Author

ckir commented Mar 6, 2017

Hi @dsander,

I tried the workaround like

docker run --rm --name huginn
-p 3000:3000
-e DATABASE_ADAPTER=postgresql
-e POSTGRES_PORT_5432_TCP_ADDR=ec2-54-197-230-161.compute-1.amazonaws.com
-e DATABASE_PORT=5432
-e DATABASE_NAME=d2i454kcn7i0kp
-e DATABASE_USERNAME=pofjnbukbwemck
-e DATABASE_PASSWORD=<don't give your password away>
-e DATABASE_ENCODING=utf8
-e DATABASE_RECONNECT=true
-e DATABASE_POOL=5
-e ON_HEROKU=true
-e AGENT_LOG_LENGTH=20
cantino/huginn

but it gives me

bootstrap stdout | DATABASE_HOST=ec2-54-197-230-161.compute-1.amazonaws.com
foreman stderr | FATAL:  permission denied for database "postgres"
DETAIL:  User does not have CONNECT privilege.
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"utf8", "reconnect"=>true, "database"=>"d2i454kcn7i0kp", "pool"=>5, "username"=>"pofjnbukbwemck", "password"=>"<don't give your password away>", "host"=>"ec2-54-197-230-161.compute-1.amazonaws.com", "port"=>5432, "socket"=>"/tmp/mysql.sock", "strict"=>false}
foreman stderr | rake aborted!
PG::ConnectionBad: FATAL:  permission denied for database "postgres"
DETAIL:  User does not have CONNECT privilege.

Please note: It tries to connect to database "postgres" not "d2i454kcn7i0kp"

@dsander
Copy link
Collaborator

dsander commented Mar 6, 2017

It seems like rails is trying to create the database even if it still exists and your database user does not have the permission to do that.

Can you try the image huginnbuilder/huginn:pr-1922 and set the DO_NOT_CREATE_DATABASE environment variable to something?

@ckir
Copy link
Author

ckir commented Mar 6, 2017

Hi @dsander,

Image huginnbuilder/huginn:pr-1922 started like

docker run --rm --name huginn
-p 3000:3000
-e DATABASE_ADAPTER=postgresql
-e POSTGRES_PORT_5432_TCP_ADDR=ec2-54-197-230-161.compute-1.amazonaws.com
-e DATABASE_PORT=5432
-e DATABASE_NAME=d2i454kcn7i0kp
-e DATABASE_USERNAME=pofjnbukbwemck
-e DATABASE_PASSWORD=<don't give your password away>
-e DATABASE_ENCODING=utf8
-e DATABASE_RECONNECT=true
-e DATABASE_POOL=5
-e ON_HEROKU=true
-e AGENT_LOG_LENGTH=20
-e DO_NOT_CREATE_DATABASE=true
huginnbuilder/huginn:pr-1922

gives me

2017-03-06 22:29:47,952 CRIT Set uid to user 0
2017-03-06 22:29:47,952 WARN Included extra file "/etc/supervisor/conf.d/bootstrap.conf" during parsing
2017-03-06 22:29:47,952 WARN Included extra file "/etc/supervisor/conf.d/foreman.conf" during parsing
2017-03-06 22:29:48,080 INFO RPC interface 'supervisor' initialized
2017-03-06 22:29:48,080 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2017-03-06 22:29:48,080 INFO supervisord started with pid 1
2017-03-06 22:29:49,084 INFO spawned: 'stdout' with pid 143
2017-03-06 22:29:49,086 INFO spawned: 'bootstrap' with pid 144
2017-03-06 22:29:49,119 INFO success: bootstrap entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2017-03-06 22:29:49,316 INFO spawned: 'foreman' with pid 146
2017-03-06 22:29:49,326 INFO success: foreman entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2017-03-06 22:29:49,336 INFO exited: bootstrap (exit status 0; expected)
2017-03-06 22:29:50,338 INFO success: stdout entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
bootstrap stdout | DATABASE_HOST=ec2-54-197-230-161.compute-1.amazonaws.com
foreman stderr | rake aborted!
NameError: uninitialized constant Rack::LiveReload
foreman stderr | /app/config/environments/development.rb:4:in block in <top (required)>' /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/railtie.rb:209:in instance_eval'
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/railtie.rb:209:in configure' /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/railtie.rb:181:in configure'
/app/config/environments/development.rb:3:in <top (required)>' /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/engine.rb:600:in block (2 levels) in class:Engine'
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/engine.rb:599:in each' /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/engine.rb:599:in block in class:Engine'
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/initializable.rb:30:in instance_exec' /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/initializable.rb:30:in run'
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/initializable.rb:55:in block in run_initializers' /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/initializable.rb:44:in each'
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/initializable.rb:44:in tsort_each_child' /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/initializable.rb:54:in run_initializers'
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/application.rb:352:in initialize!' /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/railtie.rb:193:in public_send'
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/railtie.rb:193:in method_missing' /app/config/environment.rb:5:in <top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/application.rb:328:in require_environment!' /app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/application.rb:448:in block in run_tasks_blocks'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
2017-03-06 22:30:01,320 INFO exited: foreman (exit status 1; not expected)

and no tables created in the database

@dsander
Copy link
Collaborator

dsander commented Mar 6, 2017

@ckir I honestly can't tell you why it makes a difference but it works for me without the ON_HEROKU environment variable.

@0xdevalias
Copy link
Member

@dsander Haven't looked too deeply into ON_HEROKU, but it seems to have some interesting quirks (and has sort of outlived it's naming IMO) Was thinking after I get done with the docker stuff, maybe looking into a small refactor of it, check where it's used, and call it something more relevant (probably with a legacy mapping of ON_HEROKU->new name) As best I can tell, it's main uses seem to be around the dotfile/env var usage, and forcing to postgres DB.

(Not necessarily relevant to this thread, but reminded me of a thing I was thinking about)

@dsander
Copy link
Collaborator

dsander commented Mar 17, 2017

@ckir Feel free the reopen the issue if the latest docker image still has problems for your use case.

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

No branches or pull requests

3 participants