2
0
Эх сурвалжийг харах

try higher recount for gcr images

Alexander Belanger 4 жил өмнө
parent
commit
41149544e1

+ 9 - 1
cli/cmd/deploy/create.go

@@ -302,7 +302,15 @@ func (c *CreateAgent) CreateFromDocker(
 		return "", err
 	}
 
-	err = agent.PushImage(fmt.Sprintf("%s:%s", imageURL, "latest"))
+	retryCount := 1
+
+	// sometimes newly created gcr repositories aren't ready on the initial
+	// creation, so retry count is set higher
+	if strings.Contains(imageURL, "gcr.io") {
+		retryCount = 5
+	}
+
+	err = agent.PushImage(fmt.Sprintf("%s:%s", imageURL, "latest"), retryCount)
 
 	if err != nil {
 		return "", err

+ 9 - 1
cli/cmd/deploy/deploy.go

@@ -266,7 +266,15 @@ func (d *DeployAgent) Build() error {
 
 // Push pushes a local image to the remote repository linked in the release
 func (d *DeployAgent) Push() error {
-	return d.agent.PushImage(fmt.Sprintf("%s:%s", d.imageRepo, d.tag))
+	retryCount := 1
+
+	// sometimes newly created gcr repositories aren't ready on the initial
+	// creation, so retry count is set higher
+	if strings.Contains(d.imageRepo, "gcr.io") {
+		retryCount = 5
+	}
+
+	return d.agent.PushImage(fmt.Sprintf("%s:%s", d.imageRepo, d.tag), retryCount)
 }
 
 // UpdateImageAndValues updates the current image for a release, along with new

+ 22 - 12
cli/cmd/docker/agent.go

@@ -6,6 +6,7 @@ import (
 	"encoding/json"
 	"errors"
 	"fmt"
+	"io"
 	"os"
 	"strings"
 	"time"
@@ -187,28 +188,37 @@ func (a *Agent) PullImage(image string) error {
 }
 
 // PushImage pushes an image specified by the image string
-func (a *Agent) PushImage(image string) error {
+func (a *Agent) PushImage(image string, retryCount int) error {
+	var err error
+
 	opts, err := a.getPushOptions(image)
 
 	if err != nil {
 		return err
 	}
 
-	out, err := a.client.ImagePush(
-		context.Background(),
-		image,
-		opts,
-	)
+	var out io.ReadCloser
 
-	if err != nil {
-		return err
-	}
+	for i := 0; i < retryCount; i++ {
+		out, err = a.client.ImagePush(
+			context.Background(),
+			image,
+			opts,
+		)
 
-	defer out.Close()
+		if err != nil {
+			time.Sleep(1 * time.Second)
+			continue
+		}
 
-	termFd, isTerm := term.GetFdInfo(os.Stderr)
+		defer out.Close()
 
-	return jsonmessage.DisplayJSONMessagesStream(out, os.Stderr, termFd, isTerm, nil)
+		termFd, isTerm := term.GetFdInfo(os.Stderr)
+
+		return jsonmessage.DisplayJSONMessagesStream(out, os.Stderr, termFd, isTerm, nil)
+	}
+
+	return err
 }
 
 func (a *Agent) getPullOptions(image string) (types.ImagePullOptions, error) {