mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-20 01:29:07 +00:00
pkglib: Rename v1 to registry
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
This commit is contained in:
parent
981fb7ff32
commit
54185c8a3f
@ -12,7 +12,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containerd/containerd/reference"
|
"github.com/containerd/containerd/reference"
|
||||||
v1 "github.com/google/go-containerregistry/pkg/v1"
|
registry "github.com/google/go-containerregistry/pkg/v1"
|
||||||
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/cache"
|
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/cache"
|
||||||
lktspec "github.com/linuxkit/linuxkit/src/cmd/linuxkit/spec"
|
lktspec "github.com/linuxkit/linuxkit/src/cmd/linuxkit/spec"
|
||||||
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/version"
|
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/version"
|
||||||
@ -235,7 +235,7 @@ func (p Pkg) Build(bos ...BuildOpt) error {
|
|||||||
fmt.Fprintf(writer, "building %s\n", ref)
|
fmt.Fprintf(writer, "building %s\n", ref)
|
||||||
var (
|
var (
|
||||||
args []string
|
args []string
|
||||||
descs []v1.Descriptor
|
descs []registry.Descriptor
|
||||||
)
|
)
|
||||||
|
|
||||||
if p.git != nil && p.gitRepo != "" {
|
if p.git != nil && p.gitRepo != "" {
|
||||||
@ -354,9 +354,9 @@ func (p Pkg) Build(bos ...BuildOpt) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// buildArch builds the package for a single arch
|
// buildArch builds the package for a single arch
|
||||||
func (p Pkg) buildArch(d dockerRunner, c lktspec.CacheProvider, arch string, args []string, writer io.Writer, bo buildOpts) (*v1.Descriptor, error) {
|
func (p Pkg) buildArch(d dockerRunner, c lktspec.CacheProvider, arch string, args []string, writer io.Writer, bo buildOpts) (*registry.Descriptor, error) {
|
||||||
var (
|
var (
|
||||||
desc *v1.Descriptor
|
desc *registry.Descriptor
|
||||||
tagArch string
|
tagArch string
|
||||||
tag = p.Tag()
|
tag = p.Tag()
|
||||||
)
|
)
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/containerd/containerd/reference"
|
"github.com/containerd/containerd/reference"
|
||||||
v1 "github.com/google/go-containerregistry/pkg/v1"
|
registry "github.com/google/go-containerregistry/pkg/v1"
|
||||||
"github.com/google/go-containerregistry/pkg/v1/types"
|
"github.com/google/go-containerregistry/pkg/v1/types"
|
||||||
lktspec "github.com/linuxkit/linuxkit/src/cmd/linuxkit/spec"
|
lktspec "github.com/linuxkit/linuxkit/src/cmd/linuxkit/spec"
|
||||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
@ -97,7 +97,7 @@ type cacheMocker struct {
|
|||||||
enableImagePull bool
|
enableImagePull bool
|
||||||
enableImageLoad bool
|
enableImageLoad bool
|
||||||
enableIndexWrite bool
|
enableIndexWrite bool
|
||||||
images map[string][]v1.Descriptor
|
images map[string][]registry.Descriptor
|
||||||
hashes map[string][]byte
|
hashes map[string][]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,15 +126,15 @@ func (c *cacheMocker) imageWriteStream(ref *reference.Spec, architecture string,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error reading data: %v", err)
|
return nil, fmt.Errorf("error reading data: %v", err)
|
||||||
}
|
}
|
||||||
hash, size, err := v1.SHA256(bytes.NewReader(b))
|
hash, size, err := registry.SHA256(bytes.NewReader(b))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error calculating hash of layer: %v", err)
|
return nil, fmt.Errorf("error calculating hash of layer: %v", err)
|
||||||
}
|
}
|
||||||
c.assignHash(hash.String(), b)
|
c.assignHash(hash.String(), b)
|
||||||
|
|
||||||
im := v1.Manifest{
|
im := registry.Manifest{
|
||||||
MediaType: types.OCIManifestSchema1,
|
MediaType: types.OCIManifestSchema1,
|
||||||
Layers: []v1.Descriptor{
|
Layers: []registry.Descriptor{
|
||||||
{MediaType: types.OCILayer, Size: size, Digest: hash},
|
{MediaType: types.OCILayer, Size: size, Digest: hash},
|
||||||
},
|
},
|
||||||
SchemaVersion: 2,
|
SchemaVersion: 2,
|
||||||
@ -145,12 +145,12 @@ func (c *cacheMocker) imageWriteStream(ref *reference.Spec, architecture string,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to marshal new image to json: %v", err)
|
return nil, fmt.Errorf("unable to marshal new image to json: %v", err)
|
||||||
}
|
}
|
||||||
hash, size, err = v1.SHA256(bytes.NewReader(b))
|
hash, size, err = registry.SHA256(bytes.NewReader(b))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error calculating hash of index json: %v", err)
|
return nil, fmt.Errorf("error calculating hash of index json: %v", err)
|
||||||
}
|
}
|
||||||
c.assignHash(hash.String(), b)
|
c.assignHash(hash.String(), b)
|
||||||
desc := v1.Descriptor{
|
desc := registry.Descriptor{
|
||||||
MediaType: types.OCIManifestSchema1,
|
MediaType: types.OCIManifestSchema1,
|
||||||
Size: size,
|
Size: size,
|
||||||
Digest: hash,
|
Digest: hash,
|
||||||
@ -163,12 +163,12 @@ func (c *cacheMocker) imageWriteStream(ref *reference.Spec, architecture string,
|
|||||||
return c.NewSource(ref, "", &desc), nil
|
return c.NewSource(ref, "", &desc), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cacheMocker) IndexWrite(ref *reference.Spec, descriptors ...v1.Descriptor) (lktspec.ImageSource, error) {
|
func (c *cacheMocker) IndexWrite(ref *reference.Spec, descriptors ...registry.Descriptor) (lktspec.ImageSource, error) {
|
||||||
if !c.enableIndexWrite {
|
if !c.enableIndexWrite {
|
||||||
return nil, errors.New("disabled")
|
return nil, errors.New("disabled")
|
||||||
}
|
}
|
||||||
image := ref.String()
|
image := ref.String()
|
||||||
im := v1.IndexManifest{
|
im := registry.IndexManifest{
|
||||||
MediaType: types.OCIImageIndex,
|
MediaType: types.OCIImageIndex,
|
||||||
Manifests: descriptors,
|
Manifests: descriptors,
|
||||||
SchemaVersion: 2,
|
SchemaVersion: 2,
|
||||||
@ -179,12 +179,12 @@ func (c *cacheMocker) IndexWrite(ref *reference.Spec, descriptors ...v1.Descript
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to marshal new index to json: %v", err)
|
return nil, fmt.Errorf("unable to marshal new index to json: %v", err)
|
||||||
}
|
}
|
||||||
hash, size, err := v1.SHA256(bytes.NewReader(b))
|
hash, size, err := registry.SHA256(bytes.NewReader(b))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error calculating hash of index json: %v", err)
|
return nil, fmt.Errorf("error calculating hash of index json: %v", err)
|
||||||
}
|
}
|
||||||
c.assignHash(hash.String(), b)
|
c.assignHash(hash.String(), b)
|
||||||
desc := v1.Descriptor{
|
desc := registry.Descriptor{
|
||||||
MediaType: types.OCIImageIndex,
|
MediaType: types.OCIImageIndex,
|
||||||
Size: size,
|
Size: size,
|
||||||
Digest: hash,
|
Digest: hash,
|
||||||
@ -206,13 +206,13 @@ func (c *cacheMocker) Push(name string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cacheMocker) DescriptorWrite(ref *reference.Spec, descriptors ...v1.Descriptor) (lktspec.ImageSource, error) {
|
func (c *cacheMocker) DescriptorWrite(ref *reference.Spec, descriptors ...registry.Descriptor) (lktspec.ImageSource, error) {
|
||||||
if !c.enabledDescriptorWrite {
|
if !c.enabledDescriptorWrite {
|
||||||
return nil, errors.New("descriptor disabled")
|
return nil, errors.New("descriptor disabled")
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
image = ref.String()
|
image = ref.String()
|
||||||
im = v1.IndexManifest{
|
im = registry.IndexManifest{
|
||||||
MediaType: types.OCIImageIndex,
|
MediaType: types.OCIImageIndex,
|
||||||
Manifests: descriptors,
|
Manifests: descriptors,
|
||||||
SchemaVersion: 2,
|
SchemaVersion: 2,
|
||||||
@ -223,12 +223,12 @@ func (c *cacheMocker) DescriptorWrite(ref *reference.Spec, descriptors ...v1.Des
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to marshal new index to json: %v", err)
|
return nil, fmt.Errorf("unable to marshal new index to json: %v", err)
|
||||||
}
|
}
|
||||||
hash, size, err := v1.SHA256(bytes.NewReader(b))
|
hash, size, err := registry.SHA256(bytes.NewReader(b))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error calculating hash of index json: %v", err)
|
return nil, fmt.Errorf("error calculating hash of index json: %v", err)
|
||||||
}
|
}
|
||||||
c.assignHash(hash.String(), b)
|
c.assignHash(hash.String(), b)
|
||||||
root := v1.Descriptor{
|
root := registry.Descriptor{
|
||||||
MediaType: types.OCIImageIndex,
|
MediaType: types.OCIImageIndex,
|
||||||
Size: size,
|
Size: size,
|
||||||
Digest: hash,
|
Digest: hash,
|
||||||
@ -240,13 +240,13 @@ func (c *cacheMocker) DescriptorWrite(ref *reference.Spec, descriptors ...v1.Des
|
|||||||
|
|
||||||
return c.NewSource(ref, "", &root), nil
|
return c.NewSource(ref, "", &root), nil
|
||||||
}
|
}
|
||||||
func (c *cacheMocker) FindDescriptor(name string) (*v1.Descriptor, error) {
|
func (c *cacheMocker) FindDescriptor(name string) (*registry.Descriptor, error) {
|
||||||
if desc, ok := c.images[name]; ok && len(desc) > 0 {
|
if desc, ok := c.images[name]; ok && len(desc) > 0 {
|
||||||
return &desc[0], nil
|
return &desc[0], nil
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("not found %s", name)
|
return nil, fmt.Errorf("not found %s", name)
|
||||||
}
|
}
|
||||||
func (c *cacheMocker) NewSource(ref *reference.Spec, architecture string, descriptor *v1.Descriptor) lktspec.ImageSource {
|
func (c *cacheMocker) NewSource(ref *reference.Spec, architecture string, descriptor *registry.Descriptor) lktspec.ImageSource {
|
||||||
return cacheMockerSource{c, ref, architecture, descriptor}
|
return cacheMockerSource{c, ref, architecture, descriptor}
|
||||||
}
|
}
|
||||||
func (c *cacheMocker) assignHash(hash string, b []byte) {
|
func (c *cacheMocker) assignHash(hash string, b []byte) {
|
||||||
@ -255,9 +255,9 @@ func (c *cacheMocker) assignHash(hash string, b []byte) {
|
|||||||
}
|
}
|
||||||
c.hashes[hash] = b
|
c.hashes[hash] = b
|
||||||
}
|
}
|
||||||
func (c *cacheMocker) appendImage(image string, root v1.Descriptor) {
|
func (c *cacheMocker) appendImage(image string, root registry.Descriptor) {
|
||||||
if c.images == nil {
|
if c.images == nil {
|
||||||
c.images = map[string][]v1.Descriptor{}
|
c.images = map[string][]registry.Descriptor{}
|
||||||
}
|
}
|
||||||
c.images[image] = append(c.images[image], root)
|
c.images[image] = append(c.images[image], root)
|
||||||
}
|
}
|
||||||
@ -266,7 +266,7 @@ type cacheMockerSource struct {
|
|||||||
c *cacheMocker
|
c *cacheMocker
|
||||||
ref *reference.Spec
|
ref *reference.Spec
|
||||||
architecture string
|
architecture string
|
||||||
descriptor *v1.Descriptor
|
descriptor *registry.Descriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c cacheMockerSource) Config() (imagespec.ImageConfig, error) {
|
func (c cacheMockerSource) Config() (imagespec.ImageConfig, error) {
|
||||||
@ -275,7 +275,7 @@ func (c cacheMockerSource) Config() (imagespec.ImageConfig, error) {
|
|||||||
func (c cacheMockerSource) TarReader() (io.ReadCloser, error) {
|
func (c cacheMockerSource) TarReader() (io.ReadCloser, error) {
|
||||||
return nil, errors.New("unsupported")
|
return nil, errors.New("unsupported")
|
||||||
}
|
}
|
||||||
func (c cacheMockerSource) Descriptor() *v1.Descriptor {
|
func (c cacheMockerSource) Descriptor() *registry.Descriptor {
|
||||||
return c.descriptor
|
return c.descriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user