Skip to content

Commit

Permalink
bump: use new packing function in oras-go (#1070)
Browse files Browse the repository at this point in the history
Signed-off-by: Billy Zha <[email protected]>
  • Loading branch information
qweeah authored Aug 22, 2023
1 parent 30abae3 commit 742b044
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 24 deletions.
8 changes: 3 additions & 5 deletions cmd/oras/internal/option/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,21 @@ import (
const (
ImageSpecV1_1 = "v1.1"
ImageSpecV1_0 = "v1.0"
// TODO: pending on https://github.com/oras-project/oras-go/issues/568
PackManifestTypeImageV1_0 = 0
)

// ImageSpec option struct.
type ImageSpec struct {
flag string
PackType oras.PackManifestType
PackType oras.PackManifestVersion
}

// Parse parses flags into the option.
func (opts *ImageSpec) Parse() error {
switch opts.flag {
case ImageSpecV1_1:
opts.PackType = oras.PackManifestTypeImageV1_1_0_RC4
opts.PackType = oras.PackManifestVersion1_1_RC4
case ImageSpecV1_0:
opts.PackType = PackManifestTypeImageV1_0
opts.PackType = oras.PackManifestVersion1_0
default:
return fmt.Errorf("unknown image specification flag: %q", opts.flag)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/oras/root/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ func runAttach(ctx context.Context, opts attachOptions) error {
}

// prepare push
packOpts := oras.PackOptions{
packOpts := oras.PackManifestOptions{
Subject: &subject,
ManifestAnnotations: annotations[option.AnnotationManifest],
PackImageManifest: true,
Layers: descs,
}
pack := func() (ocispec.Descriptor, error) {
return oras.Pack(ctx, store, opts.artifactType, descs, packOpts)
return oras.PackManifest(ctx, store, oras.PackManifestVersion1_1_RC4, opts.artifactType, packOpts)
}

graphCopyOptions := oras.DefaultCopyGraphOptions
Expand Down
11 changes: 5 additions & 6 deletions cmd/oras/root/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ Example - Push file "hi.txt" into an OCI image layout folder 'layout-dir' with t
return err
}
switch opts.PackType {
case option.PackManifestTypeImageV1_0:
case oras.PackManifestVersion1_0:
if opts.manifestConfigRef != "" && opts.artifactType != "" {
return errors.New("--artifact-type and --config cannot both be provided for 1.0 OCI image")
}
case oras.PackManifestTypeImageV1_1_0_RC4:
case oras.PackManifestVersion1_1_RC4:
if opts.manifestConfigRef == "" && opts.artifactType == "" {
opts.artifactType = oras.MediaTypeUnknownArtifact
}
Expand All @@ -133,11 +133,9 @@ func runPush(ctx context.Context, opts pushOptions) error {
}

// prepare pack
packOpts := oras.PackOptions{
packOpts := oras.PackManifestOptions{
ConfigAnnotations: annotations[option.AnnotationConfig],
ManifestAnnotations: annotations[option.AnnotationManifest],
PackImageManifest: true,
PackManifestType: opts.ImageSpec.PackType,
}
store, err := file.New("")
if err != nil {
Expand All @@ -160,9 +158,10 @@ func runPush(ctx context.Context, opts pushOptions) error {
if err != nil {
return err
}
packOpts.Layers = descs
memoryStore := memory.New()
pack := func() (ocispec.Descriptor, error) {
root, err := oras.Pack(ctx, memoryStore, opts.artifactType, descs, packOpts)
root, err := oras.PackManifest(ctx, memoryStore, opts.PackType, opts.artifactType, packOpts)
if err != nil {
return ocispec.Descriptor{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/spf13/pflag v1.0.5
golang.org/x/term v0.11.0
gopkg.in/yaml.v3 v3.0.1
oras.land/oras-go/v2 v2.2.1-0.20230807082644-bbe92af00542
oras.land/oras-go/v2 v2.2.1-0.20230822062013-e6d40b6ff29f
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
oras.land/oras-go/v2 v2.2.1-0.20230807082644-bbe92af00542 h1:lK/VtXN9+dzSD3EMuCXu0D28OJadBxB9yUpaJBDIABM=
oras.land/oras-go/v2 v2.2.1-0.20230807082644-bbe92af00542/go.mod h1:GeAwLuC4G/JpNwkd+bSZ6SkDMGaaYglt6YK2WvZP7uQ=
oras.land/oras-go/v2 v2.2.1-0.20230822062013-e6d40b6ff29f h1:2Lx/b6oqh6vZST55SxNYNQJSZmOQZDQckdw34tI2bc4=
oras.land/oras-go/v2 v2.2.1-0.20230822062013-e6d40b6ff29f/go.mod h1:GeAwLuC4G/JpNwkd+bSZ6SkDMGaaYglt6YK2WvZP7uQ=
2 changes: 1 addition & 1 deletion test/e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0-rc4
gopkg.in/yaml.v2 v2.4.0
oras.land/oras-go/v2 v2.2.1-0.20230807082644-bbe92af00542
oras.land/oras-go/v2 v2.2.1-0.20230822062013-e6d40b6ff29f
)

require (
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
oras.land/oras-go/v2 v2.2.1-0.20230807082644-bbe92af00542 h1:lK/VtXN9+dzSD3EMuCXu0D28OJadBxB9yUpaJBDIABM=
oras.land/oras-go/v2 v2.2.1-0.20230807082644-bbe92af00542/go.mod h1:GeAwLuC4G/JpNwkd+bSZ6SkDMGaaYglt6YK2WvZP7uQ=
oras.land/oras-go/v2 v2.2.1-0.20230822062013-e6d40b6ff29f h1:2Lx/b6oqh6vZST55SxNYNQJSZmOQZDQckdw34tI2bc4=
oras.land/oras-go/v2 v2.2.1-0.20230822062013-e6d40b6ff29f/go.mod h1:GeAwLuC4G/JpNwkd+bSZ6SkDMGaaYglt6YK2WvZP7uQ=
10 changes: 6 additions & 4 deletions test/e2e/suite/scenario/oci_artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ var _ = Describe("Common OCI artifact users:", Ordered, func() {
WithWorkDir(tempDir).
WithDescription("attach again with manifest exported").Exec()

session = ORAS("discover", subject, "-o", "json", "--artifact-type", "test.artifact2").Exec()
digest = string(Binary("jq", "-r", ".manifests[].digest").WithInput(session.Out).Exec().Out.Contents())
fetched = ORAS("manifest", "fetch", RegistryRef(Host, repo, digest)).MatchKeyWords(foobar.AttachFileMedia).Exec()
MatchFile(filepath.Join(tempDir, pulledManifest), string(fetched.Out.Contents()), DefaultTimeout)
// FIXME: oras distribution doesn't support OCI image with artifactType field
// Below test can be run after https://github.com/oras-project/oras/issues/1071 is done.
// session = ORAS("discover", subject, "-o", "json", "--artifact-type", "test.artifact2").Exec()
// digest = string(Binary("jq", "-r", ".manifests[].digest").WithInput(session.Out).Exec().Out.Contents())
// fetched = ORAS("manifest", "fetch", RegistryRef(Host, repo, digest)).MatchKeyWords(foobar.AttachFileMedia).Exec()
// MatchFile(filepath.Join(tempDir, pulledManifest), string(fetched.Out.Contents()), DefaultTimeout)

ORAS("pull", RegistryRef(Host, repo, string(digest)), "-v", "-o", pullRoot, "--include-subject").
MatchStatus(append(foobar.FileStateKeys, foobar.AttachFileStateKey), true, 4).
Expand Down

0 comments on commit 742b044

Please sign in to comment.