assaf / vanity

Experiment Driven Development for Ruby
http://vanity.labnotes.org
MIT License
1.55k stars 269 forks source link

ActionView::Template::Error when deployed with Dokku #307

Closed thomasjedstrom closed 7 years ago

thomasjedstrom commented 7 years ago

Hey guys,

I'm running into an issue where everything works fine when running locally but seems to be unable to find the test once deployed. It seems strange because it looks as though Vanity is getting fired on line 4, but then collapses all together claiming it can't find the database. But again, it works fine when run locally. Any thoughts would be greatly appreciated.

Log

1: Started GET "/" for 75.17.240.75 at 2016-10-04 12:24:37 +0000
2: Processing by HomeController#index as HTML
3: Rendering home/index.html.erb within layouts/application
4: WARN -- : No default alternative specified; choosing You Got Test A as default.
5: Rendered home/index.html.erb within layouts/application (7.4ms)
6: Completed 500 Internal Server Error in 10ms (ActiveRecord: 0.0ms)
7:
8:  ActionView::Template::Error (could not connect to server: No such file or directory
9:      Is the server running locally and accepting
10:     connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
11: ):
12:      2:
13:      3: <h4>
14:      4:     <a href="/test" id="test">
15:      5:         <%= ab_test(:welcome_message) %>
16:      6:     </a>
17:      7: </h4>
18:      8:

vanity.yml:

development: &default
  adapter: active_record
  active_record_adapter: postgresql
  database: abtesting_development
test:
  adapter: active_record
  active_record_adapter: default
  collecting: false
production:
  <<: *default
  database: abtesting_production

ApplicationController

class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception

  use_vanity :user_identity

  protected

  def user_identity
    (0...8).map { (65 + rand(26)).chr }.join
  end
end
phillbaker commented 7 years ago

Hi @thomasjedstrom - what's your production database.yml look like? (Don't need the real values, but representative examples would help.)

thomasjedstrom commented 7 years ago
default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: abtesting_development

test:
  <<: *default
  database: abtesting_test

production:
  <<: *default
  database: abtesting_production
  password: <%= ENV['ABTESTING_DATABASE_PASSWORD'] %>

Honestly I'm not totally sure how the communication to Postgres works here. Dokku is a lot like Heroku so there's a lot that goes on behind the scenes, but for the most part it usually just works. I'm fairly certain the password isn't actually doing anything but this is approximately how some of my other projects have looked so I just left it as is. What do you think?

phillbaker commented 7 years ago

Hm, just to confirm - does database access for other rails objects work? If you're including a password in the production config, you'll also need it in the vanity config.

However, if it's the same database (ie the app data is stored in the same database as the vanity data), then it's probably fine to piggy back on the same connection, in your vanity.yml:

production:
  adapter: active_record
  active_record_adapter: default
thomasjedstrom commented 7 years ago

I think that second part was the issue. They're using the same database and while the database doesn't have a problem, I think maybe Vanity was seeing the password and getting hung up on it. Since it wasn't necessary anyways I nixed it. I also explicitly defined the adapter and active_record_adapter in vanity's production and it's running now. For science I should have done those one at a time to see which was the sticking point, but I'll at least post the side by side.

So, this was the old vanity.yml:

development: &default
  adapter: active_record
  active_record_adapter: postgresql
  database: abtesting_development
test:
  adapter: active_record
  active_record_adapter: default
  collecting: false
production:
  <<: *default
  database: abtesting_production

And here was the new vanity.yml that now works:

development: &default
  adapter: active_record
  active_record_adapter: postgresql
  database: abtesting_development

test:
  adapter: active_record
  active_record_adapter: default
  collecting: false

production:
  adapter: active_record
  active_record_adapter: default
  database: abtesting_production

Thanks Phil, I should have been able to trial and error that one out on my own, but thanks for walking it through with me.