Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: force config media type when setting platform #1519

Merged
merged 5 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`),
qweeah marked this conversation as resolved.
Show resolved Hide resolved
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
Loading