Skip to content

Commit

Permalink
refactor!: merge oras.PackArtifact() into oras.Pack() (#343)
Browse files Browse the repository at this point in the history
1. Removed `oras.PackArtifact()`
2. Refactored `oras.Pack()` to pack artifact manifest or image manifest
3. Removed the dependency of `github.com/oras-project/artifacts-spec`

BREAKING CHANGE: Remove `oras.PackArtifact()`, and change the signature
of `oras.Pack()`
Signed-off-by: Lixia (Sylvia) Lei <lixlei@microsoft.com>
  • Loading branch information
Wwwsylvia authored Oct 18, 2022
1 parent 5416ed6 commit 1969551
Show file tree
Hide file tree
Showing 10 changed files with 368 additions and 380 deletions.
2 changes: 1 addition & 1 deletion content/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ func (s *Store) PackFiles(ctx context.Context, names []string) (ocispec.Descript
layers = append(layers, desc)
}

return oras.Pack(ctx, s, layers, oras.PackOptions{})
return oras.Pack(ctx, s, "", layers, oras.PackOptions{})
}

// saveFile saves content matching the descriptor to the given file.
Expand Down
22 changes: 0 additions & 22 deletions content/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1063,28 +1063,6 @@ func TestStore_PackFiles(t *testing.T) {
if !exists {
t.Errorf("Store.Exists() = %v, want %v", exists, true)
}

// test fetch
rc, err := s.Fetch(ctx, manifestDesc)
if err != nil {
t.Fatal("Store.Fetch() error =", err)
}

var manifest ocispec.Manifest
if err := json.NewDecoder(rc).Decode(&manifest); err != nil {
t.Fatal("failed to decode manifest, err =", err)
}
if err = rc.Close(); err != nil {
t.Error("Store.Fetch().Close() error =", err)
}

exists, err = s.Exists(ctx, manifest.Config)
if err != nil {
t.Fatal("Store.Exists() error =", err)
}
if !exists {
t.Errorf("Store.Exists() = %v, want %v", exists, true)
}
}

func TestStore_File_Push_SameContent(t *testing.T) {
Expand Down
20 changes: 0 additions & 20 deletions content/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"encoding/json"

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

Expand Down Expand Up @@ -88,24 +86,6 @@ func Successors(ctx context.Context, fetcher Fetcher, node ocispec.Descriptor) (
return nil, err
}
return index.Manifests, nil
case artifactspec.MediaTypeArtifactManifest: // TODO: deprecate
content, err := FetchAll(ctx, fetcher, node)
if err != nil {
return nil, err
}

var manifest artifactspec.Manifest
if err := json.Unmarshal(content, &manifest); err != nil {
return nil, err
}
var nodes []ocispec.Descriptor
if manifest.Subject != nil {
nodes = append(nodes, descriptor.ArtifactToOCI(*manifest.Subject))
}
for _, blob := range manifest.Blobs {
nodes = append(nodes, descriptor.ArtifactToOCI(blob))
}
return nodes, nil
case ocispec.MediaTypeArtifactManifest:
content, err := FetchAll(ctx, fetcher, node)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions errdef/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import "errors"
// Common errors used in ORAS
var (
ErrAlreadyExists = errors.New("already exists")
ErrUnsupported = errors.New("unsupported")
ErrInvalidReference = errors.New("invalid reference")
ErrInvalidDigest = errors.New("invalid digest")
ErrNotFound = errors.New("not found")
ErrUnsupportedVersion = errors.New("unsupported version")
ErrInvalidReference = errors.New("invalid reference")
ErrMissingReference = errors.New("missing reference")
ErrNotFound = errors.New("not found")
ErrSizeExceedsLimit = errors.New("size exceeds limit")
ErrUnsupported = errors.New("unsupported")
ErrUnsupportedVersion = errors.New("unsupported version")
)
11 changes: 7 additions & 4 deletions extendedcopy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ func TestExtendedCopy_FullCopy(t *testing.T) {
Size: int64(len(blob)),
})
}
generateManifest := func(config ocispec.Descriptor, layers ...ocispec.Descriptor) {
generateManifest := func(subject *ocispec.Descriptor, config ocispec.Descriptor, layers ...ocispec.Descriptor) {
manifest := ocispec.Manifest{
Config: config,
Layers: layers,
Config: config,
Layers: layers,
Subject: subject,
}
manifestJSON, err := json.Marshal(manifest)
if err != nil {
Expand All @@ -82,11 +83,13 @@ func TestExtendedCopy_FullCopy(t *testing.T) {
appendBlob(ocispec.MediaTypeImageConfig, []byte("config")) // Blob 0
appendBlob(ocispec.MediaTypeImageLayer, []byte("foo")) // Blob 1
appendBlob(ocispec.MediaTypeImageLayer, []byte("bar")) // Blob 2
generateManifest(descs[0], descs[1:3]...) // Blob 3
generateManifest(nil, descs[0], descs[1:3]...) // Blob 3
appendBlob(ocispec.MediaTypeImageLayer, []byte("sig_1")) // Blob 4
generateArtifactManifest(descs[3], descs[4]) // Blob 5
appendBlob(ocispec.MediaTypeImageLayer, []byte("sig_2")) // Blob 6
generateArtifactManifest(descs[5], descs[6]) // Blob 7
appendBlob(ocispec.MediaTypeImageLayer, []byte("baz")) // Blob 8
generateManifest(&descs[3], descs[0], descs[8]) // Blob 9

ctx := context.Background()
for i := range blobs {
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ module oras.land/oras-go/v2
go 1.18

require (
github.com/opencontainers/distribution-spec/specs-go v0.0.0-20220620172159-4ab4752c3b86
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0-rc2
github.com/oras-project/artifacts-spec v1.0.0-rc.2
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
)
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
github.com/opencontainers/distribution-spec/specs-go v0.0.0-20220620172159-4ab4752c3b86 h1:Oumw+lPnO8qNLTY2mrqPJZMoGExLi/0h/DdikoLTXVU=
github.com/opencontainers/distribution-spec/specs-go v0.0.0-20220620172159-4ab4752c3b86/go.mod h1:aA4vdXRS8E1TG7pLZOz85InHi3BiPdErh8IpJN6E0x4=
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 h1:2zx/Stx4Wc5pIPDvIxHXvXtQFW/7XWJGmnM7r3wg034=
github.com/opencontainers/image-spec v1.1.0-rc2/go.mod h1:3OVijpioIKYWTqjiG0zfF6wvoJ4fAXGbjdZuI2NgsRQ=
github.com/oras-project/artifacts-spec v1.0.0-rc.2 h1:9SMCNSxkJEHqWGDiMCuy6TXHgvjgwXGdXZZGXLKQvVE=
github.com/oras-project/artifacts-spec v1.0.0-rc.2/go.mod h1:Xch2aLzSwtkhbFFN6LUzTfLtukYvMMdXJ4oZ8O7BOdc=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
23 changes: 0 additions & 23 deletions internal/descriptor/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package descriptor
import (
"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
artifactspec "github.com/oras-project/artifacts-spec/specs-go/v1"
)

// Descriptor contains the minimun information to describe the disposition of
Expand Down Expand Up @@ -46,25 +45,3 @@ func FromOCI(desc ocispec.Descriptor) Descriptor {
Size: desc.Size,
}
}

// ArtifactToOCI converts artifact descriptor to OCI descriptor.
func ArtifactToOCI(desc artifactspec.Descriptor) ocispec.Descriptor {
return ocispec.Descriptor{
MediaType: desc.MediaType,
Digest: desc.Digest,
Size: desc.Size,
URLs: desc.URLs,
Annotations: desc.Annotations,
}
}

// OCIToArtifact converts OCI descriptor to artifact descriptor.
func OCIToArtifact(desc ocispec.Descriptor) artifactspec.Descriptor {
return artifactspec.Descriptor{
MediaType: desc.MediaType,
Digest: desc.Digest,
Size: desc.Size,
URLs: desc.URLs,
Annotations: desc.Annotations,
}
}
Loading

0 comments on commit 1969551

Please sign in to comment.