Within this post I’d like to give you a short introduction for using Codeship in order to automtically build, test and deploy your web projects.
Codeship is a service which is free for a single concurrent build with 100 builds per month. So there is no cost for giving it a try, if you’re interested in bigger plans with more concurrent builds or if you (and your team) are more frequently pushing commits to either github or bitbucket you can choose one of the available paid plans from here.
Codeship supports the following programming languages
- Ruby (Rails is also included)
With all those languages being supported a broad range of web projects can be built and tested using CodeShip.
It also ships with support for a lot of well-known databse systems like (PostgreSQL, MongoDB or Redis just to name a few of them)
Throughout this post I’ll show a simple example using NodeJS as serverside language for my website.
Codeship is able to automatically deploy your project to
- Heroku (which I’ll use for my demo)
- Amazon AWS
- Google App Engine
- Engine Yard
Besides those well-know cloud providers there is also support for other platforms or you could hook up a custom script to deploy to the cloud of your choice.
I’ll not explain how to get all the pre-requirements up and running, I think all those services should belong to a developers toolbelt in these days.
- github or bitbucket account
- heroku account
Codeship itself is offering OAuth authentication in order to sign up quickly.
The sample App
To keep things simple, I’ll demonstrate how to configure and use Codeship with a simple website. All the source code is available on github right here. When browsing the repo, you’ll realize that there is nothing special. It’s just a simple HTML website being served by a Express server.
The Procfile is required for heroku, it tells how many web dynos heroku should use for making you app available.
Creating a Codeship project
Codeship’s interface is pretty simple and self-explaining. After signing up, you’ve to select a github or bitbucket repo which will be used as trigger for all the automation.
Using things like grunt is easy, but you’ve to ensure that grunt-cli (which has to be installed globally) is existing on your virtual build agent.
The setup area in the following screen can be used to configure your Spin-Up-Script. See the last line in the setup textarea where I’m defining
npm install grunt-cli
The second script area is responsible for executing your tests or any other command that should run right before your tests will be executed.
After saving you test commands, you’ll be redirected to the dashboard which should look like this
Configuring the automated deployment is as simple as configuring tests. Before looking into the deployment configuration, you’ve to ensure that your cloud-app is created. As mentioned during the introduction, I’ll use Heroku for this sample. Logon to heroku and create a new app provide a name for your app and choose a region.
I’ve created an app called
dotnetrocks-sample, heroku apps are created within seconds and you should be redirected to your app’s configuration page.
In order to get Codeship’s deployment up and running you also need an API Key, this key is related to your heroku user and can be found on the Manage your Account Page
Back in Codeship’s interface, open the Deployment configuration from the Actions Menu
From here it’s simple to configure Heroku, just select the heroku tile from the list of available targets and put in your App’s Name and the API Key you’ve grabbed from your Heroku Account.
Before pushing your commits to the selected github repo, you should check the following things in order to get everything working.
- An existing PROCFILE (see PROCFILE documentation)
- A exitsing package.json (see package.json)
- Ensure that your Node Engine is set
- configure scripts
- list all dependencies
Give it a try
Make some changes to your project and push them to github. Codeship will starting to build, test and deploy your changes immediately and you can watch the progress from your dashboard as shown here
The final result should be available on heroku within a few seconds and it should look like this
The value of codeship is amazing, besides automated builds and tests (which are also offered by other platforms) you can easily deploy your projects continuously. Especially for fast growing web projects it’s really important to see how changes will act either in your dev- or stage-environment