Fork me on GitHub
Credit and license

DevOps and automation: Continuous integration

Overview

Teaching: 15 min
Exercises: 5 min
Questions
  • What is continuous integration?
  • How does continuous integration benefit me?
  • What tools can I choose from?
Objectives
  • The goal is to understand what CI is about

Introduction

  • According to Wikipedia:

In software engineering, continuous integration (CI) is the practice of merging all developer working copies to a shared mainline several times a day

  • In optimal case, CI can be interpreted so that every single commit made by a developer will go through to entire pipeline to a test ed package, ready to be deployed.
  • …and this pipeline should be automatic
  • Workflows can differ, but a basic example could be:

    1. commit your code change to the repository
    2. system runs all tests against the code
    3. system builds the package
    4. system installs the package to a clean server
    5. test the build
    6. test in production-like environment
    7. deploy to production
  • It can be possible to connect your CI server to for example chat services, so in case of a failure, the team gets the news instantly

Available CI solutions

  • There are plethora of products you can choose from
  • Many of these are hosted by someone else, but you can also install your own
  • Jenkins, Bamboo, Travis, Buildbot…

Travis

  • Travis is a nice option used commonly
  • Basics of Travis were introduced in earlier modules:
    • Hosted CI service bound to GitHub
    • Tests are run on a dedicated virtual machine
    • Supports a wide variety of languages, including R, Python, Perl and many many more
    • Supports also several analyzers
    • Free to use for Open Source projects. For serious use you might need a paid version.

Jenkins

  • Jenkins is an open source automation server
  • There are tons of plugins available, to do almost anything, find plugins from: https://wiki.jenkins-ci.org/display/JENKINS/Plugins
  • The plugin system allows you to do complex setups. For example by combining Ansible and Cloud environments you could automatically test and deploy this to myriad different environments, for example on different operating systems.
  • Installation of plugins can be done easily from Jenkins web user interface:
  • To install your own dedicated Jenkins server You can deploy the Jenkins war file on top of an existing server or for example create a dedicated server with tools created by other people:
    • Ansible roles (you can find several!)
    • Deploy it as a Docker image
  • With Jenkins you can do complicated workflows. You can for example:
    • Run unit tests automatically
    • Package the source code
    • Trigger creation of a production-like servers, where the code or package is deployed
    • Run integration and regression tests


Excercise

  • In this excercise a test is fixed and we can see how Jenkins automatically picks up the fix and runs the tests against the new code
  • Clone a repository from https://github.com/coderefinery/ci-example-python to your GitHub page
  • Create a feature branch, fix the failing test and submit a pull request to the repository above

Key points

  • CI is about automating the entire release cycle

  • Do small incremental changes. Release them often.