Skip to content

Commit

Permalink
build: upgrade image-spec to v1.1.0-rc.3 (#496)
Browse files Browse the repository at this point in the history
This PR fixes and only fixes the compiling errors due to the breaking
changes introduced by `image-spec v1.1.0-rc.3` where the artifact
manifest related specs are removed.

Fix #495.
Fix partially #494

---------

Signed-off-by: Shiwei Zhang <[email protected]>
  • Loading branch information
shizhMSFT authored May 4, 2023
1 parent 264f5f2 commit 8aed964
Show file tree
Hide file tree
Showing 21 changed files with 273 additions and 206 deletions.
5 changes: 3 additions & 2 deletions content/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"oras.land/oras-go/v2/content/memory"
"oras.land/oras-go/v2/errdef"
"oras.land/oras-go/v2/internal/descriptor"
"oras.land/oras-go/v2/internal/spec"
)

// storageTracker tracks storage API counts.
Expand Down Expand Up @@ -2287,14 +2288,14 @@ func TestStore_Predecessors(t *testing.T) {
appendBlob(ocispec.MediaTypeImageIndex, indexJSON)
}
generateArtifactManifest := func(subject ocispec.Descriptor, blobs ...ocispec.Descriptor) {
var manifest ocispec.Artifact
var manifest spec.Artifact
manifest.Subject = &subject
manifest.Blobs = append(manifest.Blobs, blobs...)
manifestJSON, err := json.Marshal(manifest)
if err != nil {
t.Fatal(err)
}
appendBlob(ocispec.MediaTypeArtifactManifest, manifestJSON)
appendBlob(spec.MediaTypeArtifactManifest, manifestJSON)
}

appendBlob(ocispec.MediaTypeImageConfig, []byte("config")) // Blob 0
Expand Down
5 changes: 3 additions & 2 deletions content/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras-go/v2/internal/docker"
"oras.land/oras-go/v2/internal/spec"
)

// PredecessorFinder finds out the nodes directly pointing to a given node of a
Expand Down Expand Up @@ -86,13 +87,13 @@ func Successors(ctx context.Context, fetcher Fetcher, node ocispec.Descriptor) (
return nil, err
}
return index.Manifests, nil
case ocispec.MediaTypeArtifactManifest:
case spec.MediaTypeArtifactManifest:
content, err := FetchAll(ctx, fetcher, node)
if err != nil {
return nil, err
}

var manifest ocispec.Artifact
var manifest spec.Artifact
if err := json.Unmarshal(content, &manifest); err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions content/memory/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"oras.land/oras-go/v2/errdef"
"oras.land/oras-go/v2/internal/cas"
"oras.land/oras-go/v2/internal/resolver"
"oras.land/oras-go/v2/internal/spec"
)

func TestStoreInterface(t *testing.T) {
Expand Down Expand Up @@ -330,14 +331,14 @@ func TestStorePredecessors(t *testing.T) {
appendBlob(ocispec.MediaTypeImageIndex, indexJSON)
}
generateArtifactManifest := func(subject ocispec.Descriptor, blobs ...ocispec.Descriptor) {
var manifest ocispec.Artifact
var manifest spec.Artifact
manifest.Subject = &subject
manifest.Blobs = append(manifest.Blobs, blobs...)
manifestJSON, err := json.Marshal(manifest)
if err != nil {
t.Fatal(err)
}
appendBlob(ocispec.MediaTypeArtifactManifest, manifestJSON)
appendBlob(spec.MediaTypeArtifactManifest, manifestJSON)
}

appendBlob(ocispec.MediaTypeImageConfig, []byte("config")) // Blob 0
Expand Down
9 changes: 5 additions & 4 deletions content/oci/oci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"oras.land/oras-go/v2/errdef"
"oras.land/oras-go/v2/internal/cas"
"oras.land/oras-go/v2/internal/descriptor"
"oras.land/oras-go/v2/internal/spec"
"oras.land/oras-go/v2/registry"
)

Expand Down Expand Up @@ -991,14 +992,14 @@ func TestStore_Predecessors(t *testing.T) {
appendBlob(ocispec.MediaTypeImageIndex, indexJSON)
}
generateArtifactManifest := func(subject ocispec.Descriptor, blobs ...ocispec.Descriptor) {
var manifest ocispec.Artifact
var manifest spec.Artifact
manifest.Subject = &subject
manifest.Blobs = append(manifest.Blobs, blobs...)
manifestJSON, err := json.Marshal(manifest)
if err != nil {
t.Fatal(err)
}
appendBlob(ocispec.MediaTypeArtifactManifest, manifestJSON)
appendBlob(spec.MediaTypeArtifactManifest, manifestJSON)
}

appendBlob(ocispec.MediaTypeImageConfig, []byte("config")) // Blob 0
Expand Down Expand Up @@ -1103,14 +1104,14 @@ func TestStore_ExistingStore(t *testing.T) {
}

generateArtifactManifest := func(subject ocispec.Descriptor, blobs ...ocispec.Descriptor) {
var manifest ocispec.Artifact
var manifest spec.Artifact
manifest.Subject = &subject
manifest.Blobs = append(manifest.Blobs, blobs...)
manifestJSON, err := json.Marshal(manifest)
if err != nil {
t.Fatal(err)
}
appendBlob(ocispec.MediaTypeArtifactManifest, manifestJSON)
appendBlob(spec.MediaTypeArtifactManifest, manifestJSON)
}

appendBlob(ocispec.MediaTypeImageConfig, []byte("config")) // Blob 0
Expand Down
13 changes: 7 additions & 6 deletions content/oci/readonlyoci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"oras.land/oras-go/v2/content"
"oras.land/oras-go/v2/content/memory"
"oras.land/oras-go/v2/internal/docker"
"oras.land/oras-go/v2/internal/spec"
"oras.land/oras-go/v2/registry"
)

Expand Down Expand Up @@ -75,8 +76,8 @@ func TestReadOnlyStore(t *testing.T) {
appendBlob(manifest.MediaType, manifestJSON)
}
generateArtifactManifest := func(subject ocispec.Descriptor, blobs ...ocispec.Descriptor) {
manifest := ocispec.Artifact{
MediaType: ocispec.MediaTypeArtifactManifest,
manifest := spec.Artifact{
MediaType: spec.MediaTypeArtifactManifest,
Subject: &subject,
Blobs: blobs,
}
Expand Down Expand Up @@ -265,14 +266,14 @@ func TestReadOnlyStore_DirFS(t *testing.T) {
appendBlob(ocispec.MediaTypeImageIndex, indexJSON)
}
generateArtifactManifest := func(subject ocispec.Descriptor, blobs ...ocispec.Descriptor) {
var manifest ocispec.Artifact
var manifest spec.Artifact
manifest.Subject = &subject
manifest.Blobs = append(manifest.Blobs, blobs...)
manifestJSON, err := json.Marshal(manifest)
if err != nil {
t.Fatal(err)
}
appendBlob(ocispec.MediaTypeArtifactManifest, manifestJSON)
appendBlob(spec.MediaTypeArtifactManifest, manifestJSON)
}

appendBlob(ocispec.MediaTypeImageConfig, []byte("config")) // Blob 0
Expand Down Expand Up @@ -554,8 +555,8 @@ func TestReadOnlyStore_Copy_OCIToMemory(t *testing.T) {
appendBlob(manifest.MediaType, manifestJSON)
}
generateArtifactManifest := func(subject ocispec.Descriptor, blobs ...ocispec.Descriptor) {
manifest := ocispec.Artifact{
MediaType: ocispec.MediaTypeArtifactManifest,
manifest := spec.Artifact{
MediaType: spec.MediaTypeArtifactManifest,
Subject: &subject,
Blobs: blobs,
}
Expand Down
5 changes: 3 additions & 2 deletions copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"oras.land/oras-go/v2/errdef"
"oras.land/oras-go/v2/internal/cas"
"oras.land/oras-go/v2/internal/docker"
"oras.land/oras-go/v2/internal/spec"
)

// storageTracker tracks storage API counts.
Expand Down Expand Up @@ -1459,8 +1460,8 @@ func TestCopyGraph_WithConcurrencyLimit(t *testing.T) {
appendBlob(manifest.MediaType, manifestJSON)
}
generateArtifact := func(subject *ocispec.Descriptor, artifactType string, blobs ...ocispec.Descriptor) {
manifest := ocispec.Artifact{
MediaType: ocispec.MediaTypeArtifactManifest,
manifest := spec.Artifact{
MediaType: spec.MediaTypeArtifactManifest,
Subject: subject,
Blobs: blobs,
ArtifactType: artifactType,
Expand Down
17 changes: 9 additions & 8 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,26 @@ import (
"oras.land/oras-go/v2"
"oras.land/oras-go/v2/content/memory"
"oras.land/oras-go/v2/content/oci"
"oras.land/oras-go/v2/internal/spec"
"oras.land/oras-go/v2/registry/remote"
)

var exampleMemoryStore oras.Target
var remoteHost string
var (
exampleManifest, _ = json.Marshal(ocispec.Artifact{
MediaType: ocispec.MediaTypeArtifactManifest,
exampleManifest, _ = json.Marshal(spec.Artifact{
MediaType: spec.MediaTypeArtifactManifest,
ArtifactType: "example/content"})
exampleManifestDescriptor = ocispec.Descriptor{
MediaType: ocispec.MediaTypeArtifactManifest,
MediaType: spec.MediaTypeArtifactManifest,
Digest: digest.Digest(digest.FromBytes(exampleManifest)),
Size: int64(len(exampleManifest))}
exampleSignatureManifest, _ = json.Marshal(ocispec.Artifact{
MediaType: ocispec.MediaTypeArtifactManifest,
exampleSignatureManifest, _ = json.Marshal(spec.Artifact{
MediaType: spec.MediaTypeArtifactManifest,
ArtifactType: "example/signature",
Subject: &exampleManifestDescriptor})
exampleSignatureManifestDescriptor = ocispec.Descriptor{
MediaType: ocispec.MediaTypeArtifactManifest,
MediaType: spec.MediaTypeArtifactManifest,
Digest: digest.FromBytes(exampleSignatureManifest),
Size: int64(len(exampleSignatureManifest))}
)
Expand Down Expand Up @@ -117,15 +118,15 @@ func TestMain(m *testing.M) {
case strings.Contains(p, "/blobs/uploads/"+exampleUploadUUid) && m == "GET":
w.WriteHeader(http.StatusCreated)
case strings.Contains(p, "/manifests/"+string(exampleSignatureManifestDescriptor.Digest)):
w.Header().Set("Content-Type", ocispec.MediaTypeArtifactManifest)
w.Header().Set("Content-Type", spec.MediaTypeArtifactManifest)
w.Header().Set("Docker-Content-Digest", string(exampleSignatureManifestDescriptor.Digest))
w.Header().Set("Content-Length", strconv.Itoa(len(exampleSignatureManifest)))
w.Write(exampleSignatureManifest)
case strings.Contains(p, "/manifests/latest") && m == "PUT":
w.WriteHeader(http.StatusCreated)
case strings.Contains(p, "/manifests/"+string(exampleManifestDescriptor.Digest)),
strings.Contains(p, "/manifests/latest") && m == "HEAD":
w.Header().Set("Content-Type", ocispec.MediaTypeArtifactManifest)
w.Header().Set("Content-Type", spec.MediaTypeArtifactManifest)
w.Header().Set("Docker-Content-Digest", string(exampleManifestDescriptor.Digest))
w.Header().Set("Content-Length", strconv.Itoa(len(exampleManifest)))
if m == "GET" {
Expand Down
9 changes: 5 additions & 4 deletions extendedcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"oras.land/oras-go/v2/internal/copyutil"
"oras.land/oras-go/v2/internal/descriptor"
"oras.land/oras-go/v2/internal/docker"
"oras.land/oras-go/v2/internal/spec"
"oras.land/oras-go/v2/internal/status"
"oras.land/oras-go/v2/internal/syncutil"
"oras.land/oras-go/v2/registry"
Expand Down Expand Up @@ -255,7 +256,7 @@ func (opts *ExtendedCopyGraphOptions) FilterAnnotation(key string, regex *regexp
switch p.MediaType {
case docker.MediaTypeManifest, ocispec.MediaTypeImageManifest,
docker.MediaTypeManifestList, ocispec.MediaTypeImageIndex,
ocispec.MediaTypeArtifactManifest:
spec.MediaTypeArtifactManifest:
annotations, err := fetchAnnotations(ctx, src, p)
if err != nil {
return nil, err
Expand Down Expand Up @@ -345,7 +346,7 @@ func (opts *ExtendedCopyGraphOptions) FilterArtifactType(regex *regexp.Regexp) {
// if the artifact type is not present in the descriptors,
// fetch it from the manifest content.
switch p.MediaType {
case ocispec.MediaTypeArtifactManifest, ocispec.MediaTypeImageManifest:
case spec.MediaTypeArtifactManifest, ocispec.MediaTypeImageManifest:
artifactType, err := fetchArtifactType(ctx, src, p)
if err != nil {
return nil, err
Expand All @@ -370,8 +371,8 @@ func fetchArtifactType(ctx context.Context, src content.ReadOnlyGraphStorage, de
defer rc.Close()

switch desc.MediaType {
case ocispec.MediaTypeArtifactManifest:
var manifest ocispec.Artifact
case spec.MediaTypeArtifactManifest:
var manifest spec.Artifact
if err := json.NewDecoder(rc).Decode(&manifest); err != nil {
return "", err
}
Expand Down
Loading

0 comments on commit 8aed964

Please sign in to comment.