mirror of https://github.com/docker/docs.git
Moving over images to use engine-api
Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
This commit is contained in:
parent
d2bbd6bc19
commit
7de9f6ee62
|
|
@ -185,7 +185,7 @@ func getImagesJSON(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
accepteds := filters.Get("node")
|
accepteds := filters.Get("node")
|
||||||
// this struct helps grouping images
|
// this struct helps grouping images
|
||||||
// but still keeps their Engine infos as an array.
|
// but still keeps their Engine infos as an array.
|
||||||
groupImages := make(map[string]dockerclient.Image)
|
groupImages := make(map[string]apitypes.Image)
|
||||||
opts := cluster.ImageFilterOptions{
|
opts := cluster.ImageFilterOptions{
|
||||||
All: boolValue(r, "all"),
|
All: boolValue(r, "all"),
|
||||||
NameFilter: r.FormValue("filter"),
|
NameFilter: r.FormValue("filter"),
|
||||||
|
|
@ -206,16 +206,16 @@ func getImagesJSON(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// grouping images by Id, and concat their RepoTags
|
// grouping images by Id, and concat their RepoTags
|
||||||
if entry, existed := groupImages[image.Id]; existed {
|
if entry, existed := groupImages[image.ID]; existed {
|
||||||
entry.RepoTags = append(entry.RepoTags, image.RepoTags...)
|
entry.RepoTags = append(entry.RepoTags, image.RepoTags...)
|
||||||
entry.RepoDigests = append(entry.RepoDigests, image.RepoDigests...)
|
entry.RepoDigests = append(entry.RepoDigests, image.RepoDigests...)
|
||||||
groupImages[image.Id] = entry
|
groupImages[image.ID] = entry
|
||||||
} else {
|
} else {
|
||||||
groupImages[image.Id] = image.Image
|
groupImages[image.ID] = image.Image
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
images := []dockerclient.Image{}
|
images := []apitypes.Image{}
|
||||||
|
|
||||||
for _, image := range groupImages {
|
for _, image := range groupImages {
|
||||||
// de-duplicate RepoTags
|
// de-duplicate RepoTags
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/docker/engine-api/types"
|
||||||
"github.com/docker/swarm/cluster"
|
"github.com/docker/swarm/cluster"
|
||||||
"github.com/samalba/dockerclient"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContainerSorter implements the Sort interface to sort Docker containers.
|
// ContainerSorter implements the Sort interface to sort Docker containers.
|
||||||
|
|
@ -27,7 +27,7 @@ func (s ContainerSorter) Less(i, j int) bool {
|
||||||
|
|
||||||
// ImageSorter implements the Sort interface to sort Docker Images.
|
// ImageSorter implements the Sort interface to sort Docker Images.
|
||||||
// It is not guaranteed to be a stable sort.
|
// It is not guaranteed to be a stable sort.
|
||||||
type ImageSorter []dockerclient.Image
|
type ImageSorter []types.Image
|
||||||
|
|
||||||
// Len returns the number of images to be sorted.
|
// Len returns the number of images to be sorted.
|
||||||
func (s ImageSorter) Len() int {
|
func (s ImageSorter) Len() int {
|
||||||
|
|
|
||||||
|
|
@ -536,7 +536,8 @@ func (e *Engine) RemoveVolume(name string) error {
|
||||||
|
|
||||||
// RefreshImages refreshes the list of images on the engine.
|
// RefreshImages refreshes the list of images on the engine.
|
||||||
func (e *Engine) RefreshImages() error {
|
func (e *Engine) RefreshImages() error {
|
||||||
images, err := e.client.ListImages(true)
|
imgLstOpts := types.ImageListOptions{All: true}
|
||||||
|
images, err := e.apiClient.ImageList(context.TODO(), imgLstOpts)
|
||||||
e.CheckConnectionErr(err)
|
e.CheckConnectionErr(err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -544,7 +545,7 @@ func (e *Engine) RefreshImages() error {
|
||||||
e.Lock()
|
e.Lock()
|
||||||
e.images = nil
|
e.images = nil
|
||||||
for _, image := range images {
|
for _, image := range images {
|
||||||
e.images = append(e.images, &Image{Image: *image, Engine: e})
|
e.images = append(e.images, &Image{Image: image, Engine: e})
|
||||||
}
|
}
|
||||||
e.Unlock()
|
e.Unlock()
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,13 @@ package cluster
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/docker/engine-api/types"
|
||||||
dockerfilters "github.com/docker/engine-api/types/filters"
|
dockerfilters "github.com/docker/engine-api/types/filters"
|
||||||
"github.com/samalba/dockerclient"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Image is exported
|
// Image is exported
|
||||||
type Image struct {
|
type Image struct {
|
||||||
dockerclient.Image
|
types.Image
|
||||||
|
|
||||||
Engine *Engine
|
Engine *Engine
|
||||||
}
|
}
|
||||||
|
|
@ -39,12 +39,12 @@ func (image *Image) Match(IDOrName string, matchTag bool) bool {
|
||||||
size := len(IDOrName)
|
size := len(IDOrName)
|
||||||
|
|
||||||
// TODO: prefix match can cause false positives with image names
|
// TODO: prefix match can cause false positives with image names
|
||||||
if image.Id == IDOrName || (size > 2 && strings.HasPrefix(image.Id, IDOrName)) {
|
if image.ID == IDOrName || (size > 2 && strings.HasPrefix(image.ID, IDOrName)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// trim sha256: and retry
|
// trim sha256: and retry
|
||||||
if parts := strings.SplitN(image.Id, ":", 2); len(parts) == 2 {
|
if parts := strings.SplitN(image.ID, ":", 2); len(parts) == 2 {
|
||||||
if parts[1] == IDOrName || (size > 2 && strings.HasPrefix(parts[1], IDOrName)) {
|
if parts[1] == IDOrName || (size > 2 && strings.HasPrefix(parts[1], IDOrName)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
@ -80,6 +80,7 @@ func (image *Image) Match(IDOrName string, matchTag bool) bool {
|
||||||
|
|
||||||
// ImageFilterOptions is the set of filtering options supported by
|
// ImageFilterOptions is the set of filtering options supported by
|
||||||
// Images.Filter()
|
// Images.Filter()
|
||||||
|
// FIXMEENGINEAPI: should either embed or be replaced by types.ImageListOptions
|
||||||
type ImageFilterOptions struct {
|
type ImageFilterOptions struct {
|
||||||
All bool
|
All bool
|
||||||
NameFilter string
|
NameFilter string
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ func (f *AffinityFilter) Filter(config *cluster.ContainerConfig, nodes []*node.N
|
||||||
case "image":
|
case "image":
|
||||||
images := []string{}
|
images := []string{}
|
||||||
for _, image := range node.Images {
|
for _, image := range node.Images {
|
||||||
images = append(images, image.Id)
|
images = append(images, image.ID)
|
||||||
images = append(images, image.RepoTags...)
|
images = append(images, image.RepoTags...)
|
||||||
for _, tag := range image.RepoTags {
|
for _, tag := range image.RepoTags {
|
||||||
repo, _ := cluster.ParseRepositoryTag(tag)
|
repo, _ := cluster.ParseRepositoryTag(tag)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue