Skip to content

Adds local file support to the crane index subcommand #2223

Merged
MeBaranov merged 7 commits intogoogle:mainfrom
edwardthiele:local-index-manifest-support
Mar 11, 2026
Merged

Adds local file support to the crane index subcommand #2223
MeBaranov merged 7 commits intogoogle:mainfrom
edwardthiele:local-index-manifest-support

Conversation

@edwardthiele
Copy link
Copy Markdown
Contributor

This PR adds support to the crane index subcommand to support local OCI layout directories and tarballs. It unifies the handling of local and remote references, allowing users to create, modify, and inspect indices across both local filesystems and remote registries.

Key Features

  • Local OCI Layout Support: crane index append can now target local directories. If the target directory does not exist, it is automatically initialized as a new OCI layout.
  • Mixed Reference Support: Manifests from local tarballs, local OCI layouts, and remote registries can be combined in a single command. For example:
    crane index append -m ./image.tar -m gcr.io/distroless/base -t ./my-layout
  • Index Listing: A new crane index list subcommand allows for inspecting the digests, media types, and platform information of any index (local or remote).
  • Platform Metadata Preservation: The tool automatically extracts platform information from image configurations to ensure the resulting index manifest correctly records os/arch metadata.
  • Nesting & Flattening Control: Supports the --flatten flag to control whether appended indices are expanded into their constituent manifests or added as nested indices.
  • Docker Compatibility: Includes the --docker-empty-base flag for creating indices with Docker-specific media types when required.

Verification

Comprehensive integration tests in cmd/crane/index_test.sh verify:

  • Appending local tarballs/layouts to local indices.
  • Appending remote manifests to local indices.
  • Appending local manifests to remote indices.
  • Nested index creation and platform metadata preservation.
  • Docker media type compatibility.

Note: All tests have been verified against both the local filesystem and a live Artifact Registry repository.

Refactors crane index append to unify the handling of local and remote references.

- Adds support for appending local OCI layouts to other local layouts or remote indices.
- Adds support for appending remote images/indices to local layouts.
- Simplifies the internal logic by removing specific appender implementations in favor of a unified collectAddendums helper.
- Updates isLocalReference to be more robust against false positives.
- Adds comprehensive tests in cmd/crane/index_test.sh covering local-to-local, remote-to-local, and mixed scenarios.
- Fixes loadImage to correctly handle multi-image OCI layouts when used as a source.
- Extracted local and remote append logic into dedicated helpers.
- Added support for preserving platform metadata in local OCI layouts.
- Moved isLocalReference to index.go with improved documentation.
- Expanded index_test.sh with mixed-source, flattening, and Docker media type tests.
- Added comprehensive comments for internal flow control and helpers.
@chizhg
Copy link
Copy Markdown
Member

chizhg commented Mar 4, 2026

@imjasonh @mattmoor could you please help review this PR when you get a chance 😄 ?

@mattmoor
Copy link
Copy Markdown
Collaborator

mattmoor commented Mar 4, 2026

cc @jonjohnsonjr

Copy link
Copy Markdown

@MeBaranov MeBaranov left a comment

Choose a reason for hiding this comment

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

LGTM

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 9, 2026

Codecov Report

❌ Patch coverage is 0% with 216 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.62%. Comparing base (8b3c303) to head (e64b4a4).
⚠️ Report is 68 commits behind head on main.

Files with missing lines Patch % Lines
cmd/crane/cmd/index.go 0.00% 216 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (8b3c303) and HEAD (e64b4a4). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (8b3c303) HEAD (e64b4a4)
2 1
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2223       +/-   ##
===========================================
- Coverage   71.67%   52.62%   -19.05%     
===========================================
  Files         123      164       +41     
  Lines        9935    11091     +1156     
===========================================
- Hits         7121     5837     -1284     
- Misses       2115     4547     +2432     
- Partials      699      707        +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MeBaranov MeBaranov enabled auto-merge (squash) March 11, 2026 20:13
@MeBaranov MeBaranov merged commit 8b2478e into google:main Mar 11, 2026
17 checks passed
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.

5 participants