Skip to content

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

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

feat(cli): add --cache-from and --cache-to options to cartesi build#485
endersonmaia wants to merge 4 commits into
prerelease/v2-alphafrom
feature/add-cache-options-to-build

Conversation

@endersonmaia
Copy link
Copy Markdown
Contributor

@endersonmaia endersonmaia commented Jun 3, 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

/close #483

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>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 3, 2026

🦋 Changeset detected

Latest commit: 37f8bd9

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
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 3, 2026

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
break;
}
case "docker": {
const effectiveDrive = {
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.

this code block is a little ugly

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

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Docker cache support

2 participants