Skip to content

Commit

Permalink
update to latest artifact spec
Browse files Browse the repository at this point in the history
Signed-off-by: Shiwei Zhang <shizh@microsoft.com>
  • Loading branch information
shizhMSFT committed Mar 26, 2021
1 parent f56d806 commit 350dae6
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 32 deletions.
5 changes: 3 additions & 2 deletions cmd/oras/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/content/local"
"github.com/containerd/containerd/errdefs"
artifactspec "github.com/opencontainers/artifacts/specs-go/v2"
artifactspec "github.com/notaryproject/artifacts/specs-go/v2"
digest "github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
Expand Down Expand Up @@ -45,7 +45,8 @@ func (s *cachedStore) Writer(ctx context.Context, opts ...content.WriterOpt) (co
}
}
switch wOpts.Desc.MediaType {
case ocispec.MediaTypeImageManifest, ocispec.MediaTypeImageIndex, artifactspec.MediaTypeArtifact:
case ocispec.MediaTypeImageManifest, ocispec.MediaTypeImageIndex,
artifactspec.MediaTypeArtifactManifest:
return s.cache.Writer(ctx, opts...)
}

Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ 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.20210317114357-17e18de6643b
github.com/containerd/containerd => github.com/notaryproject/containerd v1.5.0-beta.4.0.20210326071533-6710065b5800
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
github.com/opencontainers/artifacts => github.com/aviral26/artifacts v0.0.0-20210301104922-9ca8c5490fcc
)

require (
Expand All @@ -19,7 +18,7 @@ require (
github.com/docker/docker-credential-helpers v0.6.3 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/artifacts v0.0.0-20200916021946-9d10a670db1b
github.com/notaryproject/artifacts v0.0.0-20210325201627-49d06c9f1a07
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.0.1
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hC
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/aviral26/artifacts v0.0.0-20210301104922-9ca8c5490fcc h1:1ok0ayhp1k3OJ8vyVj8Rwv3pFok7xMTR5DLZVXL0mSg=
github.com/aviral26/artifacts v0.0.0-20210301104922-9ca8c5490fcc/go.mod h1:Xr7BjEvr8VVrtyC9LX3q5975UVkEvyaXmb34JsCvSJ0=
github.com/aws/aws-sdk-go v1.15.11/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0=
github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
Expand Down Expand Up @@ -372,8 +370,10 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/ncw/swift v1.0.47/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM=
github.com/notaryproject/containerd v1.5.0-beta.4.0.20210317114357-17e18de6643b h1:cSfrb0RlGLTTH8XB32oTNDzQ0dxbpmAyN+pmste+9qI=
github.com/notaryproject/containerd v1.5.0-beta.4.0.20210317114357-17e18de6643b/go.mod h1:V7n9OftI6ZGSUdcOzlbhPQE1YQo61TJ4wwfubUUNDpI=
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/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
8 changes: 6 additions & 2 deletions pkg/oras/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/remotes"
artifactspec "github.com/opencontainers/artifacts/specs-go/v2"
artifactspec "github.com/notaryproject/artifacts/specs-go/v2"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"golang.org/x/sync/semaphore"
Expand Down Expand Up @@ -85,7 +85,11 @@ func fetchContent(ctx context.Context, fetcher remotes.Fetcher, desc ocispec.Des
func filterHandler(opts *pullOpts, allowedMediaTypes ...string) images.HandlerFunc {
return func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
switch {
case isAllowedMediaType(desc.MediaType, ocispec.MediaTypeImageManifest, ocispec.MediaTypeImageIndex, artifactspec.MediaTypeArtifact):
case isAllowedMediaType(desc.MediaType,
ocispec.MediaTypeImageManifest,
ocispec.MediaTypeImageIndex,
artifactspec.MediaTypeArtifactManifest,
):
return nil, nil
case isAllowedMediaType(desc.MediaType, allowedMediaTypes...):
if opts.filterName(desc) {
Expand Down
12 changes: 8 additions & 4 deletions pkg/oras/pull_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
orascontent "github.com/deislabs/oras/pkg/content"

"github.com/containerd/containerd/images"
artifactspec "github.com/opencontainers/artifacts/specs-go/v2"
artifactspec "github.com/notaryproject/artifacts/specs-go/v2"
"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"golang.org/x/sync/semaphore"
Expand All @@ -30,9 +30,13 @@ type PullOpt func(o *pullOpts) error

func pullOptsDefaults() *pullOpts {
return &pullOpts{
dispatch: images.Dispatch,
filterName: filterName,
cachedMediaTypes: []string{ocispec.MediaTypeImageManifest, ocispec.MediaTypeImageIndex, artifactspec.MediaTypeArtifact},
dispatch: images.Dispatch,
filterName: filterName,
cachedMediaTypes: []string{
ocispec.MediaTypeImageManifest,
ocispec.MediaTypeImageIndex,
artifactspec.MediaTypeArtifactManifest,
},
}
}

Expand Down
33 changes: 19 additions & 14 deletions pkg/oras/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/remotes"
artifact "github.com/deislabs/oras/pkg/artifact"
artifactspec "github.com/opencontainers/artifacts/specs-go/v2"
artifactspec "github.com/notaryproject/artifacts/specs-go/v2"
digest "github.com/opencontainers/go-digest"
specs "github.com/opencontainers/image-spec/specs-go"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
Expand Down Expand Up @@ -65,31 +65,36 @@ func pack(provider content.Provider, descriptors []ocispec.Descriptor, opts *pus
}

// Config
var config ocispec.Descriptor
if opts.config == nil {
var config *ocispec.Descriptor
if opts.config != nil {
config = opts.config
} else if opts.artifact == nil {
configBytes := []byte("{}")
config = ocispec.Descriptor{
config = &ocispec.Descriptor{
MediaType: artifact.UnknownConfigMediaType,
Digest: digest.FromBytes(configBytes),
Size: int64(len(configBytes)),
}
store.Set(config, configBytes)
} else {
config = *opts.config
}
if opts.configAnnotations != nil {
config.Annotations = opts.configAnnotations
store.Set(*config, configBytes)
}
if opts.configMediaType != "" {
config.MediaType = opts.configMediaType
if config != nil {
if opts.configAnnotations != nil {
config.Annotations = opts.configAnnotations
}
if opts.configMediaType != "" {
config.MediaType = opts.configMediaType
}
}

// Manifest
var desc ocispec.Descriptor
var err error
if opts.artifact != nil {
artifact := *opts.artifact
artifact.Config = convertV1DescriptorToV2(config)
if config != nil {
artifactConfig := convertV1DescriptorToV2(*config)
artifact.Config = &artifactConfig
}
artifact.Blobs = convertV1DescriptorsToV2(descriptors)
artifact.Annotations = opts.manifestAnnotations
desc, err = store.SetObject(artifact.MediaType, artifact)
Expand All @@ -98,7 +103,7 @@ func pack(provider content.Provider, descriptors []ocispec.Descriptor, opts *pus
Versioned: specs.Versioned{
SchemaVersion: 2, // historical value. does not pertain to OCI or docker version
},
Config: config,
Config: *config,
Layers: descriptors,
Annotations: opts.manifestAnnotations,
})
Expand Down
6 changes: 3 additions & 3 deletions pkg/oras/push_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
orascontent "github.com/deislabs/oras/pkg/content"

"github.com/containerd/containerd/images"
artifactspecs "github.com/opencontainers/artifacts/specs-go"
artifactspec "github.com/opencontainers/artifacts/specs-go/v2"
artifactspecs "github.com/notaryproject/artifacts/specs-go"
artifactspec "github.com/notaryproject/artifacts/specs-go/v2"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -159,7 +159,7 @@ func AsArtifact(artifactType string, manifests ...ocispec.Descriptor) PushOpt {
Versioned: artifactspecs.Versioned{
SchemaVersion: 2, // historical value. does not pertain to OCI or docker version
},
MediaType: artifactspec.MediaTypeArtifact,
MediaType: artifactspec.MediaTypeArtifactManifest,
ArtifactType: artifactType,
Manifests: convertV1DescriptorsToV2(manifests),
}
Expand Down

0 comments on commit 350dae6

Please sign in to comment.