Explorar o código

check if image tag exists for image push

Mohammed Nafees %!s(int64=4) %!d(string=hai) anos
pai
achega
4024d3fe13
Modificáronse 1 ficheiros con 12 adicións e 9 borrados
  1. 12 9
      cli/cmd/deploy/deploy.go

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

@@ -140,6 +140,14 @@ func NewDeployAgent(client *client.Client, app string, opts *DeployOpts) (*Deplo
 	err = coalesceEnvGroups(deployAgent.client, deployAgent.opts.ProjectID, deployAgent.opts.ClusterID,
 		deployAgent.opts.Namespace, deployAgent.opts.EnvGroups, deployAgent.release.Config)
 
+	imageExists, err := deployAgent.agent.CheckIfImageExists(fmt.Sprintf("%s:%s", deployAgent.imageRepo, deployAgent.tag))
+
+	if err != nil {
+		return nil, err
+	}
+
+	deployAgent.imageExists = imageExists
+
 	return deployAgent, err
 }
 
@@ -228,14 +236,6 @@ func (d *DeployAgent) Build(overrideBuildConfig *types.BuildConfig, forceBuild b
 		d.tag = currentTag
 	}
 
-	imageExists, err := d.agent.CheckIfImageExists(fmt.Sprintf("%s:%s", d.imageRepo, d.tag))
-
-	if err != nil {
-		return err
-	}
-
-	d.imageExists = imageExists
-
 	// we do not want to re-build an image
 	// FIXME: what if overrideBuildConfig == nil but the image stays the same?
 	if overrideBuildConfig == nil && d.imageExists && d.tag != "latest" && !forceBuild {
@@ -245,6 +245,8 @@ func (d *DeployAgent) Build(overrideBuildConfig *types.BuildConfig, forceBuild b
 
 	// if build is not local, fetch remote source
 	var basePath string
+	var err error
+
 	buildCtx := d.opts.LocalPath
 
 	if !d.opts.Local {
@@ -324,7 +326,8 @@ func (d *DeployAgent) Build(overrideBuildConfig *types.BuildConfig, forceBuild b
 
 // Push pushes a local image to the remote repository linked in the release
 func (d *DeployAgent) Push(forcePush bool) error {
-	if !forcePush && d.tag != "latest" {
+	if d.imageExists && !forcePush && d.tag != "latest" {
+		fmt.Printf("%s:%s has been pushed already, so skipping push\n", d.imageRepo, d.tag)
 		return nil
 	}