working commit

This commit is contained in:
2026-03-06 19:13:29 +02:00
parent 68982835be
commit 81e943f1c5
10 changed files with 438 additions and 104 deletions
+38 -13
View File
@@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"os"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
@@ -28,7 +28,7 @@ func NewDownloader(client *Client) *Downloader {
}
}
func (down *Downloader) Pull(ctx context.Context, rawref, dir, os, arch string) error {
func (down *Downloader) Pull(ctx context.Context, rawref, dir, osname, arch string) error {
var err error
ref, err := ParseReference(rawref)
if err != nil {
@@ -46,6 +46,7 @@ func (down *Downloader) Pull(ctx context.Context, rawref, dir, os, arch string)
return err
}
var digstr string
if mime == MediaTypeOIIv1 || mime == MediaTypeDDMLv2 {
var index ocispec.Index
err = json.Unmarshal(man, &index)
@@ -55,9 +56,10 @@ func (down *Downloader) Pull(ctx context.Context, rawref, dir, os, arch string)
for _, descr := range index.Manifests {
if descr.Platform != nil {
cond := descr.Platform.Architecture == arch
cond = cond && descr.Platform.OS == os
cond = cond && descr.Platform.OS == osname
if cond {
tag = descr.Digest.String()
digstr = descr.Digest.String()
}
}
}
@@ -81,24 +83,47 @@ func (down *Downloader) Pull(ctx context.Context, rawref, dir, os, arch string)
if err != nil {
return err
}
//"oci-layout"
//"index.json"
// Write image manifest
imager := NewEmptyImager(dir)
err = imager.WriteManifest(ctx, digstr, mime, man)
if err != nil {
return err
}
layers := make([]ocispec.Descriptor, 0)
layers = append(layers, manifest.Config)
layers = append(layers, manifest.Layers...)
for _, layer := range layers {
digest := layer.Digest.String()
exist, err := down.cli.GetBlob(ctx, rawrepo, io.Discard, digest)
wrapfunc := func() error {
tmpfile, err := os.CreateTemp(dir, "*.bin")
if err != nil {
return err
}
defer tmpfile.Close()
tmpname := tmpfile.Name()
defer os.Remove(tmpname)
digstr := layer.Digest.String()
exist, err := down.cli.GetBlob(ctx, rawrepo, tmpfile, digstr)
if err != nil {
return err
}
if !exist {
err = errors.New("Layer not found")
return err
}
tmpfile.Seek(0, 0)
size := layer.Size
err = imager.WriteLayer(ctx, digstr, size, tmpfile)
if err != nil {
return err
}
return err
}
err = wrapfunc()
if err != nil {
return err
}
if !exist {
err = errors.New("Layer not found")
return err
}
fmt.Printf("Layer type: %s\n", layer.MediaType)
}
return err
}