Skip to content

Commit

Permalink
fix(imagePull): fix image not found
Browse files Browse the repository at this point in the history
fix image not found

Signed-off-by: mritd <[email protected]>
  • Loading branch information
mritd committed Sep 1, 2018
1 parent fe3814f commit c3f7703
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pkg/gcrsync/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"context"
"encoding/base64"
"fmt"
"io"
"io/ioutil"
"strings"

"github.com/json-iterator/go"
Expand Down Expand Up @@ -54,20 +56,22 @@ func (g *Gcr) process(image Image) {
}

// pull image
_, err := g.dockerClient.ImagePull(ctx, oldImageName, types.ImagePullOptions{})
r, err := g.dockerClient.ImagePull(ctx, oldImageName, types.ImagePullOptions{})
if !utils.CheckErr(err) {
logrus.Errorf("Failed to pull image: %s", oldImageName)
return
}
logrus.Debugf("Pull image: %s success.", oldImageName)
io.Copy(ioutil.Discard, r)
r.Close()
logrus.Infof("Pull image: %s success.", oldImageName)

// tag it
err = g.dockerClient.ImageTag(ctx, oldImageName, newImageName)
if !utils.CheckErr(err) {
logrus.Errorf("Failed to tag image [%s] ==> [%s]", oldImageName, newImageName)
return
}
logrus.Debugf("Tag image: %s success.", oldImageName)
logrus.Infof("Tag image: %s success.", oldImageName)

// push image
authConfig := types.AuthConfig{
Expand All @@ -80,12 +84,14 @@ func (g *Gcr) process(image Image) {
return
}
authStr := base64.URLEncoding.EncodeToString(encodedJSON)
_, err = g.dockerClient.ImagePush(ctx, newImageName, types.ImagePushOptions{RegistryAuth: authStr})
r, err = g.dockerClient.ImagePush(ctx, newImageName, types.ImagePushOptions{RegistryAuth: authStr})
if !utils.CheckErr(err) {
logrus.Errorf("Failed to push image: %s", newImageName)
return
}
logrus.Debugf("Push image: %s success.", newImageName)
io.Copy(ioutil.Discard, r)
r.Close()
logrus.Infof("Push image: %s success.", newImageName)

// clean image
g.dockerClient.ImageRemove(ctx, oldImageName, types.ImageRemoveOptions{})
Expand Down

0 comments on commit c3f7703

Please sign in to comment.