Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaoxuan Wang <[email protected]>
  • Loading branch information
wangxiaoxuan273 committed Apr 2, 2024
1 parent fe9bab3 commit 67eb1e3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 2 additions & 3 deletions cmd/oras/internal/option/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ func (is *ImageSpec) String() string {
// ApplyFlags applies flags to a command flag set.
func (is *ImageSpec) ApplyFlags(fs *pflag.FlagSet) {
// default to auto
defaultFlag := ImageSpecAuto
is.PackVersion = oras.PackManifestVersion1_1
is.Flag = defaultFlag
fs.Var(is, "image-spec", fmt.Sprintf(`[Experimental] specify manifest type for building artifact. Options: %s (default %q)`, is.Options(), defaultFlag))
is.Flag = ImageSpecAuto
fs.Var(is, "image-spec", fmt.Sprintf(`[Experimental] specify manifest type for building artifact. Options: %s (default %q)`, is.Options(), ImageSpecAuto))
}

// DistributionSpec option struct which implements pflag.Value interface.
Expand Down
7 changes: 6 additions & 1 deletion cmd/oras/root/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,16 @@ Example - Push file "hi.txt" into an OCI image layout folder 'layout-dir' with t
}

if opts.manifestConfigRef != "" && opts.artifactType == "" {
// Here packs an artifact that is not compliant to OCI artifact guidance.
// Reference: https://github.com/opencontainers/image-spec/blob/e7f7c0ca69b21688c3cea7c87a04e4503e6099e2/manifest.md?plain=1#L170
switch opts.Flag {
case option.ImageSpecAuto:
opts.PackVersion = oras.PackManifestVersion1_0
case option.ImageSpecV1_1:
return errors.New("--artifact-type must be set for 1.1 OCI image")
return &oerrors.Error{
Err: errors.New(`artifact type missing for OCI v1.1 artifacts`),
Recommendation: "set an artifact type via `--artifact-type` or use v1.0 image spec",
}
}
}

Expand Down
7 changes: 4 additions & 3 deletions test/e2e/suite/command/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ var _ = Describe("ORAS beginners:", func() {
})

It("should fail if image spec v1.1 is used, with --config and without --artifactType", func() {
testRepo := attachTestRepo("test-repo")
testRepo := pushTestRepo("v1-1/no-artifact-type")
subjectRef := RegistryRef(ZOTHost, testRepo, foobar.Tag)
imageSpecFlag := "v1.1"
ORAS("push", subjectRef, "--config", foobar.FileConfigName, Flags.ImageSpec, imageSpecFlag).
ExpectFailure().
MatchErrKeyWords("--artifact-type must be set for 1.1 OCI image").
MatchErrKeyWords("artifact type missing for OCI v1.1 artifacts").
Exec()
})
})
Expand Down Expand Up @@ -244,7 +244,7 @@ var _ = Describe("Remote registry users:", func() {
})

It("should pack with image spec v1.0 when --config is used, --artifact-type is not used, and --image-spec set to auto", func() {
repo := pushTestRepo("my/test/repo")
repo := pushTestRepo("config/without/artifact/type")
configType := "my/config/type"
tempDir := PrepareTempFiles()

Expand All @@ -263,6 +263,7 @@ var _ = Describe("Remote registry users:", func() {
Size: int64(foobar.FileConfigSize),
Digest: foobar.FileConfigDigest,
}))
Expect(manifest.ArtifactType).Should(Equal(""))
})

It("should push files with customized config file and mediatype", func() {
Expand Down

0 comments on commit 67eb1e3

Please sign in to comment.