Skip to content

feat: add Docker image layer caching between CI runs#78

Merged
chorrell merged 1 commit into
mainfrom
docker-image-caching
May 27, 2026
Merged

feat: add Docker image layer caching between CI runs#78
chorrell merged 1 commit into
mainfrom
docker-image-caching

Conversation

@chorrell
Copy link
Copy Markdown
Owner

@chorrell chorrell commented May 27, 2026

Summary

Caches Docker image layers between CI runs using the GitHub Actions cache backend, so repeated pushes build significantly faster.

What changed

.github/workflows/ruby.yml

  • Adds docker/setup-buildx-action to enable the GHA cache backend
  • Adds two docker/build-push-action steps that build node-test:22 and node-test:24 with cache-from/cache-to: type=gha before running tests
  • Removes the now-redundant DOCKER_BUILDKIT: 1 env var (Buildx enables BuildKit by default; Rakefile also sets it)
  • Suppresses a low-confidence zizmor cache-poisoning finding — both Docker actions are pinned to exact commit SHAs

spec/spec_helper.rb

  • create_image now tries Docker::Image.get("node-test:#{version}") first; falls back to build_from_dir if the pre-built image isn't present (e.g. local development)

How caching works

  • First run: layers are built from scratch and written to the GHA cache under scopes node22 / node24
  • Subsequent runs: cache-from: type=gha restores the cached layers — only changed layers are rebuilt
  • Both Ruby matrix jobs (3.4 and 4.0) share the same cache scopes, so the second job benefits from the first job's cache write on the same commit

Test plan

  • First CI run builds from scratch and writes cache
  • Second run shows cache hits in the "Build Node.js XX image" steps
  • Tests still pass on both Ruby 3.4 and 4.0

🤖 Generated with Claude Code

Uses docker/build-push-action with GitHub Actions cache backend to
cache Docker layer builds across runs. Images are built once per job
and tagged (node-test:22, node-test:24); spec_helper uses the pre-built
image directly instead of rebuilding from source.

On cache hit, the image build steps complete in seconds rather than
pulling and compiling from scratch each run. Both Ruby matrix jobs
share the same cache scopes, so the second job benefits immediately
from the first job's cache write.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@chorrell chorrell merged commit a6f2e4f into main May 27, 2026
6 checks passed
@chorrell chorrell deleted the docker-image-caching branch May 27, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant