Skip to content

crane/flatten: preserve image media type when flattening#2267

Merged
Subserial merged 3 commits into
google:mainfrom
alliasgher:fix-flatten-preserve-media-type
Apr 28, 2026
Merged

crane/flatten: preserve image media type when flattening#2267
Subserial merged 3 commits into
google:mainfrom
alliasgher:fix-flatten-preserve-media-type

Conversation

@alliasgher

Copy link
Copy Markdown
Contributor

Fixes #2203. flattenImage always created images from empty.Image (Docker media type). For OCI images, this produced mixed-type indexes. Apply mutate.MediaType to inherit the original image's media type, matching what flattenIndex already does for the index.

@codecov-commenter

codecov-commenter commented Apr 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.82%. Comparing base (38d6e40) to head (0860342).

Files with missing lines Patch % Lines
cmd/crane/cmd/flatten.go 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2267      +/-   ##
==========================================
+ Coverage   53.08%   56.82%   +3.74%     
==========================================
  Files         166      166              
  Lines       11275    11279       +4     
==========================================
+ Hits         5985     6409     +424     
+ Misses       4567     4103     -464     
- Partials      723      767      +44     

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

@Subserial

Copy link
Copy Markdown
Contributor

You have included the changes from adding the Delete scope in this pull request. Please remove them.

Carry the original image's media type (OCI vs Docker) through to the
flattened image so that an OCI image index does not end up referencing
Docker-typed image manifests (and vice versa). Registries and tooling
that assume an index and its children share the same media-type family
reject the mixed result.

Signed-off-by: Ali <alliasgher123@gmail.com>
@alliasgher alliasgher force-pushed the fix-flatten-preserve-media-type branch from 121dd4f to 7d0adee Compare April 20, 2026 20:01
@alliasgher

alliasgher commented Apr 20, 2026

Copy link
Copy Markdown
Contributor Author

Apologies — the branch was mistakenly stacked on top of the Delete-scope branch (#2266). Force-pushed a clean rebuild from main containing only the cmd/crane/cmd/flatten.go change.

@Subserial

Copy link
Copy Markdown
Contributor

Looks good! Could you add some test coverage for the change?

Verifies that flattenImage carries the source image's media type
(OCI or Docker) through to the flattened image. Fails against the
pre-fix code for OCI inputs and passes for Docker.

Signed-off-by: Ali <alliasgher123@gmail.com>
@alliasgher

Copy link
Copy Markdown
Contributor Author

Thanks @Subserial — added TestFlattenImagePreservesMediaType in 231c7a4. Runs against a local httptest registry with both OCI and Docker media types as subtests. Verified it fails against the pre-fix code for the OCI case (flattened image drops to Docker media type) and passes with the fix applied.

@Subserial Subserial merged commit f910f20 into google:main Apr 28, 2026
18 of 19 checks passed
@nishthaGupta

Copy link
Copy Markdown

@Subserial @alliasgher Thanks a lot for this fix, any ETA on the new release?

Subserial pushed a commit to Subserial/go-containerregistry that referenced this pull request May 15, 2026
* crane/flatten: preserve image media type when flattening

Carry the original image's media type (OCI vs Docker) through to the
flattened image so that an OCI image index does not end up referencing
Docker-typed image manifests (and vice versa). Registries and tooling
that assume an index and its children share the same media-type family
reject the mixed result.

Signed-off-by: Ali <alliasgher123@gmail.com>

* crane/flatten: add media type preservation test

Verifies that flattenImage carries the source image's media type
(OCI or Docker) through to the flattened image. Fails against the
pre-fix code for OCI inputs and passes for Docker.

Signed-off-by: Ali <alliasgher123@gmail.com>
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.

crane: flatten creates an index image with mixed OCI and docker mediatypes

4 participants