traefik/vendor/github.com/libkermit/docker/image.go
Vincent Demeester b7daa2f3a4 Update traefik dependencies (docker/docker and related) (#1823)
Update traefik dependencies (docker/docker and related)

- Update dependencies
- Fix compilation problems
- Remove vdemeester/docker-events (in docker api now)
- Remove `integration/vendor`
- Use `testImport`
- update some deps.
- regenerate the lock from scratch (after a `glide cc`)
2017-07-06 16:28:13 +02:00

40 lines
825 B
Go

package docker
import (
"fmt"
"io/ioutil"
"golang.org/x/net/context"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
)
// Pull pulls the given reference (image)
func (p *Project) Pull(ref string) error {
return p.ensureImageExists(ref, true)
}
func (p *Project) ensureImageExists(ref string, force bool) error {
if !force {
// Check if ref is already there
_, _, err := p.Client.ImageInspectWithRaw(context.Background(), ref)
if err != nil && !client.IsErrImageNotFound(err) {
return err
}
if err == nil {
return nil
}
}
// And pull it
responseBody, err := p.Client.ImagePull(context.Background(), ref, types.ImagePullOptions{})
if err != nil {
fmt.Printf("%v", err)
return err
}
defer responseBody.Close()
_, err = ioutil.ReadAll(responseBody)
return err
}