Continuous Deployment with Travis
Created by Floor Drees, @floordrees
What is this Continuous Deployment thing?
Continuous deployment is part of the continuous delivery ‘movement’. The idea behind continuous delivery is to automate the software delivery process as far as possible.
With a working continuous deployment chain in place you’ll enforce Git deployments (everything must be committed to be tested and everything must be tested to be deployed), making collaboration easier and deployment faster. So you can focus on making your app even more awesome!
There are a few great companies sailing the continuous wave, in this guide we’ll set up continuous deployment for our Ruby on Rails app from GitHub to anynines, using Travis-ci.
COACH: Talk about the benefits of continuous deployment.
Github, Travis CI and anynines
The first thing we need is an app in a Github repository. And we have just that! Next you’ll need to make sure you followed the guide on how to deploy your app via anynines until the very last step.
Then, we need to create a file called
manifest.yml in the main directory of your app, so we can save some information about the deployment there. In your terminal run:
This will trigger a first deployment to anynines. The cf gem will notice that there is no
manifest.yml and will ask you a standard set of configuration questions such as the desired number and memory size of your app instances, whether and which services to bind to them and most importantly, whether you want to store this information.
Please answer this question with a ‘hell yes’ as it will create the desired
Once your push was successful, you should be able to access your application using a browser of your choice, which means your are ready to setup Travis!
For now we don’t have ‘real tests’, so we will go ahead and create a Travis configuration file that will fake a succeeding test suite. Please go to your local app directory and create a
.travis.yml file. At the moment, paste the following content. We’ll add some more information later on, using the Travis gem.
Your app now contains the Travis configuration but how should Travis know when to pull your code from Github and trigger test execution? This is where Github hooks come into play!
Travis CI Github hook activation
Commit and push a code change to your repository and check travis-ci.org to see if your test suite is being executed. You should also receive an email that your build succeeded.
Now we can configure the actual deployment. Let’s use the travis gem:
Now use the
travis command to setup the anynines deployment.
In case you don’t know the anynines target URL use
to gather all information required for Travis setup. This includes target url, username, the organization and space you are currently using. You can also take a look-see at the welcome mail you have received after signing up at anynines.com.
travis command has finished, your
.travis.yml should look somewhat like this:
Don’t forget to commit and push your changes to
.travis.yml as it will be required in your Github repository to take effect.
From now on whenever you commit changes to your Github repository, tests will be run and your app is being deployed. Travis will then show a log output similar to this:
This means your are done and good to go!