The problem: I use capistrano to deploy my projects, many of which I keep in public github repositories. While I’m happy to share my code, I don’t want my system credentials, server addresses, and deployment locations visible to the world. I could add deploy.rb and my config directory to .gitignore but deployment scripts are complicated enough to benefit from version control. Additionally, there may be some value in sharing them with the outside world.
The solution: Capistrano is just a ruby DSL and can load external files. We can put the bulk of the deployment configuration in deploy.rb and check it into version control, while leaving the deployment user’s credentials in a separate file that only lives on the local machine.
In our deploy.rb we have:
set :application, "sample_app" set :scm, "git" set :repository, "email@example.com:geektastical/sample_app.git" set :branch, "master" require '../credentials/sample_app.rb' # lives outside project dir # rest of deploy
In our credentials/sample_app.rb we have:
Capistrano::Configuration.instance.load do set :deploy_to, "deploy_path" role :app, "server_name" set :user, "username" set :password, "password" end