Skip to content

Commit

Permalink
artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn committed Feb 17, 2024
1 parent 5927d21 commit 9d74288
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
23 changes: 23 additions & 0 deletions pkg/v1/remote/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,33 @@ package remote

import (
"github.com/google/go-containerregistry/pkg/name"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/partial"
"github.com/google/go-containerregistry/pkg/v1/types"
)

type descriptorArtifact struct {
desc Descriptor
}

func (d *descriptorArtifact) Digest() (v1.Hash, error) {
return d.desc.Digest, nil
}

func (d *descriptorArtifact) MediaType() (types.MediaType, error) {
return d.desc.MediaType, nil
}

func (d *descriptorArtifact) RawManifest() ([]byte, error) {
return d.desc.RawManifest()
}

func (d *descriptorArtifact) Size() (int64, error) {
return d.desc.Size, nil
}

var _ partial.Artifact = (*descriptorArtifact)(nil)

// Get returns a partial.Artifact for the given reference.
//
// See Head if you don't need the response body.
Expand Down
6 changes: 5 additions & 1 deletion pkg/v1/remote/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ type Descriptor struct {
platform v1.Platform
}

func (d *Descriptor) ToDescriptor() v1.Descriptor {
func (d *Descriptor) ToArtifact() partial.Artifact {
return &descriptorArtifact{desc: *d}
}

func (d *Descriptor) toDesc() v1.Descriptor {
return d.Descriptor
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/v1/remote/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"bytes"
"context"
"errors"
"fmt"
"io"
"net/http"
"net/url"
Expand Down Expand Up @@ -70,6 +71,7 @@ func Image(ref name.Reference, options ...Option) (v1.Image, error) {
if img, ok := desc.(v1.Image); ok {
return img, nil
}
fmt.Println(desc.MediaType())
return nil, errors.New("is not a image")
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/v1/remote/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/google/go-cmp/cmp"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/partial"
"github.com/google/go-containerregistry/pkg/v1/random"
"github.com/google/go-containerregistry/pkg/v1/types"
)
Expand Down Expand Up @@ -53,7 +54,7 @@ func mustChild(t *testing.T, idx v1.ImageIndex, h v1.Hash) v1.Image {
return img
}

func mustMediaType(t *testing.T, tag withMediaType) types.MediaType {
func mustMediaType(t *testing.T, tag partial.WithMediaType) types.MediaType {
mt, err := tag.MediaType()
if err != nil {
t.Fatalf("MediaType() = %v", err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/v1/remote/puller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package remote

import (
"context"
"errors"
"sync"

"github.com/google/go-containerregistry/pkg/name"
Expand Down Expand Up @@ -144,7 +143,8 @@ func (p *puller) artifact(ctx context.Context, ref name.Reference, acceptable []
} else if desc.MediaType.IsSchema1() {
return desc.Schema1()
}
return nil, errors.New("TODO: ???")
// TODO: is this the right thing?
return desc.ToArtifact(), nil
}

// Layer is like remote.Layer, but avoids re-authenticating when possible.
Expand Down
2 changes: 1 addition & 1 deletion pkg/v1/remote/pusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func TaggableToManifest(t Taggable) (manifest, error) {
return d.Schema1()
}

return tagManifest{t, describable{d.ToDescriptor()}}, nil
return tagManifest{t, describable{d.toDesc()}}, nil
}

desc := v1.Descriptor{
Expand Down

0 comments on commit 9d74288

Please sign in to comment.