Skip to content

Instantly share code, notes, and snippets.

@lewang
Last active September 19, 2017 15:29
Show Gist options
  • Save lewang/2cf79f93c8b219ac3938f82d9636a2ec to your computer and use it in GitHub Desktop.
Save lewang/2cf79f93c8b219ac3938f82d9636a2ec to your computer and use it in GitHub Desktop.
blog wip

Intro

In the previous installment(linkify), we saw how Docker images add power and customization to the build process.

In this installment we'll show you how to amplify that power by using the CircleCI 2.0 "workflows" feature.

Workflows in detail

Simply stated, Workflows adds a simple coordination layer between jobs.

Let's start by visualizing a simple workflow

image

The workflow config stanza and live workflow run:

workflows:
  version: 2
  blog-demo-1:
    jobs:
      - bundle_dependencies
      - rake_test:
          requires:
            - bundle_dependencies
      - precompile_assets:
          requires:
            - bundle_dependencies
      - deploy:
          requires:
            - rake_test
            - precompile_assets

The blog-demo- workflow consists of 4 jobs. The bundle_dependencies job updates and caches dependencies. Then we "fan-out" into two parallel jobs - rake_test and precompile_assets. Each of these will restore the cached dependencies and do their own work. If rake_test and precompile_assets are both successful, we "fan-in" to the deploy job.

Benefits

We could have just as easily made a single job that inlines all of the steps run. What did we gain by introducing workflows?

Explicit parallelism = faster builds

Things happen faster when things happen in parallel.

The explicit "fan-out" parallelism offered by workflows can significantly reduce build times, especially as a project grows in complexity over time, and more and more independent parallelizable tasks such as code coverage are introduced.

In the example above, rake_test and precompile_assets benefit from this paralellism.

Each job may run in a different environment

In our example above, the deploy job runs in a "machine" instead of a docker container. You have the opportunity to specify a different docker image and resource_class for each job.

In order to reduce costs and minimize build times, a user may want to use a featureful container with beefy resources to run some common precursor steps, then fan-out into many lighter weight jobs for a fast parallelized build.

Repeatability - rerun from failed

If a job fails in the middle of a workflow due to a transient issue, you do not have to restart the workflow from the beginning. The "rerun failed jobs" feature allows the workflow to carry on using the failed jobs as a starting point.

Without workflows, you would always have to rerun the entire build.

Detailed status reporting to your VCS provider

With a workflow, your VCS provider (Github for example) will get a list of statuses one for each job, this way it's easier to tell at a glance where the failure happened and you can navigate directly to the job that failed.

Outro

In this blog post, we went through a gentle introduction to the workflows feature of Circle 2.0.

In the next installment, we'll walk through adding some advanced features including:

  • Workspace forwarding
  • manual approval jobs
  • branch and tag filtering
@lewang
Copy link
Author

lewang commented Sep 19, 2017

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment