CI/CD with Travis CI

The first thing I want to do when I am working on a project of any kind is setup continuous integration and continuous deployment (CI/CD). Any good build tool or framework will have test running as a first class citizen. I like both Django and Ember. Django has a test task built into the framework and great testing tools. Ember has great testing tools and with Ember-CLI, a great test task built in. So when I start with either project, I do not have much setup to get tests going.

To automate the tests every time I commit something, if I am working on a private project, I like to use Codeship.io. If I am working on a public OSS (Open Source Software) project, the de facto seems to be Travis CI. Both services offer great integration with Github and Bitbucket. I am currently using these two projects (code-camp-ui and code-camp-api) to learn new things and CI/CD is one of those things.

To setup a Travis CI build, create an account, and then link either your Github or Bitbucket account. You will then be able to select the projects that you would like Travis CI to build. A build will be triggered for every push to the master branch or any pull requests that are opened. Travis CI will also report in the pull request the result of the build. Here are example Django .travis.yml and Ember .travis.yml setup with continuous integration.

When I got to the continous deployment step of the process, I chose to deploy the Ember application to Amazon’s AWS S3 and the Django application to Heroku. In this process, I learned that Travis CI comes with a CLI, which is open sourced and available via this Github Repo, that allows easy configuration of the .travis.yml for continuous delivery after successful builds. Deployments can get quite complicated within your .travis.yml but for me, a successful build should deploy the software to a single place. In the future, I may have master deploy to a staging environment and then a production branch deploy to the production environment.

After installing the CLI, I followed some instructions on their blog for setting up the deployments I mentioned above with S3. I also followed a friend’s blog post on how to setup an AWS user via an IAM role that I would use with my deployment. Additionally, I followed the docs for a deployment via Heroku. The Travis CLI also allows for the ability to encrypt the API keys used for deploying the code. I was incredibly pleased with how quick and easy it was to setup my CI/CD pipeline.

In the end with the deployment and everything, the final Django .travis.yml looked like this, and the final Ember .travis.yml looked like this.

comments powered by Disqus