-
Notifications
You must be signed in to change notification settings - Fork 177
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
issue #54 Add support of ENV['DATABASE_URL'] #70
issue #54 Add support of ENV['DATABASE_URL'] #70
Conversation
@fabn @donbobka @ktaragorn @markgandolfo could you check this PR? |
@cap.with rails_env: @cap.fetch(:rails_env) do | ||
@config = @cap.capture(:rails, 'runner "puts Rails.application.config.database_configuration[Rails.env].to_yaml"', '2>/dev/null') | ||
@config.gsub!(/.*\-\-\-/m, '---') # Remove all bundler and rails initialization errors | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this line? Which kind of errors are you trying to prevent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Errors, warnings and notices like:
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all non-root users on this machine.
or
Your Gemfile lists the gem X (>= 0) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of just one of them later.
which captured with database configuration and breaks the config yaml.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I am missing something.. But is there a reason to use rails runner here? Rather than just depending on the :environment task or something? Is this because it is happening on the remote?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach in #54 seems marginally cleaner to me, using a rake task
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ktaragorn via saving config to temporary file through rake task?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah.. Actually it does pretty much the same thing https://github.com/donbobka/capistrano-db-tasks/blob/77cbfcc5f5ff3a2be6f552cb54f8ae37294b6b72/lib/tasks/capistrano-db-tasks.rake.. Ignore what I said.. Was just wondering if adding this extra layer somehow took care of the errors without you having to manually..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ktaragorn i don't wanna using rake task, because we can require 'capistrano-*' gems only in development group. On the production (and staging) server they can be unavailable and our rake task too.
Alternative: #54 (comment) (author @fabn). But save file to tmp/config.yml
isn't correct. Because tempdir can be one of [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], @@systmpdir, '/tmp', '.']
and can be unequal tmp/
(proof).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough!
I'll try this tomorrow and report the result here. |
I tried it and I have the following issues
For the latest point I found out that If I start a production console (in a rails 4.1.12 application configured with Rails.application.config.database_configuration[Rails.env] # => nil
ActiveRecord::Base.connection.instance_variable_get(:@config) # => {:pool=>"25", :encoding=>"utf8", ...} |
@fabn thanks for report. I tried it with different versions of Rails and got similar result. # Rails 4.2.3
ActiveRecord::Base.connection.instance_variable_get(:@config) # => {:adapter=>"postgresql", :username=>"app_user", :password=>"app_password", :port=>5432, :database=>"app_database", :host=>"127.0.0.1"}
Rails.application.config.database_configuration[Rails.env] # => nil
# Rails 3.2.21
ActiveRecord::Base.connection.instance_variable_get(:@config) # => {:adapter=>"postgresql", :username=>"app_user", :password=>"app_password", :port=>5432, :database=>"app_database", :host=>"127.0.0.1"}
Rails.application.config.database_configuration[Rails.env] # => Errno::ENOENT: No such file or directory - /apps/cctv/config/database.yml |
@fabn @ktaragorn review please :) |
@fabn @donbobka @ktaragorn @markgandolfo @leifcr so sorry for necro-PR 💀 . But could you check this pull request if it still actual for you? |
@numbata still valid for my current setup, as with 12 factor setup, the db config is not stored as part of the app, but as part of the infrastructure. |
For testing purposes i tested separate ENV params as well, and it works with this PR: staging:
database: <%= ENV['DB_NAME'] %>
username: <%= ENV['DB_USER'] %>
password: <%= ENV['DB_PASSWORD'] %>
host: <%= ENV['DB_HOST'] %> |
Need this PR! Please, merge it |
…d::Base.connection as config source
e79f8fd
to
fc7856f
Compare
Happy birthday, PR! 🎉 🎈 Now, let's merge it. |
thanks @numbata |
Using
Rails.application.config.database_configuration
to get database configuration instead ofdatabase.yml
file. Works with database configuration from ENV['DATABASE_URL'] also.