db:pull without providing ENV password and username?
Closed this issue · 11 comments
In database.yml on my production server I define my database keys like this:
production:
database: awesome_app_production
pool: 25
username: <%= ENV['DATABASE_USERNAME'] %>
password: <%= ENV['DATABASE_PASSWORD'] %>
And when pulling the database to my local environment I need to do this:
$ cap production db:pull DATABASE_USERNAME=my_username DATABASE_PASSWORD=my_password
Is there a way of letting capistrano-db-tasks
to automatically pull the information from the .rbenv-vars
located in the shared folder on the production folder? That is where I enter database credentials and environment variables since I'm using rbenv-vars.
It would be nice to be able to only run cap production db:pull
@karlingen Can you try pull database with this PR: #70 ? Is it helpful?
@numbata Thanks for your reply. But unfortunately, it didn't work.
It just waits for password input:
$ cap production db:pull
DEBUG [394a7e4a] Running /usr/bin/env [ -d /home/deploy/.rbenv/versions/2.2.0 ] as deployer@XX.XX.XX.XX
..
[1a5735fc] Command: cd /home/deployer/awesome_app/current && pg_dump --no-acl --no-owner -h localhost awesome_app_production | bzip2 - - > db/awesome_app_production_2015-10-12-095702.sql.bz2
DEBUG [1a5735fc] perl: warning: Setting locale failed.
DEBUG [1a5735fc] perl: warning: Please check that your locale settings:
DEBUG [1a5735fc] LANGUAGE = (unset),
DEBUG [1a5735fc] LC_ALL = (unset),
DEBUG [1a5735fc] LC_CTYPE = "UTF-8",
DEBUG [1a5735fc] LANG = "en_US.UTF-8"
DEBUG [1a5735fc] are supported and installed on your system.
DEBUG [1a5735fc] perl: warning: Falling back to the standard locale ("C").
DEBUG [1a5735fc] Password:
^C(Backtrace restricted to imported tasks)
cap aborted!
@karlingen hmm. That's strange, because in PR #70 capistrano-db-tasks execute rails on remote server with all remote ENV variables to get remote database configuration (this line).
Can i ask you to debug my PR and make sure, that @config
contains your production database config put puts @config
under this line?
@numbata It was my bad! I forgot to prefix it with bundle exec
. Running bundle exec cap production db:pull
worked but resulted in a different error:
$ bundle exec cap production db:pull
..
[7ccbfc68] Running /home/deployer/.rbenv/bin/rbenv exec bundle exec rails runner "puts ActiveRecord::Base.connection.instance_variable_get(:@config).to_yaml" 2>/dev/null as deployer@46.101.215.96
DEBUG [7ccbfc68] Command: cd /home/deployer/awesome_app/current && ( RBENV_ROOT=/home/deployer/.rbenv RBENV_VERSION=2.2.0 RAILS_ENV=production /home/deployer/.rbenv/bin/rbenv exec bundle exec rails runner "puts ActiveRecord::Base.connection.instance_variable_get(:@config).to_yaml" 2>/dev/null )
DEBUG [7ccbfc68] ---
DEBUG [7ccbfc68] :database: awesome_app_production
DEBUG [7ccbfc68] :pool: 25
DEBUG [7ccbfc68] :username: awesome_app_production_user
DEBUG [7ccbfc68] :password: masked_password
DEBUG [7ccbfc68] :host: localhost
DEBUG [7ccbfc68] :adapter: postgresql
DEBUG [7ccbfc68] :encoding: unicode
DEBUG [7ccbfc68] Finished in 7.239 seconds with exit status 0 (successful).
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deployer@XX.XX.XX.XX: Only mysql or postgresql on remote and local server is supported
Only mysql or postgresql on remote and local server is supported
Tasks: TOP => db:pull => db:local:sync
(See full trace by running task with --trace)
I am running postgresql on both local and production server.
@karlingen my fault - forgot to stringify keys of database config. fixed
Next error:
DEBUG [432a8883] Running /home/deployer/.rbenv/bin/rbenv exec bundle exec rails runner "puts ActiveRecord::Base.connection.instance_variable_get(:@config).to_yaml" as karmet@localhost
DEBUG [432a8883] Command: ( RBENV_ROOT=/home/deployer/.rbenv RBENV_VERSION=2.2.0 /home/deployer/.rbenv/bin/rbenv exec bundle exec rails runner "puts ActiveRecord::Base.connection.instance_variable_get(:@config).to_yaml" )
DEBUG [432a8883] sh: /home/deployer/.rbenv/bin/rbenv: No such file or directory
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deployer@XX.XX.XX.XX: rails exit status: 32512
rails stdout: Nothing written
rails stderr: sh: /home/deployer/.rbenv/bin/rbenv: No such file or directory
SSHKit::Command::Failed: rails exit status: 32512
rails stdout: Nothing written
rails stderr: sh: /home/deployer/.rbenv/bin/rbenv: No such file or directory
Tasks: TOP => db:pull => db:local:sync
(See full trace by running task with --trace)
@karlingen - This may be a moonshot, but does you database password happen to contain a single quote in it?
I use randomly generated pws for everything and this just occurred for me. If this is the case the single quote ends the input of your pw (which is passed as a single quoted string) in the script line early causing weird errors. I have to imagine this is a rare scenario, but figured it was worth pointing out as I had to dig for quite a while to notice it.
Nice guess, but (un)fortunately we don't have any special characters in our
password.
@karlingen is it actual for you? I make a lot of changes in PR #70. Can you check them?
Sorry for bump this necroissues 💀
@karlingen PR #70 merged. Please, reopen this issue if you still have error.