fix: mismatched mediaType error when push image build with warmed bas… #3231
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #2423 #2713 #2883
Description
given base image
ubuntu:22.04
with oci format:$ crane manifest ubuntu@sha256:0eb0f877e1c869a300c442c41120e778db7161419244ee5cbc6fa5f134e74736 | jq
when warmup cache option is turned on, kaniko build will load base image from tarball using
github.com/google/go-containerregistry/pkg/v1/tarball.ImageFromPath
func and return docker format v1.ImageHowever, kaniko will override the Manifest method, prioritizing the content parsed from the manifest file. This will cause the issue mentioned in #2423 when the base image is in oci format.
After kaniko build with warmup cache done, push image will get error:
If add --oci-layout-path option, the oci-layout will looks like follow which contain different mediaType.
How to fix
option 1)
Important
Depend on google/go-containerregistry#1969
add func
OCIImageFromPath
tojackfan.us.kg/google/go-containerregistry/pkg/v1/tarball
and return v1.Image with OCI mediaType(this PR's choice)option2)
Update cachedImage's func
Manifest
inpkg/cache/cache.go
and return tabball's manifest by default. The result is that when kaniko uses warmup cache, even if the base image is in OCI format, the resulting target image is in Docker format.Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
See the contribution guide for more details.
Reviewer Notes
Release Notes
none