mirror of
https://github.com/containers/skopeo.git
synced 2025-08-29 03:22:43 +00:00
cmd/skopeo: refactor layers command
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
f420d6867b
commit
9900b79eb6
@ -1,6 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/containers/image/directory"
|
||||||
|
"github.com/containers/image/image"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -9,13 +14,45 @@ var layersCmd = cli.Command{
|
|||||||
Name: "layers",
|
Name: "layers",
|
||||||
Usage: "get images layers",
|
Usage: "get images layers",
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
img, err := parseImage(c)
|
rawSource, err := parseImageSource(c, c.Args()[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := img.LayersCommand(c.Args().Tail()...); err != nil {
|
src := image.FromSource(rawSource)
|
||||||
|
layers := c.Args().Tail()
|
||||||
|
if len(layers) == 0 {
|
||||||
|
ls, err := src.LayerDigests()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
layers = ls
|
||||||
|
}
|
||||||
|
tmpDir, err := ioutil.TempDir(".", "layers-")
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
dest := directory.NewDirImageDestination(tmpDir)
|
||||||
|
manifest, err := src.Manifest()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := dest.PutManifest(manifest); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, l := range layers {
|
||||||
|
if !strings.HasPrefix(l, "sha256:") {
|
||||||
|
l = "sha256:" + l
|
||||||
|
}
|
||||||
|
r, _, err := rawSource.GetBlob(l)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := dest.PutBlob(l, r); err != nil {
|
||||||
|
r.Close()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
r.Close()
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user