Skip to content

Commit

Permalink
Merge pull request #11 from camptocamp/wait_pull
Browse files Browse the repository at this point in the history
Wait for the pull to be completed before continuing
  • Loading branch information
raphink committed Jul 25, 2018
2 parents 89a7a7b + 2a22ac7 commit af53a53
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
upkick
upkick.1
8 changes: 7 additions & 1 deletion handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handler
import (
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
Expand Down Expand Up @@ -132,12 +133,17 @@ func (u *Upkick) GetImages() (images map[string]*image.Image, err error) {
func (u *Upkick) Pull(i *image.Image) (err error) {
log.Debugf("Pulling Image %s", i)

_, err = u.Client.ImagePull(context.Background(), i.ID, types.ImagePullOptions{})
var pullOut io.ReadCloser
pullOut, err = u.Client.ImagePull(context.Background(), i.ID, types.ImagePullOptions{})
if err != nil {
msg := fmt.Sprintf("failed to pull image %s", i.ID)
return errors.Wrap(err, msg)
}

// Wait for the image to be fully pulled
io.Copy(ioutil.Discard, pullOut);
pullOut.Close()

img, _, err := u.Client.ImageInspectWithRaw(context.Background(), i.ID)
if err != nil {
msg := fmt.Sprintf("failed to inspect image %s", i.ID)
Expand Down
5 changes: 3 additions & 2 deletions metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ func TestEventString(t *testing.T) {
Value: "bar",
}
expected := "foo{volume=\"baz\",instance=\"qux\"} bar"
if e.String() != expected {
t.Fatalf("Expected %s, got %s", expected, e.String())
expected2 := "foo{instance=\"qux\", volume=\"baz\"} bar"
if e.String() != expected && e.String() != expected2 {
t.Fatalf("Expected <%s>, got <%s>", expected, e.String())
}
}

Expand Down

0 comments on commit af53a53

Please sign in to comment.