Explaining how the real world works!     RSS Feed The Automated Tester on Twitter The Automated Tester on LinkedIn The AutomatedTester on github

A basic continuous deployment process

Mon 12 Sep 2011

One of the major buzzwords floating around the Internet these days is continuous deployment. Continuous Deployment is the process of pushing code to servers straight from trunk at any moment. A number of companies do this on a commit/push and most of those companies have chosen to push the code straight to their production servers. This means they could be releasing up to once every 11 seconds. For those who want to learn more about it I suggest that you look up continuous deployment at Imvu, easy, flickr, Amazon and Mozilla.

The approach that I took for my setup was to have a deployment process similar to if you were to use Heroku or Joyent's no.de service. When I am ready to deploy I just want to do git push myserver master. I know this process won't scale well but for most sites this is all you need.

I have been developing an IRC bot for my team to use. It does lookups in Bugzilla, it can give people links to our Pivotal Tracker projects and does logging of what is happening in the channel and a few other things. So far my team has been making really good use of it, and being people who work in QA, they tend to find bugs or think of new features.

I wanted a way that I could fix bugs, or create features required, and release with out too much effort.

The following is what I do on my free AWS EC2 Micro instance. Please note that my IRC bot is written to run with Node.Js so some things will have a Node.Js slant but the my overall process will work for every one.

On the server you want to deploy do the following

mkdir project-folder.git # note the .git prefix 
mkdir project-folder 
cd project-folder.git 
git init --bare 
git config core.worktree project-folder
git config core.bare false
git config receive.denycurrentbranch ignore
cd hooks 
mv post-receive.sample post-receive 
Edit the post-receive file and add git checkout -f to the file

Now on our development machine a simple

git remote add micro ssh://user@aws-instance/~/project-folder.git 
git push micro master 

If you go into project-folder on your server you should see your code now. If you received a security exception make sure that you have copied your ssh public key, like the one you may have put on Github, in to ~/.ssh/authorized_keys on your server. Add a new line and then the ssh key. Try push again once that is correct.

Now we need a way to restart Node.Js when there is new code is deployed. I used Nodemon by Remy Sharp. Instead of doing node myapp.js just do nodemon myapp.js. Nodemon will restart the node process running you application when it sees changes to the JavaScript files.

If you do all of the above things you should have a basic Continuous Deployment process. I haven't created any rollback scripts for if something goes wrong but since you can push fixes quickly that shouldn't matter too much.

    Area: blog

blog comments powered by Disqus