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

db:pull without providing ENV password and username? #74

Closed
karlingen opened this issue Oct 11, 2015 · 11 comments
Closed

db:pull without providing ENV password and username? #74

karlingen opened this issue Oct 11, 2015 · 11 comments

Comments

@karlingen
Copy link

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

@numbata
Copy link
Collaborator

numbata commented Oct 12, 2015

@karlingen Can you try pull database with this PR: #70 ? Is it helpful?

@karlingen
Copy link
Author

@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!

@numbata
Copy link
Collaborator

numbata commented Oct 12, 2015

@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?

@karlingen
Copy link
Author

@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.

@numbata
Copy link
Collaborator

numbata commented Oct 14, 2015

@karlingen my fault - forgot to stringify keys of database config. fixed

@karlingen
Copy link
Author

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
Copy link
Author

@numbata anything new here?

@karlingen karlingen changed the title Support for rbenv-vars? db:pull without providing ENV password and username? Nov 28, 2015
@ThomasBush
Copy link

@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.

@karlingen
Copy link
Author

karlingen commented Mar 10, 2016

Nice guess, but (un)fortunately we don't have any special characters in our
password.

@numbata
Copy link
Collaborator

numbata commented Sep 15, 2016

@karlingen is it actual for you? I make a lot of changes in PR #70. Can you check them?
Sorry for bump this necroissues 💀

@numbata
Copy link
Collaborator

numbata commented Oct 4, 2016

@karlingen PR #70 merged. Please, reopen this issue if you still have error.

@numbata numbata closed this as completed Oct 4, 2016
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