From c87f489a7995a06a16c967dcb8090d27b3f1cc15 Mon Sep 17 00:00:00 2001 From: Ramkumar Chinchani <45800463+rchincha@users.noreply.github.com> Date: Tue, 11 Mar 2025 10:38:47 -0700 Subject: [PATCH] fix: allow changing media-type when pushing an image tag (#3022) Fixes #3005 Previously, changing a image's media-type was disallowed. However, "docker buildx" appears to first push an image manifest and then an image index for the same image tag. So, allow this. Signed-off-by: Ramkumar Chinchani --- pkg/api/controller_test.go | 4 ++-- pkg/storage/common/common.go | 10 ++-------- pkg/storage/s3/s3_test.go | 4 ++-- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/pkg/api/controller_test.go b/pkg/api/controller_test.go index a6305359f..752233a08 100644 --- a/pkg/api/controller_test.go +++ b/pkg/api/controller_test.go @@ -10835,13 +10835,13 @@ func TestManifestImageIndex(t *testing.T) { resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex). SetBody(content).Put(baseURL + "/v2/index/manifests/test:1.0") So(err, ShouldBeNil) - So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) + So(resp.StatusCode(), ShouldEqual, http.StatusCreated) // previously an image index, try writing a manifest resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest). SetBody(m1content).Put(baseURL + "/v2/index/manifests/test:index1") So(err, ShouldBeNil) - So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest) + So(resp.StatusCode(), ShouldEqual, http.StatusCreated) }) }) }) diff --git a/pkg/storage/common/common.go b/pkg/storage/common/common.go index 67bd4de92..7992ffedb 100644 --- a/pkg/storage/common/common.go +++ b/pkg/storage/common/common.go @@ -250,15 +250,9 @@ func CheckIfIndexNeedsUpdate(index *ispec.Index, desc *ispec.Descriptor, // changing media-type is disallowed! if manifest.MediaType != desc.MediaType { - err := zerr.ErrBadManifest - log.Error().Err(err). + log.Info(). Str("old mediaType", manifest.MediaType). - Str("new mediaType", desc.MediaType).Msg("cannot change media-type") - - reason := fmt.Sprintf("changing manifest media-type from \"%s\" to \"%s\" is disallowed", - manifest.MediaType, desc.MediaType) - - return false, "", zerr.NewError(err).AddDetail("reason", reason) + Str("new mediaType", desc.MediaType).Msg("media-type changed") } oldDesc := *desc diff --git a/pkg/storage/s3/s3_test.go b/pkg/storage/s3/s3_test.go index c9f75eec0..b602349f1 100644 --- a/pkg/storage/s3/s3_test.go +++ b/pkg/storage/s3/s3_test.go @@ -3410,11 +3410,11 @@ func TestS3ManifestImageIndex(t *testing.T) { So(digest, ShouldNotBeNil) _, _, err = imgStore.PutImageManifest("index", "test:1.0", ispec.MediaTypeImageIndex, content) - So(err, ShouldNotBeNil) + So(err, ShouldBeNil) // previously an image index, try writing a manifest _, _, err = imgStore.PutImageManifest("index", "test:index1", ispec.MediaTypeImageManifest, m1content) - So(err, ShouldNotBeNil) + So(err, ShouldBeNil) }) }) })