start of implementing direct client access
This commit is contained in:
parent
ced348b87c
commit
7aace0ee2a
1 changed files with 45 additions and 6 deletions
51
images.go
51
images.go
|
@ -1,6 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/fsouza/go-dockerclient"
|
||||
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
@ -29,15 +31,52 @@ var imagesCommand ImagesCommand
|
|||
|
||||
func (x *ImagesCommand) Execute(args []string) error {
|
||||
|
||||
// read in stdin
|
||||
stdin, err := ioutil.ReadAll(os.Stdin)
|
||||
var images *[]Image
|
||||
|
||||
stat, err := os.Stdin.Stat()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading all input", err)
|
||||
return fmt.Errorf("error reading stdin stat", err)
|
||||
}
|
||||
|
||||
images, err := parseImagesJSON(stdin)
|
||||
if err != nil {
|
||||
return err
|
||||
if (stat.Mode() & os.ModeCharDevice) == 0 {
|
||||
// read in stdin
|
||||
stdin, err := ioutil.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading all input", err)
|
||||
}
|
||||
|
||||
images, err = parseImagesJSON(stdin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// grab directly from docker daemon
|
||||
client, err := docker.NewClient("unix:///var/run/docker.sock")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
clientImages, err := client.ListImages(docker.ListImagesOptions{All: true})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var ims []Image
|
||||
for _, image := range clientImages {
|
||||
// fmt.Println(image)
|
||||
ims = append(ims, Image{
|
||||
image.ID,
|
||||
image.ParentID,
|
||||
image.RepoTags,
|
||||
image.VirtualSize,
|
||||
image.Size,
|
||||
image.Created,
|
||||
})
|
||||
}
|
||||
|
||||
images = &ims
|
||||
}
|
||||
|
||||
if imagesCommand.Dot {
|
||||
|
|
Loading…
Reference in a new issue