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.
Simply stated, Workflows adds a simple coordination layer between jobs.
Let's start by visualizing a simple workflow
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.
We could have just as easily made a single job that inlines all of the steps run. What did we gain by introducing workflows?
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.
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.
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.
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.
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