managing database.yml securely - no such file to load "deploy/capistrano_database"

440 views
Skip to first unread message

treydock

unread,
Jan 30, 2012, 4:43:16 PM1/30/12
to Capistrano
I'm attempting use of Capistrano for the first time, and have followed
the steps on the wiki to "Manage database.yml securely".

I've put both database.yml.erb and capistrano_database.rb into
multiple locations, all with the same results. I've tried config/
deploy/ and now deploy/

This is the error
-------------
cap deploy:setup
/home/trey/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/
rubygems/custom_require.rb:36:in `require': no such file to load --
deploy/capistrano_database (LoadError)


Here's my config/deploy.rb
----------

#############################################################
## Application
##############################################################
set :application, "ballotbox"

#############################################################
## Settings
##############################################################
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'deploy')
require "deploy/capistrano_database"

$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) # Add RVM's lib
directory to the load path.
require "rvm/capistrano" # Load RVM's capistrano
plugin.
set :rvm_ruby_string, 'ruby-1.9.2-p290@ballotbox' # Or whatever
env you want it to run in.

require "bundler/capistrano"

set :use_sudo, false

#############################################################
## Servers
##############################################################
set :user, "ballotbox"

set :deploy_to, "/usr/share/#{application}"

set :domain, "liberalartsvoting.tamu.edu"
role :web, domain
role :app, domain
role :db, domain, :primary => true

#############################################################
## Git
##############################################################
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`,
`perforce`, `subversion` or `none`
set :scm, :git
set :repository, "g...@cllawolf.tamu.edu:ballotbox.git"
set :branch, "master"

#############################################################
## Passenger
##############################################################
namespace :passenger do
desc "Restart Application"
task :restart do
run "touch #{current_path}/tmp/restart.txt"
end
end

after :deploy, "passenger:restart"


The "$LOAD_PATH" was an attempt to force the deploy/ directory to be
loaded. My Capfile looks like this...


$ cat Capfile
load 'deploy' if respond_to?(:namespace) # cap2 differentiator

# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'

Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each
{ |plugin| load(plugin) }

load 'config/deploy' # remove this line to skip loading any of the
default tasks


Thanks
- Trey

Michael Richardson

unread,
Feb 3, 2012, 4:26:07 PM2/3/12
to capis...@googlegroups.com

>>>>> "treydock" == treydock <trey...@gmail.com> writes:
treydock> I'm attempting use of Capistrano for the first time, and
treydock> have followed the steps on the wiki to "Manage
treydock> database.yml securely".

I'm not really sure what you are trying to do.

This is what I do. Put database.yml and production.rb (because I have
some settings that differ depending on which machine, alpha test or
release) into ~ on the target machine(s).
(I often put those files there by debian package and/or post-install
script), and I do:

namespace :deploy do
task :update_database_yml, :roles => [:app,:web] do
db_config = "/home/#{user}/database.yml"
prod_config = "/home/#{user}/production.rb"
run "cp #{db_config} #{release_path}/config/database.yml"
run "cp #{prod_config} #{release_path}/config/environments"
releasenum=File.basename(release_path)
run "echo '$ReleaseNum = \"#{releasenum}\"' >#{release_path}/config/initializers/releasenum.rb"
puts "Ran update database_yml"
end
after "deploy:update_code", "deploy:update_database_yml"
end

(Releasenum.rb is included in my layout as a comment, so I can know that
in fact I did deploy properly...)

--
] He who is tired of Weird Al is tired of life! | firewalls [
] Michael Richardson, Sandelman Software Works, Ottawa, ON |net architect[
] m...@sandelman.ottawa.on.ca http://www.sandelman.ottawa.on.ca/ |device driver[
Kyoto Plus: watch the video <http://www.youtube.com/watch?v=kzx1ycLXQSE>
then sign the petition.

treydock

unread,
Feb 7, 2012, 11:41:23 PM2/7/12
to Capistrano
I ended up getting it working. What I was working towards was having
capistrano prompt me during setup for the production db password that
way I can push an erb templated database.yml to production without
storing any passwords.

This is what fixed my issue,



On Feb 3, 3:26 pm, Michael Richardson <m...@sandelman.ca> wrote:
> ] m...@sandelman.ottawa.on.cahttp://www.sandelman.ottawa.on.ca/|device driver[

treydock

unread,
Feb 7, 2012, 11:42:47 PM2/7/12
to Capistrano
And accidently hit send,...

Capfile - added these 2 lines to end of it to load
-------------
$:.unshift File.join(File.dirname(__FILE__), 'config/deploy')
require "capistrano_database_yml"
Reply all
Reply to author
Forward
0 new messages