Hank Stoever
part time nerd, part time gnar.

Continuous deployment with github, heroku and codeship.io

posted about 9 years ago - 2 min read

I love well-tested code, because it creates a certain peace of mind when you are writing software. It allows you to add new features and refactor old code while remaining confident that you aren't breaking anything. When all tests are passing, you can trust that deployments won't break. This post will teach you how to incorporate continuous deployment patterns to maximize developer efficiency and code stability.

Many people preach the values of Test Driven Development (TDD), which is a software development practice where tests are created before a feature is developed. By creating your tests first, you force yourself to get a good understanding of what the requirements of your code are. You have to consider what your methods will accept as parameters, what they will return, and any possible errors that could occur.

Most importantly, test driven development ensures you have a well-covered codebase. As stated before, this allows you to edit your codebase with the confidence that everything works properly.

Continuous Deployment

codeship logs

Continous deployment is a pattern where in one command, you push code (via git or similar) to a remote repository (like github), and tests are automatically ran on a remote server with this new codebase. If all tests pass, a staging server is updated and restarted with the new code.

While it is possible to create this flow with your own self-hosted tools, I prefer to rely on hosted solutions. These tend to be reliable, and I usually want to spend my time focusing on my own producs, not the development tools. Because of this, I use Github for code hosting, codeship.io for continuous deployments, and heroku for server hosting. Each of these services has a free teir that works well for small projects (like this website).

codeship config

Setting up codeship is extremely easy. You login with Github, select the repository you're using, and configure the technology stack you're using (ruby on rails, node.js, django, etc). You then connect to your Heroku application, and you're all set. Simply change your code, push to github, and if everything is setup correctly, your tests will be run on codeship. If those tests pass, your code will be pushed to Heroku. If you're having troubles, check out codeship's documentation.

From now on, you'll get handy error messages whenever a new build fails. You'll also have the confidence that your code in production is well tested. With codeship, you can do more things to automate your deployment, like updating your staging database with production data. You can also set up a heroku staging environment, and configure codeship so that if you push to a certain branch (like master), staging will be updated. You can manually pull this code into a stable branch, and set up codeship to push that code to your live production servers.

cool config

This setup creates a really resilient environment for your app in just a few minutes.

Build status for uludum.org:

Codeship Status for hstove/uludum

comments powered by Disqus