Continuous Integration

Goals

By the end of this lesson, you will:

  • Understand what continuous integration is and why it’s important
  • Be familiar with a typical deployment flow for agile teams
  • Be able to set up CircleCI for continuous integration and automatic deployments for front-end or back-end applications.

You are required to fill out this exit ticket at the end of the lesson

Important Vocabulary

  • local environment: A version of an application that a developer can edit and run on their own machine (i.e. an application run on localhost).
  • production environment: A deployed version of an application that the end user can interact with (i.e. a final project deployed on Heroku or Fly.io)
  • lower environments: Any environments that are internal to a team/company and are used for development purposes. Lower environments usually include a testing/QA environment that’s used for testing and/or a staging environment that’s used for showcasing features before a release. Lower environments are not viewable by the end user.
  • deployment: The process of making software (with new features and changes) available in a target environment
  • deployment pipeline: A system of automated processes (often managed by a CI tool) responsible for facilitating the building, testing and deployment of code from a version control system to production.

For further reading on environments and the history of multi-environment deployment processes, refer to this lesson

What is Continuous Integration

Continuous integration (CI) is the practice of merging code to a main branch (“integrating” code) regularly and verifying the quality of merged code with the help of automated build and testing tools. This practice developed out of the pain and struggles developers felt after dealing with problems integrating different branches and features that had been developed in isolation over the course of weeks or even months. In order to properly practice continuous integration on software teams, developers should diligently monitor these automated tools so that when an error is detected, they are able to promptly fix it. Development teams often find that this practice allows them to more easily and quickly deploy integrated code with fewer bugs.

Continuous integration is not the same as continuous delivery, but it is closely connected. Continous delivery means keeping your application in a “deployable state” so that it can be released at any time. CD is often associated with releasing smaller changesets more often, rather than huge releases at a less frequent cadence. You cannot practice continuous delivery without also practicing continous integration. Many teams these days will rely on some sort of automated service to handle testing these changesets and facilitating frequent releases.

Some of the most common CI services you’ll hear about are TravisCI, CircleCI, Github Actions, and Jenkins. They all behave similarly, though each tool’s setup and configuration process is slightly different. Focus on integrating CircleCI to perform a full build of an application, test it using our test suite, and automatically deploy our changes to Heroku.

Why Use a CI Tool?

It is important to run and test a complete build of your application before you release it to production. Think of how easy it was to deploy new changes to your production apps on Heroku. You would make a commit, which would immediately be reflected on production after running git push heroku main. What if that commit introduced breaking changes? There is no safeguard or filter against pushing up bad code. With a CI tool like CircleCI, we can still take advantage of automatic deployments, but we also get an extra layer of assurance that our app is in good condition before any changes are pushed live.

CircleCI will also help with catching errors that you might not find locally. By mimicking a production environment more closely, we can recognize any differences that might be causing inconsistent behavior between environments. For example, if I am developing an app locally and I did an npm install(JavaScript apps) or bundle install(Ruby apps) months ago, and I did not explicitly lock down the version numbers for each of my dependencies in my package.json or Gemfile, I might not notice that my production environment received more updated packages during the npm install/bundle install phase. Some of these packages may have included breaking changes that would only be exposed in production and impossible to reproduce locally until another npm install/bundle install was run.

What is a Build?

Think of all the steps you have to take if you want to collaborate on a classmate’s project. You have to fork their repo, clone it down locally, make sure you have an up-to-date version of Node (or some other platform) on your machine, install any dependencies, start up a server and maybe run a file watcher.

Sometimes more complex projects require additional steps. This setup process is called a build. It’s all the things you need to do to get your app up and running. CI tools will run through all of these steps (and then some!) to ensure the application is in a stable, working state before it goes to production.

Phases of the Build Process

The .yml file can define settings for various build lifecycle phases.

  • install: install any dependencies required (configure the virtual machine (VM) to be able to run your code)
  • script: run the build script (run your code and tests)
  • deploy: deploy your code to your web servers (such as deploying to Heroku)

Configure Automatic Deployments

If a build passes in your CI, then that means the code is probably good enough to go to production. You can make your CI tool automatically deploy to a service of your choice after the build passes. Consider Heroku, Vercel, or Netlify for your deployments.

Here are some resources to get you started with setting up CD:


Getting Started with CI

There are many tools available to implement CI. We’re sharing these examples with you for exposure and to start your research, but we do not require you to implement CI on your own. You may choose to explore it if it interests you.

You can find some options, guides, and ideas below to get you started in your research.

Checks for Understanding

Fill out this form!

Lesson Search Results

Showing top 10 results