Who's Afraid of Continuous Deployment?
Join the DZone community and get the full member experience.Join For Free
we can all see the risks here. one slightly screwy checkin could create a bug that's not covered by unit tests. that code then goes live to your production environment, where customers see it and get angry. they then cancel their service, your company goes out of business, and you're forced to eat nothing but hamburger helper for the rest of your life.
i was well aware of these risks, but when i came onboard as cto of famigo , i was determined to give continuous deployment a try. why? well, i was initially intrigued by eric ries' writings on the subject . the more i thought about it, the more advantages i discovered.
first, continuous deployment makes deployment a non-event . before famigo, i worked for a great company called grasshopper . there, we would deploy around a dozen separate projects to nearly 50 machines every 2 weeks. even though we deployed relatively frequently, it wasn't uncommon for our deployments to last 10 hours and cause enormous stress on the team.
there were a number of reasons why deployment was such a pain point. the structure of our environment required a lot of manual intervention for deploying. also, we included a lot of manual testing at various points within the deployment so we could rollback quickly if we spotted an issue. the great thing about continuous deployment is that it addresses both of these problems, as you have no choice but to automate everything. if a deployment fails, it fails quickly .
second, continuous deployment forces you to build great tests . there's simply no way around this. as developers, we all know that we should be religiously writing tests for our code, but it's incredibly easy to cheat and say, "i'll catch up on my tests later," or "this test can fail for right now." the problem is that we never, ever clean that up. with continuous deployment, you absolutely can't operate in that manner. without repeatable and thorough testing, continuous deployment is continuous nightmare.
will you encounter production bugs that you didn't catch with a test? of course, you will. at that point, you write a test that covers the bug, you watch the test fail, you fix the bug, you watch the test pass, and then you commit. like magic, the fix goes out to production and you have a little more confidence in your code.
what if your code currently has horrendous test coverage? how do you get around the problem? simple: start writing tests . i spent nights and weekends writing unit and integration tests for famigo's api before i started work officially. i fully expected that time investment to pay immediate dividends once i was ready to start pushing my work for our third party mobile developers, and it has.
third, continuous deployment encourages good source control practices . you know what would be hilarious? another beverly hills cop movie. you know what would be even more hilarious? someone trying to continuously deploy with 50 developers all checking into the trunk all the time.
all non-idiotic source control systems have branches; use them ! if you're building something great, you're going to have to make breaking changes to your code. i'm a big fan of branching for these breaking changes/big features/huge refactors, and then merging that back into the trunk once you've stabilized the code. not only does that keep the build happy, that keeps your teammates happy because they don't have to suffer through you sending out emails to everybody saying, "i know i broke the trunk, it'll be fixed in 2 days or i'll come to work dressed as a leprechaun." so far, this branching strategy has been crucial to scaling the deployment process to larger teams.
another good source control practice that's enforced through continuous deployment is tagging. it's trivial to script your deployment out so that it tags each release you push to production. that is very helpful in the event you need to rollback.
fourth, and most importantly, continuous deployment is fun . you know what i love about making software? it's when someone tells me about a major problem that i can fix simply. i am inundated with warm, fuzzy feelings when i see that simple, but important change go live just a few minutes after i commit. it makes me feel like i'm making a difference.
not only is that sort of immediacy fun and rewarding, it actually makes you more productive. imagine you do monthly deployments. are you actually writing new code every day of that month? of course not. once you get close to the release, you do a code freeze and then you test for a while. if there's a bug with something you wrote 3 weeks ago, you have to figure it all out again and then start up the testing cycle once more.
if you're deploying continuously, you shorten that loop considerably because there's so little work in progress . you don't have to code freeze, and you don't have to test for a week to ensure the build is stable. that wasted time goes away.
how do you set up continuous deployments? it's simpler than you might think. first, download a continuous integration service; i really like hudson , which is free and easy to administer. once you have your continuous integration service installed, create a job inside of it that polls your source control repository every few minutes for changes. when changes are found, you want to build your code (if necessary) and run your unit tests. so far, this is straight up continuous integration .
the deployment angle comes in after the tests have been run. here, i just wrote a simple shell script that my hudson job calls before it completes. the script zips up the current production code and moves it to an archive directory, then it copies the files over from my continuous integration environment to our production environment. we do multiple projects in a couple of seconds this way. it took me an hour or two to figure out this shell script, so allow time for experimentation here.
continuous deployment is an ideal solution in any environment where you must me able to iterate very quickly. at our startup , that is a must. if you give it a shot with one of your simpler projects, i think you'll soon be won over, just as i've been.
if you're going to be in austin and want to talk lean startup or
mobile development, shoot me an email (cody at cody powell dot com) or
on twitter! first beer's on me.
Opinions expressed by DZone contributors are their own.