Skip to content

Commit

Permalink
fix: force config media type when setting platform (#1519)
Browse files Browse the repository at this point in the history
Signed-off-by: Billy Zha <[email protected]>
Co-authored-by: Terry Howe <[email protected]>
  • Loading branch information
qweeah and TerryHowe authored Nov 3, 2024
1 parent 9a83394 commit 8f0f0cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
8 changes: 5 additions & 3 deletions cmd/oras/root/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,13 @@ func runPush(cmd *cobra.Command, opts *pushOptions) error {
if err != nil {
return err
}
mediaType := ocispec.MediaTypeImageConfig
if opts.Flag == option.ImageSpecV1_0 && opts.artifactType != "" {
mediaType = opts.artifactType
return &oerrors.Error{
Err: errors.New(`artifact type cannot be customized for OCI image-spec v1.0 when platform is specified`),
Recommendation: "consider using image spec v1.1 or remove --artifact-type",
}
}
desc := content.NewDescriptorFromBytes(mediaType, blob)
desc := content.NewDescriptorFromBytes(ocispec.MediaTypeImageConfig, blob)
err = store.Push(ctx, desc, bytes.NewReader(blob))
if err != nil {
return err
Expand Down
18 changes: 3 additions & 15 deletions test/e2e/suite/command/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,24 +640,12 @@ var _ = Describe("OCI image layout users:", func() {
}))
})

It("should push files with platform with mediaType as artifactType for v1.0", func() {
It("should fail to customize config mediaType when baking config blob with platform for v1.0", func() {
tempDir := PrepareTempFiles()
ref := LayoutRef(tempDir, tag)
ORAS("push", Flags.Layout, ref, "--image-spec", "v1.0", "--artifact-type", "test/artifact+json", "--artifact-platform", "darwin/arm64", foobar.FileBarName, "-v").
MatchStatus([]match.StateKey{
foobar.PlatformV10ConfigStateKey,
foobar.FileBarStateKey,
}, true, 2).
WithWorkDir(tempDir).Exec()
// validate
fetched := ORAS("manifest", "fetch", Flags.Layout, ref).Exec().Out.Contents()
var manifest ocispec.Manifest
Expect(json.Unmarshal(fetched, &manifest)).ShouldNot(HaveOccurred())
Expect(manifest.Config).Should(Equal(ocispec.Descriptor{
MediaType: "test/artifact+json",
Size: int64(foobar.PlatformV10ConfigSize),
Digest: foobar.PlatformV10ConfigDigest,
}))
ExpectFailure().
Exec()
})

It("should push files with platform with no artifactType for v1.0", func() {
Expand Down

0 comments on commit 8f0f0cd

Please sign in to comment.