Skip to content

Commit c87f489

Browse files
authored
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 <[email protected]>
1 parent 0930e57 commit c87f489

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

pkg/api/controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10835,13 +10835,13 @@ func TestManifestImageIndex(t *testing.T) {
1083510835
resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageIndex).
1083610836
SetBody(content).Put(baseURL + "/v2/index/manifests/test:1.0")
1083710837
So(err, ShouldBeNil)
10838-
So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest)
10838+
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
1083910839

1084010840
// previously an image index, try writing a manifest
1084110841
resp, err = resty.R().SetHeader("Content-Type", ispec.MediaTypeImageManifest).
1084210842
SetBody(m1content).Put(baseURL + "/v2/index/manifests/test:index1")
1084310843
So(err, ShouldBeNil)
10844-
So(resp.StatusCode(), ShouldEqual, http.StatusBadRequest)
10844+
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
1084510845
})
1084610846
})
1084710847
})

pkg/storage/common/common.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,9 @@ func CheckIfIndexNeedsUpdate(index *ispec.Index, desc *ispec.Descriptor,
250250

251251
// changing media-type is disallowed!
252252
if manifest.MediaType != desc.MediaType {
253-
err := zerr.ErrBadManifest
254-
log.Error().Err(err).
253+
log.Info().
255254
Str("old mediaType", manifest.MediaType).
256-
Str("new mediaType", desc.MediaType).Msg("cannot change media-type")
257-
258-
reason := fmt.Sprintf("changing manifest media-type from \"%s\" to \"%s\" is disallowed",
259-
manifest.MediaType, desc.MediaType)
260-
261-
return false, "", zerr.NewError(err).AddDetail("reason", reason)
255+
Str("new mediaType", desc.MediaType).Msg("media-type changed")
262256
}
263257

264258
oldDesc := *desc

pkg/storage/s3/s3_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3410,11 +3410,11 @@ func TestS3ManifestImageIndex(t *testing.T) {
34103410
So(digest, ShouldNotBeNil)
34113411

34123412
_, _, err = imgStore.PutImageManifest("index", "test:1.0", ispec.MediaTypeImageIndex, content)
3413-
So(err, ShouldNotBeNil)
3413+
So(err, ShouldBeNil)
34143414

34153415
// previously an image index, try writing a manifest
34163416
_, _, err = imgStore.PutImageManifest("index", "test:index1", ispec.MediaTypeImageManifest, m1content)
3417-
So(err, ShouldNotBeNil)
3417+
So(err, ShouldBeNil)
34183418
})
34193419
})
34203420
})

0 commit comments

Comments
 (0)