Re-Blog: CI & CD With Docker, Beanstalk, CircleCI, Slack, & Gantree

Posted Dec 10th, 2014

Bleacher-report-logoDocker movement going on in the dev world right now and not many QA Engineers have gotten their hands dirty with the technology yet. What makes Docker so awesome is the ability to ship a container and almost guarantee its functionality.

At Bleacher Report we get to play with some amazing, cutting edge tools. While CircleCI has been in the game for a while, they were the first CI system to adopt Docker support. With just one line of code you have access to all of the power of docker. Bleacher Report also let me build an open source tool called Gantree that allows us to manage and deploy our applications seamlessly. Not only did we want to ship our containers from development to production seamlessly, we also wanted to ensure the image we built actually passed our integration and unit tests as well. While the below example only shows a small set of unit tests, it is a great sample application due to its simplicity. Note, our Carburetor app is an Elixir application that uses mix to run its tests. Getting Started

  • First you need to create an account with CircleCi and add your Github repository.
  • Then, commit a circle.yml
  • Example circle.yml:
      version: 2.1.3
      - docker
      SHORT_SHA: $(echo $CIRCLE_SHA1 | cut -b1-7)
      IMAGE_PATH: “bleacher/cms”
      DOCKER_RUN_CMD: “elixir -pa _build/prod/consilidated -S mix test”
      PROD: carburetor-prod-s1
      STAG: carburetor-stag-s1

      - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
      - docker build -t $IMAGE_PATH:$TAG_NAME .

      - docker run -tip 3000:3000 bleacher/carburetor:$TAG_NAME $DOCKER_RUN_CMD

      branch: release
        - gem install gantree
        - docker push $IMAGE_PATH:$TAG_NAME
        - gantree deploy $PROD -i $IMAGE_PATH -t $TAG_NAME
      branch: continuous-deployment
        - gem install gantree
        - docker push $IMAGE_PATH:$TAG_NAME
        - gantree deploy $STAG -i $IMAGE_PATH -t $TAG_NAME
  • Change the image_path to your docker hub account/repo
  • Add your environment variables needed
  • Remove the docker login steps if you are using an open source image.
  • Change your docker run variable to match the command needed to kickoff your tests.

Running Tests: running tests 1

  • This should now be able to deploy your application.

Gantree deploy: deploy Slack notification from ubuntu:

  • This will only happen if you have a .gantreecfg with your information added in the repo.

Slack A note about integration tests This example does not show how to run integration tests but this is dependent on your language and testing choice. One way to theoretically handle this is to have multiple docker run commands. Here is an example of a rails application:

      - docker run -ti bleacher/carburetor:$TAG_NAME bundle exec rake test
      - docker run -tip 3000:3000 bleacher/carburetor:$TAG_NAME bundle exec rails s
      - docker run -ti bleacher/carburetor:$TAG_NAME bundle exec rake test:integration:sauce

The first command runs the integration tests, the second starts the web server and the third starts the integration test suite. You just have to make sure your tests are pointed at localhost:3000.  Have a question or comment? Follow Felix on Twitter at . His original post can be found here.

Written by

Bill McGee