/
update.go
71 lines (55 loc) · 1.55 KB
/
update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// This update processor updates the images on nanobox local
package processors
import (
"strings"
"time"
"github.com/jcelliott/lumber"
"github.com/nanobox-io/golang-docker-client"
process_provider "github.com/nanobox-io/nanobox/processors/provider"
"github.com/nanobox-io/nanobox/util"
"github.com/nanobox-io/nanobox/util/display"
)
func Update() error {
// init docker client
if err := process_provider.Init(); err != nil {
return util.ErrorAppend(err, "failed to init docker client")
}
// update all the nanobox images
if err := pullImages(); err != nil {
return util.ErrorAppend(err, "failed to pull images")
}
return nil
}
func pullImages() error {
display.OpenContext("Updating Images")
defer display.CloseContext()
images, err := docker.ImageList()
if err != nil {
return err
}
for _, image := range images {
if image.Slug == "" {
continue
}
if !strings.Contains(image.Slug, "nanobox/") {
continue
}
display.StartTask("Pulling %s image", image.Slug)
// generate a docker percent display
dockerPercent := &display.DockerPercentDisplay{
Output: display.NewStreamer("info"),
}
// pull the build image
imagePullFunc := func() error {
_, err := docker.ImagePull(image.Slug, dockerPercent)
return err
}
if err := util.Retry(imagePullFunc, 5, time.Second); err != nil {
lumber.Error("code:pullBuildImage:docker.ImagePull(%s, nil): %s", image.Slug, err.Error())
display.ErrorTask()
return util.ErrorAppend(err, "failed to pull docker image (%s)", image.Slug)
}
display.StopTask()
}
return nil
}