Просмотр исходного кода

Merge branch 'master' into nafees/cli-improvements

Mohammed Nafees 4 лет назад
Родитель
Сommit
4644694ca9
3 измененных файлов с 71 добавлено и 36 удалено
  1. 47 26
      cli/cmd/deploy/create.go
  2. 12 6
      cli/cmd/deploy/deploy.go
  3. 12 4
      cli/cmd/preview/build_image_driver.go

+ 47 - 26
cli/cmd/deploy/create.go

@@ -278,12 +278,20 @@ func (c *CreateAgent) CreateFromDocker(
 		env = make(map[string]string)
 	}
 
-	buildEnv, err := GetNestedMap(mergedValues, "container", "env", "build")
+	envConfig, err := GetNestedMap(mergedValues, "container", "env")
 
 	if err == nil {
-		for key, val := range buildEnv {
-			if valStr, ok := val.(string); ok {
-				env[key] = valStr
+		_, exists := envConfig["build"]
+
+		if exists {
+			buildEnv, err := GetNestedMap(mergedValues, "container", "env", "build")
+
+			if err == nil {
+				for key, val := range buildEnv {
+					if valStr, ok := val.(string); ok {
+						env[key] = valStr
+					}
+				}
 			}
 		}
 	}
@@ -520,33 +528,46 @@ func (c *CreateAgent) CreateSubdomainIfRequired(mergedValues map[string]interfac
 				enabled, eOK := enabledVal.(bool)
 				customDomain, cOK := customDomVal.(bool)
 
-				// in the case of ingress enabled but no custom domain, create subdomain
-				if eOK && cOK && enabled && !customDomain {
-					dnsRecord, err := c.Client.CreateDNSRecord(
-						context.Background(),
-						c.CreateOpts.ProjectID,
-						c.CreateOpts.ClusterID,
-						c.CreateOpts.Namespace,
-						c.CreateOpts.ReleaseName,
-					)
-
-					if err != nil {
-						return "", fmt.Errorf("Error creating subdomain: %s", err.Error())
-					}
+				if eOK && cOK && enabled {
+					if customDomain {
+						// return the first custom domain when one exists
+						hostsArr, hostsExists := ingressMap["hosts"]
 
-					subdomain = dnsRecord.ExternalURL
+						if hostsExists {
+							hostsArrVal, hostsArrOk := hostsArr.([]string)
 
-					if ingressVal, ok := mergedValues["ingress"]; !ok {
-						mergedValues["ingress"] = map[string]interface{}{
-							"porter_hosts": []string{
-								subdomain,
-							},
+							if hostsArrOk && len(hostsArrVal) > 0 {
+								subdomain = hostsArrVal[0]
+							}
 						}
 					} else {
-						ingressValMap := ingressVal.(map[string]interface{})
+						// in the case of ingress enabled but no custom domain, create subdomain
+						dnsRecord, err := c.Client.CreateDNSRecord(
+							context.Background(),
+							c.CreateOpts.ProjectID,
+							c.CreateOpts.ClusterID,
+							c.CreateOpts.Namespace,
+							c.CreateOpts.ReleaseName,
+						)
+
+						if err != nil {
+							return "", fmt.Errorf("Error creating subdomain: %s", err.Error())
+						}
+
+						subdomain = dnsRecord.ExternalURL
 
-						ingressValMap["porter_hosts"] = []string{
-							subdomain,
+						if ingressVal, ok := mergedValues["ingress"]; !ok {
+							mergedValues["ingress"] = map[string]interface{}{
+								"porter_hosts": []string{
+									subdomain,
+								},
+							}
+						} else {
+							ingressValMap := ingressVal.(map[string]interface{})
+
+							ingressValMap["porter_hosts"] = []string{
+								subdomain,
+							}
 						}
 					}
 				}

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

@@ -173,13 +173,19 @@ func (d *DeployAgent) GetBuildEnv(opts *GetBuildEnvOpts) (map[string]string, err
 		return nil, err
 	}
 
-	if opts.IncludeBuildEnv {
-		buildEnv, err := GetNestedMap(conf, "container", "env", "build")
+	envConfig, err := GetNestedMap(conf, "container", "env")
 
-		if err == nil {
-			for key, val := range buildEnv {
-				if valStr, ok := val.(string); ok {
-					env[key] = valStr
+	if err == nil {
+		_, exists := envConfig["build"]
+
+		if exists {
+			buildEnv, err := GetNestedMap(conf, "container", "env", "build")
+
+			if err == nil {
+				for key, val := range buildEnv {
+					if valStr, ok := val.(string); ok {
+						env[key] = valStr
+					}
 				}
 			}
 		}

+ 12 - 4
cli/cmd/preview/build_image_driver.go

@@ -249,12 +249,20 @@ func (d *BuildDriver) Apply(resource *models.Resource) (*models.Resource, error)
 		env = make(map[string]string)
 	}
 
-	buildEnv, err := deploy.GetNestedMap(mergedValues, "container", "env", "build")
+	envConfig, err := deploy.GetNestedMap(mergedValues, "container", "env")
 
 	if err == nil {
-		for key, val := range buildEnv {
-			if valStr, ok := val.(string); ok {
-				env[key] = valStr
+		_, exists := envConfig["build"]
+
+		if exists {
+			buildEnv, err := deploy.GetNestedMap(mergedValues, "container", "env", "build")
+
+			if err == nil {
+				for key, val := range buildEnv {
+					if valStr, ok := val.(string); ok {
+						env[key] = valStr
+					}
+				}
 			}
 		}
 	}