Skip to content

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

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

endersonmaia wants to merge 2 commits into
prerelease/v2-alphafrom
feature/add-cache-options-to-build

Conversation

@endersonmaia

@endersonmaia endersonmaia commented Jun 3, 2026 •

Copy link
Copy Markdown
Member

This pull request adds support for Docker Buildx cache options to the cartesi build command, allowing users to specify cache sources and destinations for Docker builds. The changes introduce new --cache-from and --cache-to CLI flags, update the configuration parsing logic to support these options in cartesi.toml, and add comprehensive tests to ensure correct behavior.

Docker Buildx cache support:

  • Added --cache-from <spec> and --cache-to <spec> CLI flags to the cartesi build command, allowing users to specify Docker Buildx cache sources and destinations. These flags are repeatable and override any values set in cartesi.toml. [1] [2]
  • Updated the DockerDriveConfig type and configuration parsing to support cacheFrom and cacheTo arrays, both in code defaults and when reading from cartesi.toml. [1] [2] [3] [4]
  • Modified the Docker build logic to pass the --cache-from and --cache-to options to Docker Buildx when building images. [1] [2] [3] [4]

Testing and validation:

  • Added integration tests to verify that cache is populated and reused correctly using the new options, including checks for local cache directories and layer reuse. [1] [2]
  • Updated unit tests to cover parsing of cache_from and cache_to options from configuration files. [1] [2]

These changes improve build performance and reproducibility by enabling advanced Docker caching strategies in both CLI usage and configuration files.

/closes #483

@changeset-bot

changeset-bot Bot commented Jun 3, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0933509

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 91% (🎯 0%) 12260 / 13472
🔵 Statements 91% 12260 / 13472
🔵 Functions 81.71% 277 / 339
🔵 Branches 0% 0 / 0
📁 File Coverage (20 files)
File Lines Statements Functions Branches Uncovered Lines
apps/cli/src/base.ts 🔴 39.33% 🔴 39.33% 🟡 64.71% 🔴 0% 49, 70-71, 79-83, 88, 102, ...
apps/cli/src/builder/directory.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/builder/docker.ts 🟢 87.5% 🟢 87.5% 🟢 81.82% 🔴 0% 89-91, 93, 126-128, 186-195
apps/cli/src/builder/empty.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/builder/none.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/builder/nvram.ts 🟢 96.88% 🟢 96.88% 🟢 100% 🔴 0% 27
apps/cli/src/builder/tar.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/commands/foreclose.ts 🔴 49.09% 🔴 49.09% 🔴 50% 🔴 0% 69, 91-145
apps/cli/src/commands/refund.ts 🔴 38.2% 🔴 38.2% 🟡 66.67% 🔴 0% 55-109
apps/cli/src/commands/withdraw.ts 🔴 46.58% 🔴 46.58% 🟡 73.33% 🔴 0% 95-123, 277-278, 301-356, 3...
apps/cli/src/compose/anvil.ts 🟡 79.25% 🟡 79.25% 🟢 100% 🔴 0% 19-29
apps/cli/src/compose/builder.ts 🟢 99.79% 🟢 99.79% 🟢 100% 🔴 0% 228
apps/cli/src/compose/bundler.ts 🔴 4.82% 🔴 4.82% 🔴 0% 🔴 0% 8-40, 44-75, 79-92
apps/cli/src/compose/common.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/compose/database.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/compose/explorer.ts 🔴 6.67% 🔴 6.67% 🔴 0% 🔴 0% 10-38, 43-55, 59-72
apps/cli/src/compose/node.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/compose/passkey.ts 🔴 8.33% 🔴 8.33% 🔴 0% 🔴 0% 9-18, 23-42, 46-59
apps/cli/src/compose/paymaster.ts 🔴 7.69% 🔴 7.69% 🔴 0% 🔴 0% 8-21, 25-44, 48-61
apps/cli/src/compose/proxy.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -

@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
@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?

@endersonmaia
endersonmaia force-pushed the feature/add-cache-options-to-build branch from f05974e to 05479fe Compare October 19, 2026 13:03
@endersonmaia
endersonmaia requested a balanced review from Copilot October 19, 2026 13:04
@endersonmaia
endersonmaia force-pushed the feature/add-cache-options-to-build branch from 05479fe to 8c93f37 Compare October 19, 2026 13:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The cache flag accumulators fail type checking, and the recovery test can pass without exercising cache import.

2 open issues
What changed in this PR

Adds Docker Buildx cache configuration to cartesi build, supporting cache reuse in CI as requested in #483.

Changes:

  • Adds repeatable cache flags that override per-drive TOML settings.
  • Passes cache specifications to Docker Buildx.
  • Adds parsing and cache integration tests, plus a release note.
File Description
apps/​cli/​tests/​unit/​config.test.ts Tests TOML cache parsing and defaults.
apps/​cli/​tests/​integration/​builder/​fixtures/​Dockerfile.cache Adds a timestamp layer to detect cache reuse.
apps/​cli/​tests/​integration/​builder/​docker.test.ts Tests local cache export and recovery.
apps/​cli/​src/​config.ts Defines and parses per-drive cache settings.
apps/​cli/​src/​commands/​build.ts Adds cache flags and override handling.
apps/​cli/​src/​builder/​docker.ts Forwards cache options to Buildx.
.changeset/​cache-options-for-build.md Documents the CLI feature for release.

Review effort: Balanced

Comment thread apps/cli/src/commands/build.ts Outdated
Comment thread apps/cli/tests/integration/builder/docker.test.ts Outdated
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 8c93f37 to c2ad3d4 Compare October 20, 2026 12:04
@endersonmaia
endersonmaia requested review from tuler and a balanced review from Copilot October 20, 2026 13:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The cache-recovery test prunes unrelated caches from the user's selected Buildx builder.

1 open issue
2 resolved since last review

Review effort: Balanced

Comment thread apps/cli/tests/integration/builder/docker.test.ts

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

Cache settings are consistently wired through configuration and Buildx, prior feedback is addressed, and no blocking issues remain.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@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.

recommend waiting for SDK release before merging

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
Status: 👍 Waiting Merge

Development

Successfully merging this pull request may close these issues.

Docker cache support

4 participants