From 690f97e4665e196a165bad60bd1ed4d5b69eb4ae Mon Sep 17 00:00:00 2001 From: Jin Dong Date: Tue, 9 May 2023 01:42:44 +0000 Subject: [PATCH] Remove OCI MediaTypeArtifactManifest Signed-off-by: Jin Dong --- cmd/go.mod | 6 +-- cmd/go.sum | 12 ++--- cmd/soci/commands/create.go | 12 ----- cmd/soci/commands/internal/spec.go | 32 ----------- go.mod | 6 +-- go.sum | 12 ++--- integration/metrics_test.go | 16 ++---- integration/pull_test.go | 15 ++---- integration/push_test.go | 39 ++++---------- integration/util_soci_test.go | 17 ++---- soci/artifacts.go | 2 +- soci/soci_index.go | 86 +++++++----------------------- soci/soci_index_test.go | 17 +++--- 13 files changed, 68 insertions(+), 204 deletions(-) delete mode 100644 cmd/soci/commands/internal/spec.go diff --git a/cmd/go.mod b/cmd/go.mod index a3aecbc49..a3da434be 100644 --- a/cmd/go.mod +++ b/cmd/go.mod @@ -9,14 +9,14 @@ require ( github.com/docker/cli v23.0.4+incompatible github.com/docker/go-metrics v0.0.1 github.com/opencontainers/go-digest v1.0.0 - github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b + github.com/opencontainers/image-spec v1.1.0-rc3 github.com/pelletier/go-toml v1.9.5 github.com/sirupsen/logrus v1.9.0 github.com/urfave/cli v1.22.12 go.etcd.io/bbolt v1.3.7 golang.org/x/sys v0.7.0 google.golang.org/grpc v1.54.0 - oras.land/oras-go/v2 v2.0.2 + oras.land/oras-go/v2 v2.1.0 ) require ( @@ -94,7 +94,7 @@ require ( golang.org/x/mod v0.10.0 // indirect golang.org/x/net v0.9.0 // indirect golang.org/x/oauth2 v0.5.0 // indirect - golang.org/x/sync v0.1.0 // indirect + golang.org/x/sync v0.2.0 // indirect golang.org/x/term v0.7.0 // indirect golang.org/x/text v0.9.0 // indirect golang.org/x/time v0.3.0 // indirect diff --git a/cmd/go.sum b/cmd/go.sum index 3a92b144c..119e2a113 100644 --- a/cmd/go.sum +++ b/cmd/go.sum @@ -227,8 +227,8 @@ github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAl github.com/onsi/gomega v1.24.2 h1:J/tulyYK6JwBldPViHJReihxxZ+22FHs0piGjQAvoUE= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= -github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b h1:YWuSjZCQAPM8UUBLkYUk1e+rZcvWHJmFb6i6rM44Xs8= -github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b/go.mod h1:3OVijpioIKYWTqjiG0zfF6wvoJ4fAXGbjdZuI2NgsRQ= +github.com/opencontainers/image-spec v1.1.0-rc3 h1:fzg1mXZFj8YdPeNkRXMg+zb88BFV0Ys52cJydRwBkb8= +github.com/opencontainers/image-spec v1.1.0-rc3/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8= github.com/opencontainers/runc v1.1.6 h1:XbhB8IfG/EsnhNvZtNdLB0GBw92GYEFvKlhaJk9jUgA= github.com/opencontainers/runc v1.1.6/go.mod h1:CbUumNnWCuTGFukNXahoo/RFBZvDAgRh/smNYNOhA50= github.com/opencontainers/runtime-spec v1.1.0-rc.2 h1:ucBtEms2tamYYW/SvGpvq9yUN0NEVL6oyLEwDcTSrk8= @@ -339,8 +339,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= +golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -463,8 +463,8 @@ k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 h1:+70TFaan3hfJzs+7VK2o+O k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280/go.mod h1:+Axhij7bCpeqhklhUTe3xmOn6bWxolyZEeyaFpjGtl4= k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5 h1:kmDqav+P+/5e1i9tFfHq1qcF3sOrDp+YEkVDAHu7Jwk= k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -oras.land/oras-go/v2 v2.0.2 h1:3aSQdJ7EUC0ft2e9PjJB9Jzastz5ojPA4LzZ3Q4YbUc= -oras.land/oras-go/v2 v2.0.2/go.mod h1:PWnWc/Kyyg7wUTUsDHshrsJkzuxXzreeMd6NrfdnFSo= +oras.land/oras-go/v2 v2.1.0 h1:1nS8BIeEP6CBVQifwxrsth2bkuD+cYfjp7Hf7smUcS8= +oras.land/oras-go/v2 v2.1.0/go.mod h1:v5ZSAPIMEJYnZjZ6rTGPAyaonH+rCFmbE95IAzCTeGU= sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 h1:iXTIw73aPyC+oRdyqqvVJuloN1p0AC/kzH07hu3NE+k= sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE= diff --git a/cmd/soci/commands/create.go b/cmd/soci/commands/create.go index 0934d195a..e5c57a6ac 100644 --- a/cmd/soci/commands/create.go +++ b/cmd/soci/commands/create.go @@ -18,7 +18,6 @@ package commands import ( "errors" - "fmt" "os" "github.com/awslabs/soci-snapshotter/cmd/soci/commands/internal" @@ -45,7 +44,6 @@ var CreateCommand = cli.Command{ ArgsUsage: "[flags] ", Flags: append( internal.PlatformFlags, - internal.ManifestTypeFlag, cli.Int64Flag{ Name: spanSizeFlag, Usage: "Span size that soci index uses to segment layer data. Default is 4 MiB", @@ -108,16 +106,6 @@ var CreateCommand = cli.Command{ soci.WithBuildToolIdentifier(buildToolIdentifier), } - manifestType := cliContext.String(internal.ManifestTypeFlagName) - - if manifestType != internal.ImageManifestType && manifestType != internal.ArtifactManifestType { - return fmt.Errorf("undefined manifest type: %v. supported manifest types: [%s, %s]", manifestType, internal.ImageManifestType, internal.ArtifactManifestType) - } - - if manifestType == internal.ArtifactManifestType { - builderOpts = append(builderOpts, soci.WithOCIArtifactRegistrySupport) - } - for _, plat := range ps { builder, err := soci.NewIndexBuilder(cs, blobStore, artifactsDb, append(builderOpts, soci.WithPlatform(plat))...) diff --git a/cmd/soci/commands/internal/spec.go b/cmd/soci/commands/internal/spec.go deleted file mode 100644 index b35114f28..000000000 --- a/cmd/soci/commands/internal/spec.go +++ /dev/null @@ -1,32 +0,0 @@ -/* - Copyright The Soci Snapshotter Authors. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package internal - -import "github.com/urfave/cli" - -const ( - ManifestTypeFlagName = "manifest-type" - ImageManifestType = "image" - ArtifactManifestType = "artifact" -) - -var ManifestTypeFlag = cli.StringFlag{ - Name: ManifestTypeFlagName, - Value: ImageManifestType, - Usage: `Generate either an OCI 1.1 artifact manifest or OCI 1.0 image manifest for the SOCI index. - (You should use 'artifact' only if you intend on interacting with a registry that supports OCI 1.1 artifacts)`, -} diff --git a/go.mod b/go.mod index ae09fd6df..e2f34afd9 100644 --- a/go.mod +++ b/go.mod @@ -18,20 +18,20 @@ require ( github.com/moby/sys/mountinfo v0.6.2 github.com/montanaflynn/stats v0.7.0 github.com/opencontainers/go-digest v1.0.0 - github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b + github.com/opencontainers/image-spec v1.1.0-rc3 github.com/prometheus/client_golang v1.15.0 github.com/rs/xid v1.5.0 github.com/sirupsen/logrus v1.9.0 go.etcd.io/bbolt v1.3.7 golang.org/x/crypto v0.8.0 - golang.org/x/sync v0.1.0 + golang.org/x/sync v0.2.0 golang.org/x/sys v0.7.0 golang.org/x/time v0.3.0 google.golang.org/grpc v1.54.0 k8s.io/api v0.26.3 k8s.io/apimachinery v0.26.3 k8s.io/client-go v0.26.3 - oras.land/oras-go/v2 v2.0.2 + oras.land/oras-go/v2 v2.1.0 ) require ( diff --git a/go.sum b/go.sum index 7aa0149fe..5a8f887fc 100644 --- a/go.sum +++ b/go.sum @@ -185,8 +185,8 @@ github.com/onsi/ginkgo/v2 v2.4.0 h1:+Ig9nvqgS5OBSACXNk15PLdp0U9XPYROt9CFzVdFGIs= github.com/onsi/gomega v1.23.0 h1:/oxKu9c2HVap+F3PfKort2Hw5DEU+HGlW8n+tguWsys= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= -github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b h1:YWuSjZCQAPM8UUBLkYUk1e+rZcvWHJmFb6i6rM44Xs8= -github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b/go.mod h1:3OVijpioIKYWTqjiG0zfF6wvoJ4fAXGbjdZuI2NgsRQ= +github.com/opencontainers/image-spec v1.1.0-rc3 h1:fzg1mXZFj8YdPeNkRXMg+zb88BFV0Ys52cJydRwBkb8= +github.com/opencontainers/image-spec v1.1.0-rc3/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8= github.com/opencontainers/runc v1.1.6 h1:XbhB8IfG/EsnhNvZtNdLB0GBw92GYEFvKlhaJk9jUgA= github.com/opencontainers/runc v1.1.6/go.mod h1:CbUumNnWCuTGFukNXahoo/RFBZvDAgRh/smNYNOhA50= github.com/opencontainers/runtime-spec v1.1.0-rc.2 h1:ucBtEms2tamYYW/SvGpvq9yUN0NEVL6oyLEwDcTSrk8= @@ -295,8 +295,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= +golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -404,8 +404,8 @@ k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 h1:+70TFaan3hfJzs+7VK2o+O k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280/go.mod h1:+Axhij7bCpeqhklhUTe3xmOn6bWxolyZEeyaFpjGtl4= k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5 h1:kmDqav+P+/5e1i9tFfHq1qcF3sOrDp+YEkVDAHu7Jwk= k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -oras.land/oras-go/v2 v2.0.2 h1:3aSQdJ7EUC0ft2e9PjJB9Jzastz5ojPA4LzZ3Q4YbUc= -oras.land/oras-go/v2 v2.0.2/go.mod h1:PWnWc/Kyyg7wUTUsDHshrsJkzuxXzreeMd6NrfdnFSo= +oras.land/oras-go/v2 v2.1.0 h1:1nS8BIeEP6CBVQifwxrsth2bkuD+cYfjp7Hf7smUcS8= +oras.land/oras-go/v2 v2.1.0/go.mod h1:v5ZSAPIMEJYnZjZ6rTGPAyaonH+rCFmbE95IAzCTeGU= sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 h1:iXTIw73aPyC+oRdyqqvVJuloN1p0AC/kzH07hu3NE+k= sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE= diff --git a/integration/metrics_test.go b/integration/metrics_test.go index b0724a6ba..68e5f98f7 100644 --- a/integration/metrics_test.go +++ b/integration/metrics_test.go @@ -18,7 +18,6 @@ package integration import ( "bytes" - "encoding/json" "fmt" "io" "math" @@ -350,18 +349,13 @@ func buildIndexByManipulatingZtocData(sh *shell.Shell, indexDigest string, manip ztocDescs = append(ztocDescs, ztocDesc) } - newIndex := soci.Index{ - MediaType: ocispec.MediaTypeArtifactManifest, - ArtifactType: soci.SociIndexArtifactType, - Blobs: ztocDescs, - Subject: &ocispec.Descriptor{ - MediaType: ocispec.MediaTypeArtifactManifest, - Digest: index.Subject.Digest, - Size: index.Subject.Size, - }, + subject := ocispec.Descriptor{ + Digest: index.Subject.Digest, + Size: index.Subject.Size, } - b, err := json.Marshal(newIndex) + newIndex := soci.NewIndex(ztocDescs, &subject, nil) + b, err := soci.MarshalIndex(newIndex) if err != nil { return "", err } diff --git a/integration/pull_test.go b/integration/pull_test.go index 28b39441b..b1ebbe8a5 100644 --- a/integration/pull_test.go +++ b/integration/pull_test.go @@ -448,18 +448,13 @@ func TestPullWithAribtraryBlobInvalidZtocFormat(t *testing.T) { }) } - index := soci.Index{ - MediaType: ocispec.MediaTypeArtifactManifest, - ArtifactType: soci.SociIndexArtifactType, - Blobs: ztocDescs, - Subject: &ocispec.Descriptor{ - MediaType: ocispec.MediaTypeArtifactManifest, - Digest: digest.Digest(imgDigest), - Size: int64(len(imgBytes)), - }, + subject := ocispec.Descriptor{ + Digest: digest.Digest(imgDigest), + Size: int64(len(imgBytes)), } + index := soci.NewIndex(ztocDescs, &subject, nil) - b, err := json.Marshal(index) + b, err := soci.MarshalIndex(index) if err != nil { return nil, nil, err } diff --git a/integration/push_test.go b/integration/push_test.go index da08d2b1d..6d0c78f73 100644 --- a/integration/push_test.go +++ b/integration/push_test.go @@ -125,34 +125,19 @@ func TestPushAlwaysMostRecentlyCreatedIndex(t *testing.T) { func TestLegacyOCI(t *testing.T) { tests := []struct { - name string - registryImage string - supportArtifactRegistry bool - expectError bool + name string + registryImage string + expectError bool }{ { - name: "OCI 1.1 Artifacts succeed with OCI 1.1 registry", - registryImage: oci11RegistryImage, - supportArtifactRegistry: true, - expectError: false, + name: "OCI 1.0 Artifacts succeed with OCI 1.1 registry", + registryImage: oci11RegistryImage, + expectError: false, }, { - name: "OCI 1.0 Artifacts succeed with OCI 1.1 registry", - registryImage: oci11RegistryImage, - supportArtifactRegistry: false, - expectError: false, - }, - { - name: "OCI 1.1 Artifacts fail with OCI 1.0 registry", - registryImage: oci10RegistryImage, - supportArtifactRegistry: true, - expectError: true, - }, - { - name: "OCI 1.0 Artifacts succeed with OCI 1.0 registry", - registryImage: oci10RegistryImage, - supportArtifactRegistry: false, - expectError: false, + name: "OCI 1.0 Artifacts succeed with OCI 1.0 registry", + registryImage: oci10RegistryImage, + expectError: false, }, } @@ -168,11 +153,7 @@ func TestLegacyOCI(t *testing.T) { imageName := ubuntuImage copyImage(sh, dockerhub(imageName), regConfig.mirror(imageName)) - var buildOpts []indexBuildOption - if tc.supportArtifactRegistry { - buildOpts = append(buildOpts, withOCIArtifactRegistrySupport) - } - indexDigest := buildIndex(sh, regConfig.mirror(imageName), buildOpts...) + indexDigest := buildIndex(sh, regConfig.mirror(imageName)) rawJSON := sh.O("soci", "index", "info", indexDigest) var sociIndex soci.Index if err := soci.UnmarshalIndex(rawJSON, &sociIndex); err != nil { diff --git a/integration/util_soci_test.go b/integration/util_soci_test.go index 91eb6582a..5c1b3fb3e 100644 --- a/integration/util_soci_test.go +++ b/integration/util_soci_test.go @@ -55,9 +55,8 @@ const ( // indexBuildConfig represents the values of the CLI flags that should be used // when creating an index with `buildIndex` type indexBuildConfig struct { - spanSize int64 - minLayerSize int64 - supportArtifactRegistry bool + spanSize int64 + minLayerSize int64 } // indexBuildOption is a functional argument to update `indexBuildConfig` @@ -78,11 +77,6 @@ func withMinLayerSize(minLayerSize int64) indexBuildOption { } } -// withOCIArtifactRegistrySupport sets the SOCI index to built as an artifact manifest -func withOCIArtifactRegistrySupport(ibc *indexBuildConfig) { - ibc.supportArtifactRegistry = true -} - // defaultIndexBuildConfig is the default parameters when creating and index with `buildIndex` func defaultIndexBuildConfig() indexBuildConfig { return indexBuildConfig{ @@ -106,9 +100,6 @@ func buildIndex(sh *shell.Shell, src imageInfo, opt ...indexBuildOption) string "--span-size", fmt.Sprintf("%d", indexBuildConfig.spanSize), "--platform", platforms.Format(src.platform), } - if indexBuildConfig.supportArtifactRegistry { - createArgs = append(createArgs, "--manifest-type", "artifact") - } indexDigest := sh. X(append([]string{"nerdctl", "pull", "-q", "--platform", platforms.Format(src.platform)}, opts[0]...)...). @@ -120,8 +111,8 @@ func buildIndex(sh *shell.Shell, src imageInfo, opt ...indexBuildOption) string } func validateSociIndex(sh *shell.Shell, sociIndex soci.Index, imgManifestDigest string, includedLayers map[string]struct{}) error { - if sociIndex.MediaType != ocispec.MediaTypeArtifactManifest && sociIndex.MediaType != ocispec.MediaTypeImageManifest { - return fmt.Errorf("unexpected index media type; expected types: [%v, %v], got: %v", ocispec.MediaTypeArtifactManifest, ocispec.MediaTypeImageManifest, sociIndex.MediaType) + if sociIndex.MediaType != ocispec.MediaTypeImageManifest { + return fmt.Errorf("unexpected index media type; expected types: [%v], got: %v", ocispec.MediaTypeImageManifest, sociIndex.MediaType) } if sociIndex.ArtifactType != soci.SociIndexArtifactType { return fmt.Errorf("unexpected index artifact type; expected = %v, got = %v", soci.SociIndexArtifactType, sociIndex.ArtifactType) diff --git a/soci/artifacts.go b/soci/artifacts.go index 57c82cd93..8200dc83b 100644 --- a/soci/artifacts.go +++ b/soci/artifacts.go @@ -376,7 +376,7 @@ func (db *ArtifactsDb) RemoveArtifactEntryByImageDigest(digest string) error { // Determines whether a bucket represents an index, as opposed to a zTOC func indexBucket(b *bolt.Bucket) bool { mt := string(b.Get(bucketKeyMediaType)) - return mt == ocispec.MediaTypeArtifactManifest || mt == ocispec.MediaTypeImageManifest + return mt == ocispec.MediaTypeImageManifest } // Determines whether a bucket's image digest is the same as digest diff --git a/soci/soci_index.go b/soci/soci_index.go index 914446dcc..e2f5dec0f 100644 --- a/soci/soci_index.go +++ b/soci/soci_index.go @@ -71,8 +71,7 @@ var ( // serializing a SOCI index as an OCI 1.0 Manifest for fallback compatibility. defaultConfigDescriptor = ocispec.Descriptor{ // The Config's media type is set to `SociIndexArtifactType` so that the oras-go - // library can use it to filter artifacts. This would normally be handled using the - // `ArtifactType` filed of an OCI 1.1 Artifact. + // library can use it to filter artifacts. MediaType: SociIndexArtifactType, Digest: emptyJSONObjectDigest, Size: 2, @@ -112,8 +111,7 @@ type IndexDescriptorInfo struct { } // DecodeIndex deserializes a JSON blob in an io.Reader -// into a SOCI index. The blob can be either an OCI 1.1 Artifact -// or an OCI 1.0 Manifest +// into a SOCI index. The blob is an OCI 1.0 Manifest func DecodeIndex(r io.Reader, index *Index) error { b, err := io.ReadAll(r) if err != nil { @@ -123,20 +121,19 @@ func DecodeIndex(r io.Reader, index *Index) error { } // UnmarshalIndex deserializes a JSON blob in a byte array -// into a SOCI index. The blob can be either an OCI 1.1 Artifact -// or an OCI 1.0 Manifest +// into a SOCI index. The blob is an OCI 1.0 Manifest func UnmarshalIndex(b []byte, index *Index) error { - err := json.Unmarshal(b, index) - if err == nil && index.MediaType == ocispec.MediaTypeArtifactManifest { - return nil + if err := json.Unmarshal(b, index); err != nil { + return err } + var manifest ocispec.Manifest - err = json.Unmarshal(b, &manifest) - if err == nil { - fromManifest(manifest, index) - return nil + if err := json.Unmarshal(b, &manifest); err != nil { + return err } - return err + + fromManifest(manifest, index) + return nil } // fromManifest converts an OCI 1.0 Manifest to a SOCI Index @@ -148,23 +145,9 @@ func fromManifest(manifest ocispec.Manifest, index *Index) { index.Annotations = manifest.Annotations } -// Marshal serializes a SOCI index into a JSON blob. -// The JSON blob will be either an OCI 1.1 Artifact or -// an OCI 1.0 Manifest, depending on how the index was created. +// MarshalIndex serializes a SOCI index into a JSON blob. +// The JSON blob is an OCI 1.0 Manifest func MarshalIndex(i *Index) ([]byte, error) { - if i.MediaType == ocispec.MediaTypeArtifactManifest { - return marshalIndexAs11Artifact(i) - } - return marshalIndexAs10Manifest(i) -} - -// marshalIndexAs11Artifact marshals an index as an OCI 1.1 Artifact Manifest -func marshalIndexAs11Artifact(i *Index) ([]byte, error) { - return json.Marshal(i) -} - -// marshalIndexAs10Manifest marshals an index as an OCI 1.0 Image Manifest -func marshalIndexAs10Manifest(i *Index) ([]byte, error) { var manifest ocispec.Manifest manifest.SchemaVersion = 2 manifest.MediaType = ocispec.MediaTypeImageManifest @@ -220,24 +203,11 @@ type buildConfig struct { buildToolIdentifier string artifactsDb *ArtifactsDb platform ocispec.Platform - artifactRegistry bool -} -type indexConfig struct { - artifact bool } // BuildOption specifies a config change to build soci indices. type BuildOption func(c *buildConfig) error -// IndexOption specifies a config change for index creation. -type IndexOption func(c *indexConfig) error - -// WithIndexAsArtifact sets whether to build SOCI index as an artifact manifest instead of an image manifest. -func WithIndexAsArtifact(c *indexConfig) error { - c.artifact = true - return nil -} - // WithSpanSize specifies span size. func WithSpanSize(spanSize int64) BuildOption { return func(c *buildConfig) error { @@ -270,14 +240,7 @@ func WithPlatform(platform ocispec.Platform) BuildOption { } } -// WithOCIArtifactRegistrySupport sets whether to build SOCI index as an artifact manifest instead of an image -// manifest. Artifact manifests are proposed within the OCI 1.1 spec and are only supported by OCI 1.1 compatible registries. -func WithOCIArtifactRegistrySupport(c *buildConfig) error { - c.artifactRegistry = true - return nil -} - -// Speicifies the artifacts database +// WithArtifactsDb speicifies the artifacts database func WithArtifactsDb(db *ArtifactsDb) BuildOption { return func(c *buildConfig) error { c.artifactsDb = db @@ -366,11 +329,8 @@ func (b *IndexBuilder) Build(ctx context.Context, img images.Image) (*IndexWithM Digest: imgManifestDesc.Digest, Size: imgManifestDesc.Size, } - var indexOpts []IndexOption - if b.config.artifactRegistry { - indexOpts = append(indexOpts, WithIndexAsArtifact) - } - index := NewIndex(ztocsDesc, refers, annotations, indexOpts...) + + index := NewIndex(ztocsDesc, refers, annotations) return &IndexWithMetadata{ Index: index, Platform: &b.config.platform, @@ -398,7 +358,7 @@ func (b *IndexBuilder) buildSociLayer(ctx context.Context, desc ocispec.Descript if compressionAlgo == "" { switch desc.MediaType { - case ocispec.MediaTypeImageLayer, ocispec.MediaTypeImageLayerNonDistributable: + case ocispec.MediaTypeImageLayer: // for OCI image layers, empty is returned for an uncompressed layer. compressionAlgo = compression.Uncompressed } @@ -471,21 +431,13 @@ func (b *IndexBuilder) buildSociLayer(ctx context.Context, desc ocispec.Descript } // NewIndex returns a new index. -func NewIndex(blobs []ocispec.Descriptor, subject *ocispec.Descriptor, annotations map[string]string, opts ...IndexOption) *Index { - ic := new(indexConfig) - for _, opt := range opts { - opt(ic) - } - mediaType := ocispec.MediaTypeImageManifest - if ic.artifact { - mediaType = ocispec.MediaTypeArtifactManifest - } +func NewIndex(blobs []ocispec.Descriptor, subject *ocispec.Descriptor, annotations map[string]string) *Index { return &Index{ Blobs: blobs, ArtifactType: SociIndexArtifactType, Annotations: annotations, Subject: subject, - MediaType: mediaType, + MediaType: ocispec.MediaTypeImageManifest, } } diff --git a/soci/soci_index_test.go b/soci/soci_index_test.go index 69842b631..040d533b0 100644 --- a/soci/soci_index_test.go +++ b/soci/soci_index_test.go @@ -97,7 +97,7 @@ func TestBuildSociIndexNotLayer(t *testing.T) { }, { name: "soci index manifest", - mediaType: ocispec.MediaTypeArtifactManifest, + mediaType: ocispec.MediaTypeImageManifest, err: errNotLayerType, }, { @@ -256,7 +256,7 @@ func TestNewIndex(t *testing.T) { for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { - index := NewIndex(tc.blobs, &tc.subject, tc.annotations, WithIndexAsArtifact) + index := NewIndex(tc.blobs, &tc.subject, tc.annotations) if diff := cmp.Diff(index.Blobs, tc.blobs); diff != "" { t.Fatalf("unexpected blobs; diff = %v", diff) @@ -266,8 +266,8 @@ func TestNewIndex(t *testing.T) { t.Fatalf("unexpected artifact type; expected = %s, got = %s", SociIndexArtifactType, index.ArtifactType) } - if index.MediaType != ocispec.MediaTypeArtifactManifest { - t.Fatalf("unexpected media type; expected = %v, got = %v", ocispec.MediaTypeArtifactManifest, index.MediaType) + if index.MediaType != ocispec.MediaTypeImageManifest { + t.Fatalf("unexpected media type; expected = %v, got = %v", ocispec.MediaTypeImageManifest, index.MediaType) } if diff := cmp.Diff(index.Subject, &tc.subject); diff != "" { @@ -304,8 +304,8 @@ func TestDecodeIndex(t *testing.T) { for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { - index := NewIndex(tc.blobs, &tc.subject, tc.annotations, WithIndexAsArtifact) - jsonBytes, err := json.Marshal(index) + index := NewIndex(tc.blobs, &tc.subject, tc.annotations) + jsonBytes, err := MarshalIndex(index) if err != nil { t.Fatalf("cannot convert index to json byte data: %v", err) } @@ -343,11 +343,6 @@ func TestMarshalIndex(t *testing.T) { index *Index ty interface{} }{ - { - name: "successfully roundtrip as Artifact Manifest", - index: NewIndex(blobs, &subject, annotations, WithIndexAsArtifact), - ty: ocispec.Artifact{}, - }, { name: "successfully roundtrip as Image Manifest", index: NewIndex(blobs, &subject, annotations),