Database.yml and multi-stage Capistrano deployment

Posted on by Tim Rosenblatt

If you're using Capistrano's multi-stage deploy addon, it makes things work really well. Staging servers are excellent for testing and demoing new features and code before releasing it to your users. If you need to change your database.yml files, or another config file, here's a technique for changing passwords or API keys depending on which stage you are deploying to.

In your main deploy.rb, add an

And just throw as many of these in as you need. This will call these tasks no matter which stage you are deploying to (and as an added benefit, if you forget to define a method for a stage, it will error and alert you). Next step is to define an "update_config_file" or "update_database_yml" file for each stage. In your /config/deploy/ path, you'll have a file for each stage that you deploy to. Go in there and add something like this:

Just define as many of these tasks as you need, and change your config files to contain whatever values you need them to. Clean and simple, happens 100% automatically with each deploy.

 
comments powered by Disqus