Skip to content

Commit

Permalink
support artifact discovery for oras lib
Browse files Browse the repository at this point in the history
Signed-off-by: Shiwei Zhang <[email protected]>
  • Loading branch information
shizhMSFT committed Mar 26, 2021
1 parent 350dae6 commit 55d1abe
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.16
replace (
// WARNING! Do NOT replace these without also replacing their lines in the `require` stanza below.
// These `replace` stanzas are IGNORED when this is imported as a library
github.com/containerd/containerd => github.com/notaryproject/containerd v1.5.0-beta.4.0.20210326071533-6710065b5800
github.com/containerd/containerd => github.com/notaryproject/containerd v1.5.0-beta.4.0.20210326100849-6094ad5d5479
github.com/docker/distribution => github.com/docker/distribution v0.0.0-20191216044856-a8371794149d
github.com/docker/docker => github.com/moby/moby v17.12.0-ce-rc1.0.20200618181300-9dc6525e6118+incompatible
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+
github.com/ncw/swift v1.0.47/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM=
github.com/notaryproject/artifacts v0.0.0-20210325201627-49d06c9f1a07 h1:geJlhRFBwSJXhIv7KMgAXBz1Ie6wsuFeE5vuau3B4AQ=
github.com/notaryproject/artifacts v0.0.0-20210325201627-49d06c9f1a07/go.mod h1:za0DINIIQLPCBn9AhLfPjywgT51o0zll644gbIXiQiQ=
github.com/notaryproject/containerd v1.5.0-beta.4.0.20210326071533-6710065b5800 h1:vMfubXqR1FzRCXJDKgjpuFybJWbNVJKetJTwceky9eI=
github.com/notaryproject/containerd v1.5.0-beta.4.0.20210326071533-6710065b5800/go.mod h1:uvn4m2BuoisfEj5I7GLoCJguWejxwLUlyM0L4XnVWY8=
github.com/notaryproject/containerd v1.5.0-beta.4.0.20210326100849-6094ad5d5479 h1:zan+c1XrL2pyc6RuR+xYJ43SgB2AOXnLH99uAQQrn5w=
github.com/notaryproject/containerd v1.5.0-beta.4.0.20210326100849-6094ad5d5479/go.mod h1:uvn4m2BuoisfEj5I7GLoCJguWejxwLUlyM0L4XnVWY8=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
github.com/onsi/ginkgo v0.0.0-20151202141238-7f8ab55aaf3b/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand Down
29 changes: 29 additions & 0 deletions pkg/oras/discover.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package oras

import (
"context"

"github.com/containerd/containerd/remotes"
artifactspec "github.com/notaryproject/artifacts/specs-go/v2"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)

// Discover discovers artifacts referencing the specified artifact
func Discover(ctx context.Context, resolver remotes.Resolver, ref, artifactType string) (ocispec.Descriptor, []artifactspec.Artifact, error) {
_, desc, err := resolver.Resolve(ctx, ref)
if err != nil {
return ocispec.Descriptor{}, nil, err
}

discoverer, err := resolver.Discoverer(ctx, ref)
if err != nil {
return ocispec.Descriptor{}, nil, err
}

artifacts, err := discoverer.Discover(ctx, desc, artifactType)
if err != nil {
return ocispec.Descriptor{}, nil, err
}

return desc, artifacts, err
}

0 comments on commit 55d1abe

Please sign in to comment.