Updating Image Pull to use docker/distribution package

Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
This commit is contained in:
Nishant Totla 2016-03-31 17:42:01 -07:00
parent 0b75203143
commit 25241bdd08
No known key found for this signature in database
GPG Key ID: 7EA5781C9B3D0C19
1 changed files with 23 additions and 4 deletions

View File

@ -16,6 +16,7 @@ import (
"golang.org/x/net/context"
log "github.com/Sirupsen/logrus"
"github.com/docker/distribution/reference"
"github.com/docker/docker/pkg/version"
engineapi "github.com/docker/engine-api/client"
"github.com/docker/engine-api/types"
@ -950,15 +951,33 @@ func (e *Engine) CreateVolume(request *types.VolumeCreateRequest) (*Volume, erro
}
// FIXME: This will become unnecessary after docker/engine-api#162 is merged
func getTagFromNamedRef(dref reference.Named) string {
var tag string
switch x := dref.(type) {
case reference.Digested:
tag = x.Digest().String()
case reference.NamedTagged:
tag = x.Tag()
}
return tag
}
// Pull an image on the engine
func (e *Engine) Pull(image string, authConfig *types.AuthConfig) error {
if !strings.Contains(image, ":") {
image = image + ":latest"
distributionRef, err := reference.ParseNamed(image)
if err != nil {
return err
}
repository := distributionRef.Name()
tag := getTagFromNamedRef(distributionRef)
pullOpts := types.ImagePullOptions{
ImageID: image,
ImageID: repository,
Tag: tag,
}
_, err := e.apiClient.ImagePull(context.TODO(), pullOpts, nil)
_, err = e.apiClient.ImagePull(context.TODO(), pullOpts, nil)
e.CheckConnectionErr(err)
if err != nil {
return err