Capistrano - Can't Deploy My Database.Yml

Capistrano - can't deploy my database.yml

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.

Capistrano 3, Rails 4, database configuration does not specify adapter

Edit: Per this pull request, it's now fixed in version 1.1.0 of capistrano-rails.

Per this Github issue, another fix is to edit your Capfile. Comment out these two lines


#require 'capistrano/rails/assets'
#require 'capistrano/rails/migrations'

and put this line in


require 'capistrano/rails'

which will correctly set your RAILS_ENV variable.

capistrano - write database.yml

The Yaml::load is executed locally on your machine from which you run cap deploy this is why that file is not found it is not being searched remotely.

Take a look at this gem: capistrano-recipes, if you want you can use that. Otherwise to learn how they're doing here

For completeness here are how you can read a remote file in a cap recipe

file = capture "cat #{shared_path}/config/database.yml"

capture will execute a remote command and return its output as a string.



Related Topics



Leave a reply



Submit