Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broader CI bundler cache #841

Merged
merged 10 commits into from
Dec 11, 2019
Merged

Broader CI bundler cache #841

merged 10 commits into from
Dec 11, 2019

Conversation

marcotc
Copy link
Member

@marcotc marcotc commented Oct 16, 2019

Depends on #821

This PR adds an extra caching layer to the local gem cache, /usr/local/bundle, that is able to be re-utilized across different CI builds.

This PR does not affect the behavior of bundle install or appraisal install, or the gems they select to install. This only pre-populates the local cache.

The caching key needs to only depends on information available before bundle install and appraisal install are run. This rules out the checksum of gem lock files.

With this in mind, this caching key was chosen:

bundle-{{ .Environment.CIRCLE_CACHE_VERSION }}-<<parameters.ruby_version>>-{{ checksum "lib/ddtrace/version.rb" }}-{{ .Branch }}-{{ checksum "Gemfile" }}-{{ checksum "Appraisals" }}-{{ checksum "ddtrace.gemspec" }}

It varies by: Ruby version, dd-trace-rb version, git branch name, contents of Gemfile, Appraisals, and ddtrace.gemspec.

It can also be arbitrarily invalidated at any point by setting a different CIRCLE_CACHE_VERSION environment variable in our CI pipeline.

When restoring this cache key, we try a few combinations:

- restore_cache:
 keys:
  - bundle-{{ .Environment.CIRCLE_CACHE_VERSION }}-<<parameters.ruby_version>>-{{ checksum "lib/ddtrace/version.rb" }}-{{ .Branch }}-{{ checksum "Gemfile" }}-{{ checksum "Appraisals" }}-{{ checksum "ddtrace.gemspec" }}
  - bundle-{{ .Environment.CIRCLE_CACHE_VERSION }}-<<parameters.ruby_version>>-{{ checksum "lib/ddtrace/version.rb" }}-{{ .Branch }}-
  - bundle-{{ .Environment.CIRCLE_CACHE_VERSION }}-<<parameters.ruby_version>>-{{ checksum "lib/ddtrace/version.rb" }}
  1. With every parameter matching.
    1. Speeds up workflow reruns.
  2. With the same Ruby version, dd-trace-rb version, and git branch name.
    1. Speeds up successive runs on branches that change Gemfile and Appraisals files. Caching content is still good, as all unchanged dependencies are likely the same.
  3. With the same Ruby version and dd-trace-rb version.
    1. Speeds up first build of a branch. Caching content should be valuable, as we still ensure we use the latest cache for the current dd-trace-rb version.

This fallback strategy guarantees the only build that runs without any gem caching is a version bump (or manual cache invalidation through CIRCLE_CACHE_VERSION).

For reference, the current cache persistency layer we have is used to propagate installed dependencies to downstream jobs (e.g CI test steps,) and speeds up CI workflow reruns.
It is very precisely matched to the current build environment, depending on the checksum of all gemlock files.
Given it depends on gemlocks files, that are only available after gem installation, it cannot be used to speed up such operation.

Some results

Before:
Screen Shot 2019-10-16 at 6 14 55 PM
After:
Screen Shot 2019-10-16 at 6 15 00 PM
(~ 1-2 minute reduction)

@marcotc marcotc added dev/testing Involves testing processes (e.g. RSpec) ci-cache-dependencies labels Oct 16, 2019
@marcotc marcotc requested a review from a team October 16, 2019 22:42
@marcotc marcotc self-assigned this Oct 16, 2019
@delner
Copy link
Contributor

delner commented Oct 17, 2019

Thanks for this @marcotc! I'll give this a review in a bit, but those results look promising!

@marcotc
Copy link
Member Author

marcotc commented Oct 17, 2019

I added checksum ".circleci/bundle_checksum" to the caching key, to allow for cache busting when gem lock files change.

delner
delner previously approved these changes Oct 25, 2019
Copy link
Contributor

@delner delner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@delner delner added this to In review in Active work Nov 21, 2019
@marcotc marcotc changed the base branch from test/parallel-ci to master December 10, 2019 22:29
@marcotc marcotc merged commit b1887c7 into master Dec 11, 2019
Active work automation moved this from In review to Merged & awaiting release Dec 11, 2019
@marcotc marcotc deleted the test/ci-cache branch December 11, 2019 19:54
@marcotc marcotc added this to the 0.31.0 milestone Jan 7, 2020
@delner delner moved this from Merged & awaiting release to Released in Active work Mar 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev/testing Involves testing processes (e.g. RSpec)
Projects
Active work
  
Released
Development

Successfully merging this pull request may close these issues.

None yet

2 participants