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
Breaking a Large Rails App into Smaller Apps
Standalone Ruby -- How to Load Different Environments from Database.Yml
Robustly Call a Flaky API: Proper Error Handling with Net::Http
How to Have One Resource in Routes for Namespace and Root Path Altogether - Rails 4
How to Find Out Why a Gem Bundle Has Locked a Gem at a Specific Version
How to Calculate Next, Previous Business Day in Rails
Zip Up All Paperclip Attachments Stored on S3
Rails Routing: Giving Default Values for Path Helpers
Why Do I Need Asterisk Before an Array
When to Use Self in Module's Methods
Gemfile.Lock Always Has Changes Not Staged for Commit
Carrierwave: Create 1 Uploader for Multiple Types of Files
Installing Pl/Ruby for Postgresql 8.3
How to Find .Index of a Multidimensional Array
Ruby on Rails:How to Implement Cancel Button in Form_Tag
How to Share Worker Among Two Different Applications on Heroku