Travis CI


Using Depcon with Travis CI is extremely simple. In fact this site and many others are automatically deployed whenever source code changes. Lets walk through how to set up a deployment pipeline in Travis CI.

Repo Configuration

An assumption is that your current project is already building a Docker image. Assuming this your next step would be to create an application descriptor. For this guide lets call this depcon.yml.

The contents of the application descriptor will vary depending on your project. For this example we’ll use the descriptor we use to deploy this site:

id: /sites/depcon
cpus: 0.5
mem: 400.0
instances: 1
  type: DOCKER
    image: containx/depcon-site:${VERSION}
    network: BRIDGE
    forcePullImage: true
    - containerPort: 80
      hostPort: 0
      servicePort: 4010
      protocol: tcp
  HAPROXY_GROUP: external
- path: /
  portIndex: 0
  protocol: HTTP
  gracePeriodSeconds: 120
  intervalSeconds: 30
  timeoutSeconds: 20
  maxConsecutiveFailures: 3
  ignoreHttp1xx: false

Travis Configuration

Environment Variables

To deploy our descriptor in Travis we must declare some secret environment variables. Use the guide below as example of the required params and adjust according to your environment.

Variable Name Description
DOCKER_USERNAME Docker hub username
DOCKER_PASSWORD Docker hub password
MARATHON_HOST Hostname of your Marathon framework
MARATHON_USER Username to authenticate with Marathon with (if applicable)
MARATHON_PASS Password for Marathon (if applicable)
DEPCON_MODE Set the value to ‘marathon’

The settings above are defined within the Travis project page under “Settings”.

Here’s a screenshot reflecting the above details:


Travis YAML

Lets look at how we handle building and deploying our application during a Travis build. Here’s an example of a portion of the Travis YAML for this website:

  - docker

  - docker login -e="$DOCKER_EMAIL" -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
  - docker build -t containx/depcon-site .
  - docker tag containx/depcon-site containx/depcon-site:$TRAVIS_BUILD_NUMBER
  - docker run -d -p --name depcon containx/depcon-site

  - docker ps | grep -q depcon

  - docker push containx/depcon-site
  - docker push containx/depcon-site:$TRAVIS_BUILD_NUMBER
  - docker run -e DEPCON_MODE#=$DEPCON_MODE -e MARATHON_HOST=$MARATHON_HOST -e MARATHON_USER=$MARATHON_USER -e MARATHON_PASS=$MARATHON_PASS -v $PWD:/data containx/depcon app create /data/depcon.yml -p VERSION=$TRAVIS_BUILD_NUMBER --wait --force

So lets break down in sequence what the above file is doing:

  • Login to Docker hub with the user that has push writes. We’re using the variables we defined earlier.
  • Build this site leveraging the Dockerfile in this Repo
  • Tag the build with the version generated by Travis
  • Run the image
  • Test the image is actually running
  • Push the image to Docker hub
  • Run the Depcon container using the depcon.yml we created above and a parameter flag leveraging the version of this build. That’s it! You now have the ability to continuously update your project.