Blue-Green deployment solution for Capistrano, using symbolic links between releases.
Blue Green Concept
Learn more about Blue Green Deployment with Martin Fowler
Presentations about this gem and the concept:
- Video Presentation - FISL15 - Portuguese
- Slides - FISL15 - Portuguese
- Video Presentation - QCon RJ - Portuguese
- Slides - QCon RJ - Portuguese
Cap Blue Green Deployment is a non canonical Blue Green solution, based on symlinks. Instead of having blue and green, we have pre and live. Pre is always validation environment and live it's production environment.
You can do as many deploys as you need to pre without affecting your live env. Changing symlinks you can easily put your code from validation to production environment.
- Capistrano 2 (Capistrano 3 coming soon)
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install cap_blue_green_deploy
And then, require the gem script under your capistrano configuration file (Capfile, deploy.rb, ...):
Understanding the deploy folder:
- current: Pre environment. Used to test and validate your application.
- current_live: Live environment. Your production access goes here. This dir name can be customized in custom variables, see below
- previous_live: Last live release. Used to do the rollback action of current_live. This dir name can be customized in custom variables, see below
Going to Pre
This command is an alias for
cap deploydefault task. It will run the deploy process and create the
Going to Live
This command will change symlinks of
current_livedir to use the same release path of
currentdir. And also create the
previous_livesymlink to track the last current live release used.
This command will change the
current_livesymlink to use the same destination of
This is the same behavior of the default capistrano cleanup
deploy:cleanup, but the
previous_livereleases will be preserved and not removed.
This lib automatically rewrite the default deploy:cleanup to use this new cleanup function.
Don't forget that you need to add the cleanup callback manually in your capistrano file:
after "deploy:update", "deploy:cleanup"
You can change the default values by overwriting them in your capistrano file. The default values are:
- keep_releases: 5
- blue_green_live_dir: "current_live"
- blue_green_previous_dir: "previous_live"
How to Play
Custom Variables used
set :keep_releases, 2
set :blue_green_live_dir, "current_live"
set :blue_green_previous_dir, "previous_live"
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request