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

bump: use new packing function in oras-go #1070

Merged
merged 3 commits into from
Aug 22, 2023
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: 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
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/Wwwsylvia/oras-go/v2 v2.0.0-20230821122310-d774911dfd59 h1:Pulegq42R9usyOcuwiIaUvsGQbnAe5fE41hXDcOTkV8=
github.com/Wwwsylvia/oras-go/v2 v2.0.0-20230821122310-d774911dfd59/go.mod h1:GeAwLuC4G/JpNwkd+bSZ6SkDMGaaYglt6YK2WvZP7uQ=
TerryHowe marked this conversation as resolved.
Show resolved Hide resolved
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down Expand Up @@ -34,5 +36,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