When I try to deploy my app with capistrano, I\'ll get this error:
failed: \"sh -c \'cp /var/www/my_app/releases/20120313115055/config/database.stagi
If you don't need to "reference application objects or methods"(1) during precompile then you might be OK with setting config.assets.initialize_on_precompile
to false
in config/application.rb
I'm not sure how to solve your problem. It looks like database.staging.yml is not being deployed, so there's nothing for it to copy over.
I think there's a better workflow, though. Things like settings and database configs do not typically change between deployments, so those things can go in the shared folder of all the capistrano releases. Typically, you don't want your database.yml to be in your repo either since it's sensitive information. You can satisfy both of these things by excluding config/database.yml
in your .gitignore
.
This requires you to do a one time set up on your servers. You need create a database.yml
at your_app_path/shared/config
. Shared is a sibling to current and releases.
Your deploy.rb
should have a task that symlinks the newly deployed release's database.yml
to the on in the shared directory. 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 contain no database.yml
files. Since they are probably already in your repo. You'll have to git rm
them, commit. Add them to the .gitignore
and commit that.
In Capistrano 3, linking files is built-in. John's answer is simply:
shared/
folder create config/database.yml
In config/deploy.rb
use this line
set :linked_files, fetch(:linked_files, []).push('config/database.yml')
This does what John was saying.