Capistrano - Unable to deploy my database.yml

When I try to deploy my application using capistrano, I will get this error:

failed: "sh -c" cp / var / www / my _app / releases / 20120313115055 / config / database.staging.yml / var / www / my _app / releases / 20120313115055 / config / database.yml '"on IP_ADDR

My database.yml , i.e. empty, database.staging.yml :

production: adapter: mysql2 encoding: utf8 reconnect: false database: my_db pool: 15 username: my_user_name password: my_pass host: localhost 

in / confing / deploy are the "production" "staging" files

What am I missing here / where should I look for failure? The credentials for the database on the server must be correct.

EDIT - here is my deployment

 set :application, "my_app" set :repository, "https://IP_ADDR/svn/my_app" set :scm, :subversion set :scm_username, 'my_name' set :scm_password, 'my_pass' default_run_options[:pty] = true set :user, "my_name" set :domain, 'IP_ADDR' set :deploy_to, "/var/www/my_app" set :use_sudo, false set :deploy_via, :remote_cache #set :keep_releases, 1 set :rails_env, 'production' role :web, domain role :app, domain role :db, domain, :primary => true # This is where Rails migrations will run namespace :deploy do task :build_gems, :roles => :app do desc "Building gems" run "cd #{release_path} && bundle install --deployment" end task :migrations do desc "Migrating database" run "cd #{release_path} && rake db:migrate RAILS_ENV=production" end [:start, :stop].each do |t| desc "#{t} task is a no-op with passenger" task t, :roles => :app do ; end end desc "Restarting passenger with restart.txt" task :restart, :roles => :app, :except => { :no_release => true } do run "touch #{release_path}/tmp/restart.txt" end after "deploy:update_code", "deploy:build_gems", "db:copy_configuration", "config:copy", "deploy:migrations", "deploy:cleanup" after "deploy:update", "bluepill:copy_config", "bluepill:restart" end namespace :db do task :copy_configuration do run "cp #{release_path}/config/database.staging.yml #{release_path}/config/database.yml" end end namespace :config do task :copy do run "cp #{release_path}/config/config.staging.yml #{release_path}/config/config.yml" end end namespace :bluepill do desc "Restart bluepill process" task :restart, :roles => [:app] do run "#{release_path}/script/delayed_job stop" sudo "/etc/init.d/bluepill.sh restart" end #desc "Load bluepill configuration and start it" ##task :start, :roles => [:app] do # sudo "/etc/init.d/bluepill.sh start" #end desc "Prints bluepills monitored processes statuses" task :status, :roles => [:app] do sudo "bluepill status" end desc "Copy config" task :copy_config, :roles => [:app] do run "cp #{release_path}/config/bluepill/configuration.rb /srv/script/bluepill.rb" end end 

Problem:

 cp: cannot stat `/var/www/my_app/releases/20120313144907/config/database.staging.yml': No such file or directory 
+8
ruby database deployment capistrano
source share
3 answers

I am not sure how to solve your problem. Database.staging.yml doesn't seem to be deploying, so there is nothing to copy it.

I think there is a better workflow there. Things like database settings and configurations usually do not change between deployments, so these things can go in the shared folder of all capistrano releases. As a rule, you do not want your database.yml to be in your repo or with its confidential information. You can satisfy both of these things by excluding config/database.yml in .gitignore .

This requires you to do one time on your servers. You need to create database.yml in your_app_path/shared/config . Shared is a sibling and current release.

In your deploy.rb should be set that symbolizes a new deployed version of database.yml for inclusion in the shared folder. Like this:

 before "deploy:assets:precompile" do run ["ln -nfs #{shared_path}/config/settings.yml #{release_path}/config/settings.yml", "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml", "ln -fs #{shared_path}/uploads #{release_path}/uploads" ].join(" && ") end 

This means that your repo will not contain database.yml files. Since they are probably already in your repo. You will have to git rm them, commit. Add them to .gitignore and commit this.

+21
source share

Capistrano 3 has built-in binder files. John's answer is simple:

  • In the shared/ folder, create config/database.yml
  • In config/deploy.rb use this line

     set :linked_files, fetch(:linked_files, []).push('config/database.yml') 

This is what John said.

+8
source share

If you donโ€™t need to โ€œrefer to application objects or methodsโ€ ( 1 ) during precompilation, then you can be fine with config.assets.initialize_on_precompile to false in config/application.rb

0
source share

All Articles