Get ahead
VMware offers training and certification to turbo-charge your progress.
Learn moreLast week, I began this series by announcing that the Sagan reference app is now open source and showed how to get up and running with it on your own machine.
In this post, I want to walk through how we push Sagan into production at spring.io multiple times a day with zero downtime using blue-green deployments. You may have heard of this technique before; Martin Fowler gave it a write-up a few years ago, and there is a section on it in the highly-recommended book Continuous Delivery. In a nutshell, it goes like this:
Conceptually, blue-green deployments are simple and the benefits are significant (deploy often, never go down, roll back with ease). But without the right infrastructure, they can be tricky to implement. For example, to accomplish the critical fourth step of "flipping the switch", you need a fast, reliable, and automated means of mapping and unmapping production URLs between the blue and green environments. A DNS-based approach fails on most or all of these criteria; what you want is a platform that is built with use cases like this in mind.
Fortunately, Cloud Foundry is just such a platform. The Pivotal Web Services documentation on blue-green deployments does a great job of explaining how the CF Router makes this kind of mapping and unmapping possible.
In the case of the Sagan project, while working with CF's routing infrastructure did indeed give us the fast and reliable mapping we needed, it left a little to be desired in the automation department. We initially wrote shell scripts around the Ruby cf
client, and then migrated them to the new Go-based gcf
client when it came out. This worked, but what we really wanted was a solution that (a) we didn't have to write and maintain ourselves, and that (b) could run 100% on the JVM, driven natively by Sagan's Gradle build.
To make this happen, we worked with Scott Frederick on the Cloud Foundry team, who did an excellent job of enhancing the Cloud Foundry Gradle plugin to support blue-green deployments as a first-class feature. It means no more shell scripts, declarative configuration, and out of the box, zero-downtime deployments are now as simple as:
./gradlew deploy -Pspace=production
But this is the sort of thing that's better shown than described. In this screencast, I'll walk through the process of upgrading Sagan from Spring Boot 1.0.0.M5 to the newly-announced 1.0 GA, and pushing the change live, blue-green style.
!{iframe src="//player.vimeo.com/video/90956088" width="640" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen}{/iframe}
Note: See the show notes for links to sites mentioned in the screencast
Check out how to run the site on Cloud Foundry on the Sagan wiki to get started, and remember you can use the invitation code "sagan" to get immediate approval for an account at Pivotal Web Services.
We'll have another entry in this series next week. We're still planning the content for that, and it would be great to hear what aspects of the Sagan application you'd like to see explored. Until then!