Skip to content

Commit

Permalink
#230: Improvements to image pull/update (#231)
Browse files Browse the repository at this point in the history
* #230: Improvements to the image update process.
* Add a test for changes in #230
* remove dead code to ensure validation checks pass
  • Loading branch information
fubarhouse committed Jul 10, 2020
1 parent 72cf9d8 commit 8ce99bb
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 71 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ matrix:
- go build -o pygmy-go-linux-x86

# Run pygmy
- ./pygmy-go-linux-x86 pull;
- ./pygmy-go-linux-x86 pull;
- ./pygmy-go-linux-x86 status;
- ./pygmy-go-linux-x86 --config examples/pygmy.travis.yml up;
- ./pygmy-go-linux-x86 --config examples/pygmy.travis.yml status;
Expand Down
49 changes: 0 additions & 49 deletions service/amazee/amazee.go

This file was deleted.

10 changes: 5 additions & 5 deletions service/interface/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,15 +487,15 @@ func DockerPull(image string) (string, error) {
}

if event != nil {
if strings.Contains(event.Status, fmt.Sprintf("Downloaded newer image for %s", image)) {
return fmt.Sprintf("Successfully pulled %v\n", image), nil
if strings.Contains(event.Status, fmt.Sprint("Downloaded newer image")) {
return fmt.Sprintf("Successfully pulled %v", image), nil
}

if strings.Contains(event.Status, fmt.Sprintf("Image is up to date for %s", image)) {
return fmt.Sprintf("Image %v is up to date\n", image), nil
if strings.Contains(event.Status, fmt.Sprint("Image is up to date")) {
return fmt.Sprintf("Image %v is up to date", image), nil
}
}
return "", nil
return event.Status, nil
}

// DockerRun will setup and run a given container.
Expand Down
17 changes: 3 additions & 14 deletions service/library/pull.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
package library

import (
"fmt"
"github.com/fubarhouse/pygmy-go/service/interface"
)

// Pull is an alias function for Update.
// It is here for the sake of user experience.
func Pull(c Config) {

Setup(&c)

for _, Service := range c.Services {

_, e := model.DockerPull(Service.Config.Image)
if e != nil {
fmt.Print(e)
}
Update(c)

}
}
45 changes: 42 additions & 3 deletions service/library/update.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,47 @@
package library

import "github.com/fubarhouse/pygmy-go/service/amazee"
import (
"fmt"
"strings"

// Update will update the Amazee images
model "github.com/fubarhouse/pygmy-go/service/interface"
)

// Update will update the the images for all configured services.
func Update(c Config) {
amazee.AmazeeImagePull()

// 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 = model.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)
}
}
}
}

}

0 comments on commit 8ce99bb

Please sign in to comment.