traefik/vendor/github.com/libkermit/docker/image.go

41 lines
820 B
Go
Raw Normal View History

2017-02-07 21:33:23 +00:00
package docker
import (
"fmt"
"io/ioutil"
"golang.org/x/net/context"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
2017-02-07 21:33:23 +00:00
)
// 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)
2018-01-22 11:16:03 +00:00
if err != nil && !client.IsErrNotFound(err) {
2017-02-07 21:33:23 +00:00
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
}