/
update.go
58 lines (50 loc) · 1.13 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
package library
import (
"fmt"
"strings"
"github.com/pygmystack/pygmy/service/interface/docker"
)
// Update will update the the images for all configured services.
func Update(c Config) {
// Import the configuration.
Setup(&c)
// Loop over services.
for s := range c.Services {
// Pull the image.
service := c.Services[s]
purpose, _ := service.GetFieldString("purpose")
var result string
var err error
if purpose == "" || purpose == "sshagent" {
result, err = docker.DockerPull(service.Config.Image)
if err == nil {
fmt.Println(result)
}
}
// If the service is running, restart it.
if s, _ := service.Status(); s && !strings.Contains(result, "is up to date") {
var e error
e = service.Stop()
if e != nil {
fmt.Println(e)
}
if s, _ := service.Status(); !s {
e = service.Start()
if e != nil {
fmt.Println(e)
}
}
}
}
images, _ := docker.DockerImageList()
for _, image := range images {
for _, tag := range image.RepoTags {
if strings.Contains(tag, "uselagoon") {
result, err := docker.DockerPull(tag)
if err == nil {
fmt.Println(result)
}
}
}
}
}