Skip to content

feat(cli): add --cache-from and --cache-to options to cartesi build - #485

Open
endersonmaia wants to merge 1 commit into
prerelease/v2-alphafrom
feature/add-cache-options-to-build
Open

endersonmaia wants to merge 1 commit into
prerelease/v2-alphafrom
feature/add-cache-options-to-build

Conversation

@endersonmaia

@endersonmaia endersonmaia commented Jun 3, 2026 •

Copy link
Copy Markdown
Member

Expose Docker Buildx cache backend specs via two new repeatable CLI flags:

cartesi build --cache-from type=local,src=/tmp/cache
--cache-to type=local,dest=/tmp/cache

The same options are also available per-drive in cartesi.toml:

[drives.root]
cache_from = ["type=gha"]
cache_to = ["type=gha,mode=max"]

CLI flags override the TOML values when non-empty.

Changes:

  • config.ts: add cacheFrom/cacheTo fields to DockerDriveConfig and
    defaultRootDriveConfig; parse cache_from/cache_to from TOML
  • builder/docker.ts: thread cacheFrom/cacheTo through ImageBuildOptions
    and append --cache-from / --cache-to args to the buildx invocation
  • commands/build.ts: add --cache-from and --cache-to options (accumulator
    style); merge into BuildContext and apply over per-drive config
  • tests/unit/config.test.ts: add assertion for cache_from/cache_to parsing
  • tests/integration/builder/docker.test.ts: add two integration tests —
    one verifying the local cache directory is written, one verifying that
    layers are recovered from a local cache after the daemon build cache is
    pruned (attested by comparing root.ext2 SHA-256 between the two builds)
  • tests/integration/builder/fixtures/Dockerfile.cache: new fixture using
    a non-deterministic RUN date layer to make cache-hit vs miss detectable

Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com

/close #483

@changeset-bot

changeset-bot Bot commented Jun 3, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f05974e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cartesi/cli Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 95.54% (🎯 0%) 1201 / 1257
🔵 Statements 95.54% 1201 / 1257
🔵 Functions 95.88% 93 / 97
🔵 Branches 0% 0 / 0
📁 File Coverage (12 files)
File Lines Statements Functions Branches Uncovered Lines
apps/cli/src/builder/directory.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/builder/docker.ts 🟢 89.09% 🟢 89.09% 🟢 90% 🔴 0% 95-97, 151-159
apps/cli/src/builder/empty.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/builder/none.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/builder/tar.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/compose/builder.ts 🟢 99.79% 🟢 99.79% 🟢 100% 🔴 0% 228
apps/cli/src/config.ts 🟢 92.75% 🟢 92.75% 🟢 94.12% 🔴 0% 65-66, 221, 230, 239, 259, ...
apps/cli/src/exec/cartesi-machine.ts 🟡 75% 🟡 75% 🟡 66.67% 🔴 0% 10-12, 28-30
apps/cli/src/exec/genext2fs.ts 🟢 96.92% 🟢 96.92% 🟢 100% 🔴 0% 87-88
apps/cli/src/exec/index.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/exec/mksquashfs.ts 🟢 91.23% 🟢 91.23% 🟢 100% 🔴 0% 68-72
apps/cli/src/exec/util.ts 🟢 94.44% 🟢 94.44% 🟢 100% 🔴 0% 47-48

@endersonmaia
endersonmaia requested a review from brunomenezes June 3, 2026 17:49
@endersonmaia endersonmaia linked an issue Jun 3, 2026 that may be closed by this pull request
Comment thread apps/cli/src/commands/build.ts Outdated

@tuler tuler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good. Fixup

@github-project-automation github-project-automation Bot moved this from Todo to Waiting Merge in Rollups SDK Jun 8, 2026
Expose Docker Buildx cache backend specs via two new repeatable CLI flags:

  cartesi build --cache-from type=local,src=/tmp/cache \
                --cache-to   type=local,dest=/tmp/cache

The same options are also available per-drive in cartesi.toml:

  [drives.root]
  cache_from = ["type=gha"]
  cache_to   = ["type=gha,mode=max"]

CLI flags override the TOML values when non-empty.

Changes:
- config.ts: add cacheFrom/cacheTo fields to DockerDriveConfig and
  defaultRootDriveConfig; parse cache_from/cache_to from TOML
- builder/docker.ts: thread cacheFrom/cacheTo through ImageBuildOptions
  and append --cache-from / --cache-to args to the buildx invocation
- commands/build.ts: add --cache-from and --cache-to options (accumulator
  style); merge into BuildContext and apply over per-drive config
- tests/unit/config.test.ts: add assertion for cache_from/cache_to parsing
- tests/integration/builder/docker.test.ts: add two integration tests —
  one verifying the local cache directory is written, one verifying that
  layers are recovered from a local cache after the daemon build cache is
  pruned (attested by comparing root.ext2 SHA-256 between the two builds)
- tests/integration/builder/fixtures/Dockerfile.cache: new fixture using
  a non-deterministic RUN date layer to make cache-hit vs miss detectable

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@endersonmaia
endersonmaia force-pushed the feature/add-cache-options-to-build branch from 1790c3a to f05974e Compare June 8, 2026 19:11
@brunomenezes

Copy link
Copy Markdown
Member

@endersonmaia can you rebase that so we can merge it?

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

Labels

None yet

Projects

Status: Waiting Merge

Development

Successfully merging this pull request may close these issues.

Docker cache support

3 participants