Sfoglia il codice sorgente

Merge pull request #1846 from porter-dev/belanger/add-preview-env-fixes

Add small preview environment improvements to apply command
abelanger5 4 anni fa
parent
commit
41c72d24e4
3 ha cambiato i file con 65 aggiunte e 10 eliminazioni
  1. 23 5
      cli/cmd/apply.go
  2. 5 3
      cli/cmd/deploy/create.go
  3. 37 2
      cli/cmd/job.go

+ 23 - 5
cli/cmd/apply.go

@@ -171,9 +171,14 @@ type Target struct {
 type ApplicationConfig struct {
 	WaitForJob bool
 
+	// If set to true, this does not run an update, it only creates the initial application and job,
+	// skipping subsequent updates
+	OnlyCreate bool
+
 	Build struct {
 		ForceBuild bool
 		ForcePush  bool
+		UseCache   bool
 		Method     string
 		Context    string
 		Dockerfile string
@@ -358,6 +363,15 @@ func (d *Driver) applyApplication(resource *models.Resource, client *api.Client,
 		OverrideTag:     tag,
 		Method:          deploy.DeployBuildType(method),
 		EnvGroups:       appConfig.EnvGroups,
+		UseCache:        appConfig.Build.UseCache,
+	}
+
+	if appConfig.Build.UseCache {
+		err := setDockerConfig(client)
+
+		if err != nil {
+			return nil, err
+		}
 	}
 
 	if shouldCreate {
@@ -366,19 +380,21 @@ func (d *Driver) applyApplication(resource *models.Resource, client *api.Client,
 		if err != nil {
 			return nil, err
 		}
-	} else {
+	} else if !appConfig.OnlyCreate {
 		resource, err = d.updateApplication(resource, client, sharedOpts, appConfig)
 
 		if err != nil {
 			return nil, err
 		}
+	} else {
+		color.New(color.FgYellow).Printf("Skipping creation for %s as onlyCreate is set to true\n", resource.Name)
 	}
 
 	if err = d.assignOutput(resource, client); err != nil {
 		return nil, err
 	}
 
-	if d.source.Name == "job" && appConfig.WaitForJob {
+	if d.source.Name == "job" && appConfig.WaitForJob && (shouldCreate || !appConfig.OnlyCreate) {
 		color.New(color.FgYellow).Printf("Waiting for job '%s' to finish\n", resource.Name)
 
 		prevProject := config.Project
@@ -507,10 +523,12 @@ func (d *Driver) updateApplication(resource *models.Resource, client *api.Client
 			return nil, err
 		}
 
-		err = updateAgent.Push(appConf.Build.ForcePush)
+		if !appConf.Build.UseCache {
+			err = updateAgent.Push(appConf.Build.ForcePush)
 
-		if err != nil {
-			return nil, err
+			if err != nil {
+				return nil, err
+			}
 		}
 	}
 

+ 5 - 3
cli/cmd/deploy/create.go

@@ -327,10 +327,12 @@ func (c *CreateAgent) CreateFromDocker(
 			return "", err
 		}
 
-		err = agent.PushImage(fmt.Sprintf("%s:%s", imageURL, imageTag))
+		if !opts.SharedOpts.UseCache {
+			err = agent.PushImage(fmt.Sprintf("%s:%s", imageURL, imageTag))
 
-		if err != nil {
-			return "", err
+			if err != nil {
+				return "", err
+			}
 		}
 	}
 

+ 37 - 2
cli/cmd/job.go

@@ -166,8 +166,14 @@ func waitForJob(_ *types.GetAuthenticatedUserResponse, client *api.Client, args
 		return pausedErr
 	}
 
-	// if no job exists with the given revision, wait up to 30 minutes
-	timeWait := time.Now().Add(30 * time.Minute)
+	// attempt to parse out the timeout value for the job, given by `sidecar.timeout`
+	// if it does not exist, we set the default to 30 minutes
+	timeoutVal := getJobTimeoutValue(jobRelease.Release.Config)
+
+	color.New(color.FgYellow).Printf("Waiting for timeout seconds %d\n", timeoutVal.Seconds())
+
+	// if no job exists with the given revision, wait for the timeout value
+	timeWait := time.Now().Add(timeoutVal)
 
 	for time.Now().Before(timeWait) {
 		// get the jobs for that job chart
@@ -222,3 +228,32 @@ func getJobMatchingRevision(revision uint, jobs []v1.Job) *v1.Job {
 
 	return nil
 }
+
+func getJobTimeoutValue(values map[string]interface{}) time.Duration {
+	defaultTimeout := time.Minute * 60
+	sidecarInter, ok := values["sidecar"]
+
+	if !ok {
+		return defaultTimeout
+	}
+
+	sidecarVal, ok := sidecarInter.(map[string]interface{})
+
+	if !ok {
+		return defaultTimeout
+	}
+
+	timeoutInter, ok := sidecarVal["timeout"]
+
+	if !ok {
+		return defaultTimeout
+	}
+
+	timeoutVal, ok := timeoutInter.(int64)
+
+	if !ok {
+		return defaultTimeout
+	}
+
+	return time.Second * time.Duration(timeoutVal)
+}