imagetools: implement inspect for manifest list

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi
2019-04-16 15:14:03 -07:00
parent a0719aee88
commit 0a28ec6f38
5 changed files with 209 additions and 11 deletions

View File

@ -1,10 +1,16 @@
package commands
import (
"fmt"
"os"
"github.com/containerd/containerd/images"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/pkg/errors"
"github.com/moby/buildkit/util/appcontext"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/spf13/cobra"
"github.com/tonistiigi/buildx/util/imagetools"
)
type inspectOptions struct {
@ -12,7 +18,32 @@ type inspectOptions struct {
}
func runInspect(dockerCli command.Cli, in inspectOptions, name string) error {
return errors.Errorf("not-implemented")
ctx := appcontext.Context()
r := imagetools.New(imagetools.Opt{
Auth: dockerCli.ConfigFile(),
})
dt, desc, err := r.Get(ctx, name)
if err != nil {
return err
}
if in.raw {
fmt.Printf("%s\n", dt)
return nil
}
switch desc.MediaType {
// case images.MediaTypeDockerSchema2Manifest, specs.MediaTypeImageManifest:
// TODO: handle distribution manifest and schema1
case images.MediaTypeDockerSchema2ManifestList, ocispec.MediaTypeImageIndex:
imagetools.PrintManifestList(dt, desc, name, os.Stdout)
default:
fmt.Printf("%s\n", dt)
}
return nil
}
func inspectCmd(dockerCli command.Cli) *cobra.Command {