Skip to content

Commit 86176e8

Browse files
authored
build: bump github.com/opencontainers/image-spec to v1.1.0-rc5 (#615)
1. Bump `github.com/opencontainers/image-spec` to `v1.1.0-rc5` in go mod 2. Replace "index.json" and "blobs" with corresponding constants in the spec 3. Fix testable examples that broke by the spec change - `MediaType` became a required field in `Descriptor` Resolve: #599 Signed-off-by: Lixia (Sylvia) Lei <lixlei@microsoft.com>
1 parent 6dfbe52 commit 86176e8

10 files changed

+38
-40
lines changed

content/oci/oci.go

+2-12
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,6 @@ import (
3838
"oras.land/oras-go/v2/internal/resolver"
3939
)
4040

41-
// ociImageIndexFile is the file name of the index
42-
// from the OCI Image Layout Specification.
43-
// Reference: https://github.com/opencontainers/image-spec/blob/v1.1.0-rc4/image-layout.md#indexjson-file
44-
const ociImageIndexFile = "index.json"
45-
46-
// ociBlobsDir is the name of the blobs directory
47-
// from the OCI Image Layout Specification.
48-
// Reference: https://github.com/opencontainers/image-spec/blob/v1.1.0-rc4/image-layout.md#content
49-
const ociBlobsDir = "blobs"
50-
5141
// Store implements `oras.Target`, and represents a content store
5242
// based on file system with the OCI-Image layout.
5343
// Reference: https://github.com/opencontainers/image-spec/blob/v1.1.0-rc4/image-layout.md
@@ -89,13 +79,13 @@ func NewWithContext(ctx context.Context, root string) (*Store, error) {
8979
store := &Store{
9080
AutoSaveIndex: true,
9181
root: rootAbs,
92-
indexPath: filepath.Join(rootAbs, ociImageIndexFile),
82+
indexPath: filepath.Join(rootAbs, ocispec.ImageIndexFile),
9383
storage: storage,
9484
tagResolver: resolver.NewMemory(),
9585
graph: graph.NewMemory(),
9686
}
9787

98-
if err := ensureDir(filepath.Join(rootAbs, ociBlobsDir)); err != nil {
88+
if err := ensureDir(filepath.Join(rootAbs, ocispec.ImageBlobsDir)); err != nil {
9989
return nil, err
10090
}
10191
if err := store.ensureOCILayoutFile(); err != nil {

content/oci/oci_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func TestStore_Success(t *testing.T) {
109109
}
110110

111111
// validate index.json
112-
indexFilePath := filepath.Join(tempDir, ociImageIndexFile)
112+
indexFilePath := filepath.Join(tempDir, "index.json")
113113
indexFile, err := os.Open(indexFilePath)
114114
if err != nil {
115115
t.Errorf("error opening layout file, error = %v", err)
@@ -361,7 +361,7 @@ func TestStore_NotExistingRoot(t *testing.T) {
361361
}
362362

363363
// validate index.json
364-
indexFilePath := filepath.Join(root, ociImageIndexFile)
364+
indexFilePath := filepath.Join(root, "index.json")
365365
indexFile, err := os.Open(indexFilePath)
366366
if err != nil {
367367
t.Errorf("error opening layout file, error = %v", err)
@@ -930,7 +930,7 @@ func TestStore_TagByDigest(t *testing.T) {
930930
func TestStore_BadIndex(t *testing.T) {
931931
tempDir := t.TempDir()
932932
content := []byte("whatever")
933-
path := filepath.Join(tempDir, ociImageIndexFile)
933+
path := filepath.Join(tempDir, "index.json")
934934
os.WriteFile(path, content, 0666)
935935

936936
_, err := New(tempDir)

content/oci/readonlyoci.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func validateOCILayout(layout *ocispec.ImageLayout) error {
154154

155155
// loadIndexFile reads index.json from s.fsys.
156156
func (s *ReadOnlyStore) loadIndexFile(ctx context.Context) error {
157-
indexFile, err := s.fsys.Open(ociImageIndexFile)
157+
indexFile, err := s.fsys.Open(ocispec.ImageIndexFile)
158158
if err != nil {
159159
return fmt.Errorf("failed to open index file: %w", err)
160160
}

content/oci/readonlyoci_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ func TestReadOnlyStore(t *testing.T) {
123123
// build fs
124124
fsys := fstest.MapFS{}
125125
for i, desc := range descs {
126-
path := strings.Join([]string{ociBlobsDir, desc.Digest.Algorithm().String(), desc.Digest.Encoded()}, "/")
126+
path := strings.Join([]string{"blobs", desc.Digest.Algorithm().String(), desc.Digest.Encoded()}, "/")
127127
fsys[path] = &fstest.MapFile{Data: blobs[i]}
128128
}
129129
fsys[ocispec.ImageLayoutFile] = &fstest.MapFile{Data: layoutJSON}
130-
fsys[ociImageIndexFile] = &fstest.MapFile{Data: indexJSON}
130+
fsys["index.json"] = &fstest.MapFile{Data: indexJSON}
131131

132132
// test read-only store
133133
ctx := context.Background()
@@ -507,7 +507,7 @@ func TestReadOnlyStore_TarFS(t *testing.T) {
507507
func TestReadOnlyStore_BadIndex(t *testing.T) {
508508
content := []byte("whatever")
509509
fsys := fstest.MapFS{
510-
ociImageIndexFile: &fstest.MapFile{Data: content},
510+
"index.json": &fstest.MapFile{Data: content},
511511
}
512512

513513
ctx := context.Background()
@@ -603,11 +603,11 @@ func TestReadOnlyStore_Copy_OCIToMemory(t *testing.T) {
603603
// build fs
604604
fsys := fstest.MapFS{}
605605
for i, desc := range descs {
606-
path := strings.Join([]string{ociBlobsDir, desc.Digest.Algorithm().String(), desc.Digest.Encoded()}, "/")
606+
path := strings.Join([]string{"blobs", desc.Digest.Algorithm().String(), desc.Digest.Encoded()}, "/")
607607
fsys[path] = &fstest.MapFile{Data: blobs[i]}
608608
}
609609
fsys[ocispec.ImageLayoutFile] = &fstest.MapFile{Data: layoutJSON}
610-
fsys[ociImageIndexFile] = &fstest.MapFile{Data: indexJSON}
610+
fsys["index.json"] = &fstest.MapFile{Data: indexJSON}
611611

612612
// test read-only store
613613
ctx := context.Background()
@@ -717,11 +717,11 @@ func TestReadOnlyStore_Tags(t *testing.T) {
717717
// build fs
718718
fsys := fstest.MapFS{}
719719
for i, desc := range descs {
720-
path := strings.Join([]string{ociBlobsDir, desc.Digest.Algorithm().String(), desc.Digest.Encoded()}, "/")
720+
path := strings.Join([]string{"blobs", desc.Digest.Algorithm().String(), desc.Digest.Encoded()}, "/")
721721
fsys[path] = &fstest.MapFile{Data: blobs[i]}
722722
}
723723
fsys[ocispec.ImageLayoutFile] = &fstest.MapFile{Data: layoutJSON}
724-
fsys[ociImageIndexFile] = &fstest.MapFile{Data: indexJSON}
724+
fsys["index.json"] = &fstest.MapFile{Data: indexJSON}
725725

726726
// test read-only store
727727
ctx := context.Background()

content/oci/readonlystorage.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,5 @@ func blobPath(dgst digest.Digest) (string, error) {
9595
return "", fmt.Errorf("cannot calculate blob path from invalid digest %s: %w: %v",
9696
dgst.String(), errdef.ErrInvalidDigest, err)
9797
}
98-
return path.Join(ociBlobsDir, dgst.Algorithm().String(), dgst.Encoded()), nil
98+
return path.Join(ocispec.ImageBlobsDir, dgst.Algorithm().String(), dgst.Encoded()), nil
9999
}

content/oci/readonlystorage_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestReadOnlyStorage_Exists(t *testing.T) {
3838
dgst := digest.FromBytes(blob)
3939
desc := content.NewDescriptorFromBytes("", blob)
4040
fsys := fstest.MapFS{
41-
strings.Join([]string{ociBlobsDir, dgst.Algorithm().String(), dgst.Encoded()}, "/"): {},
41+
strings.Join([]string{"blobs", dgst.Algorithm().String(), dgst.Encoded()}, "/"): {},
4242
}
4343
s := NewStorageFromFS(fsys)
4444
ctx := context.Background()
@@ -76,7 +76,7 @@ func TestReadOnlyStorage_Fetch(t *testing.T) {
7676
dgst := digest.FromBytes(blob)
7777
desc := content.NewDescriptorFromBytes("", blob)
7878
fsys := fstest.MapFS{
79-
strings.Join([]string{ociBlobsDir, dgst.Algorithm().String(), dgst.Encoded()}, "/"): {
79+
strings.Join([]string{"blobs", dgst.Algorithm().String(), dgst.Encoded()}, "/"): {
8080
Data: blob,
8181
},
8282
}
@@ -123,7 +123,7 @@ func TestReadOnlyStorage_DirFS(t *testing.T) {
123123
dgst := digest.FromBytes(blob)
124124
desc := content.NewDescriptorFromBytes("test", blob)
125125
// write blob to disk
126-
path := filepath.Join(tempDir, ociBlobsDir, dgst.Algorithm().String(), dgst.Encoded())
126+
path := filepath.Join(tempDir, "blobs", dgst.Algorithm().String(), dgst.Encoded())
127127
if err := os.MkdirAll(filepath.Dir(path), 0777); err != nil {
128128
t.Fatal("error calling Mkdir(), error =", err)
129129
}

content/oci/storage_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func TestStorage_Fetch_ExistingBlobs(t *testing.T) {
289289
}
290290

291291
tempDir := t.TempDir()
292-
path := filepath.Join(tempDir, ociBlobsDir, dgst.Algorithm().String(), dgst.Encoded())
292+
path := filepath.Join(tempDir, "blobs", dgst.Algorithm().String(), dgst.Encoded())
293293
if err := os.MkdirAll(filepath.Dir(path), 0777); err != nil {
294294
t.Fatal("error calling Mkdir(), error =", err)
295295
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ go 1.20
44

55
require (
66
github.com/opencontainers/go-digest v1.0.0
7-
github.com/opencontainers/image-spec v1.1.0-rc4
7+
github.com/opencontainers/image-spec v1.1.0-rc5
88
golang.org/x/sync v0.4.0
99
)

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
22
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
3-
github.com/opencontainers/image-spec v1.1.0-rc4 h1:oOxKUJWnFC4YGHCCMNql1x4YaDfYBTS5Y4x/Cgeo1E0=
4-
github.com/opencontainers/image-spec v1.1.0-rc4/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8=
3+
github.com/opencontainers/image-spec v1.1.0-rc5 h1:Ygwkfw9bpDvs+c9E34SdgGOj41dX/cbdlwvlWt0pnFI=
4+
github.com/opencontainers/image-spec v1.1.0-rc5/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8=
55
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
66
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=

registry/remote/example_test.go

+17-9
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,20 @@ import (
4040
)
4141

4242
const (
43-
exampleRepositoryName = "example"
44-
exampleTag = "latest"
45-
exampleConfig = "Example config content"
46-
exampleLayer = "Example layer content"
47-
exampleUploadUUid = "0bc84d80-837c-41d9-824e-1907463c53b3"
48-
ManifestDigest = "sha256:0b696106ecd0654e031f19e0a8cbd1aee4ad457d7c9cea881f07b12a930cd307"
49-
ReferenceManifestDigest = "sha256:6983f495f7ee70d43e571657ae8b39ca3d3ca1b0e77270fd4fbddfb19832a1cf"
43+
_ = ExampleUnplayable
44+
exampleRepositoryName = "example"
45+
exampleTag = "latest"
46+
exampleConfig = "Example config content"
47+
exampleLayer = "Example layer content"
48+
exampleUploadUUid = "0bc84d80-837c-41d9-824e-1907463c53b3"
49+
// For ExampleRepository_Push_artifactReferenceManifest:
50+
ManifestDigest = "sha256:a3f9d449466b9b7194c3a76ca4890d792e11eb4e62e59aa8b4c3cce0a56f129d"
51+
ReferenceManifestDigest = "sha256:2d30397701742b04550891851529abe6b071e4fae920a91897d34612662a3bf6"
52+
// For Example_pushAndIgnoreReferrersIndexError:
5053
referrersAPIUnavailableRepositoryName = "no-referrers-api"
51-
referrerDigest = "sha256:21c623eb8ccd273f2702efd74a0abb455dd06a99987f413c2114fb00961ebfe7"
54+
referrerDigest = "sha256:4caba1e18385eb152bd92e9fee1dc01e47c436e594123b3c2833acfcad9883e2"
5255
referrersTag = "sha256-c824a9aa7d2e3471306648c6d4baa1abbcb97ff0276181ab4722ca27127cdba0"
5356
referrerIndexDigest = "sha256:7baac5147dd58d56fdbaad5a888fa919235a3a90cb71aaa8b56ee5d19f4cd838"
54-
_ = ExampleUnplayable
5557
)
5658

5759
var (
@@ -107,8 +109,10 @@ var (
107109
Size: int64(len(exampleManifestWithBlobs))}
108110
subjectDescriptor = content.NewDescriptorFromBytes(ocispec.MediaTypeImageManifest, []byte(`{"layers":[]}`))
109111
referrerManifestContent, _ = json.Marshal(ocispec.Manifest{
112+
Versioned: specs.Versioned{SchemaVersion: 2},
110113
MediaType: ocispec.MediaTypeImageManifest,
111114
Subject: &subjectDescriptor,
115+
Config: ocispec.DescriptorEmptyJSON,
112116
})
113117
referrerDescriptor = content.NewDescriptorFromBytes(ocispec.MediaTypeImageManifest, referrerManifestContent)
114118
referrerIndex, _ = json.Marshal(ocispec.Index{
@@ -304,7 +308,11 @@ func ExampleRepository_Push_artifactReferenceManifest() {
304308

305309
// 1. assemble the referenced artifact manifest
306310
manifest := ocispec.Manifest{
311+
Versioned: specs.Versioned{
312+
SchemaVersion: 2, // historical value. does not pertain to OCI or docker version
313+
},
307314
MediaType: ocispec.MediaTypeImageManifest,
315+
Config: content.NewDescriptorFromBytes(ocispec.MediaTypeImageConfig, []byte("config bytes")),
308316
}
309317
manifestContent, err := json.Marshal(manifest)
310318
if err != nil {

0 commit comments

Comments
 (0)