Continuous Integration

Part 2, Chapter 3


Next, we'll add continuous integration (CI), via Travis CI, to our projects.


Do you usually use a different CI service or run Jenkins? It's encouraged to check your understanding by continuing to use the CI service that you're accustomed to. Convert the Travis configuration examples as necessary.

Follow steps 1 and 2 of the Getting Started guide to enable Travis in the project.

To trigger a build, add a .travis.yml file to the project root:

sudo: required

services:
  - docker

env:
  DOCKER_COMPOSE_VERSION: 1.23.2

before_install:
  - sudo rm /usr/local/bin/docker-compose
  - curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
  - chmod +x docker-compose
  - sudo mv docker-compose /usr/local/bin

before_script:
  - docker-compose up -d --build

script:
  - docker-compose exec users python manage.py test
  - docker-compose exec users flake8 project

after_script:
  - docker-compose down

Commit your changes, and then push to GitHub. This should trigger a new build, which should pass.

If you get an error indicating that port 5432 is already used -- Failed to bind tcp 0.0.0.0:5432 address already in use -- make sure that port is only exposed to other containers in the Docker Compose file. It should not be exposed to the host.

Once done, add a README.md file to the project root, adding the Travis status badge:

# Microservices with Docker, Flask, and React

[![Build Status](https://travis-ci.org/YOUR_GITHUB_USERNAME/testdriven-app.svg?branch=master)](https://travis-ci.org/YOUR_GITHUB_USERNAME/testdriven-app)

Be sure to replace YOUR_GITHUB_USERNAME with your actual GitHub username.

In terms of workflow, for now, while the project structure is still somewhat simple, we'll:

  1. Code a new feature locally
  2. Commit and push code
  3. Ensure tests pass on Travis



Mark as Completed