Kaynağa Gözat

build failures hotfix (#3215)

Feroze Mohideen 2 yıl önce
ebeveyn
işleme
f40a6b43f5

+ 22 - 3
api/server/handlers/porter_app/create.go

@@ -140,6 +140,7 @@ func (c *CreatePorterAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
 			stackName:      stackName,
 		},
 		injectLauncher,
+		shouldCreate,
 	)
 	if err != nil {
 		err = telemetry.Error(ctx, span, err, "error parsing porter yaml into chart and values")
@@ -377,9 +378,27 @@ func (c *CreatePorterAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
 			app.BuildContext = request.BuildContext
 		}
 		// handles deletion of builder,buildpacks, and dockerfile path
-		app.Builder = request.Builder
-		app.Buildpacks = request.Buildpacks
-		app.Dockerfile = request.Dockerfile
+		if request.Builder != "" {
+			if request.Builder == "null" {
+				app.Builder = ""
+			} else {
+				app.Builder = request.Builder
+			}
+		}
+		if request.Buildpacks != "" {
+			if request.Buildpacks == "null" {
+				app.Buildpacks = ""
+			} else {
+				app.Buildpacks = request.Buildpacks
+			}
+		}
+		if request.Dockerfile != "" {
+			if request.Dockerfile == "null" {
+				app.Dockerfile = ""
+			} else {
+				app.Dockerfile = request.Dockerfile
+			}
+		}
 		if request.ImageRepoURI != "" {
 			app.ImageRepoURI = request.ImageRepoURI
 		}

+ 30 - 19
api/server/handlers/porter_app/parse.go

@@ -58,6 +58,7 @@ func parse(
 	existingDependencies []*chart.Dependency,
 	opts SubdomainCreateOpts,
 	injectLauncher bool,
+	shouldCreate bool,
 ) (*chart.Chart, map[string]interface{}, map[string]interface{}, error) {
 	parsed := &PorterStackYAML{}
 
@@ -66,7 +67,7 @@ func parse(
 		return nil, nil, nil, fmt.Errorf("%s: %w", "error parsing porter.yaml", err)
 	}
 
-	values, err := buildUmbrellaChartValues(parsed, imageInfo, existingValues, opts, injectLauncher)
+	values, err := buildUmbrellaChartValues(parsed, imageInfo, existingValues, opts, injectLauncher, shouldCreate)
 	if err != nil {
 		return nil, nil, nil, fmt.Errorf("%s: %w", "error building values from porter.yaml", err)
 	}
@@ -86,7 +87,14 @@ func parse(
 	return chart, convertedValues, preDeployJobValues, nil
 }
 
-func buildUmbrellaChartValues(parsed *PorterStackYAML, imageInfo types.ImageInfo, existingValues map[string]interface{}, opts SubdomainCreateOpts, injectLauncher bool) (map[string]interface{}, error) {
+func buildUmbrellaChartValues(
+	parsed *PorterStackYAML,
+	imageInfo types.ImageInfo,
+	existingValues map[string]interface{},
+	opts SubdomainCreateOpts,
+	injectLauncher bool,
+	shouldCreate bool,
+) (map[string]interface{}, error) {
 	values := make(map[string]interface{})
 
 	if parsed.Apps == nil {
@@ -110,7 +118,7 @@ func buildUmbrellaChartValues(parsed *PorterStackYAML, imageInfo types.ImageInfo
 			}
 		}
 
-		validateErr := validateHelmValues(helm_values)
+		validateErr := validateHelmValues(helm_values, shouldCreate)
 		if validateErr != "" {
 			return nil, fmt.Errorf("error validating service \"%s\": %s", name, validateErr)
 		}
@@ -167,24 +175,27 @@ func buildUmbrellaChartValues(parsed *PorterStackYAML, imageInfo types.ImageInfo
 }
 
 // we can add to this function up later or use an alternative
-func validateHelmValues(values map[string]interface{}) string {
-	containerMap, err := getNestedMap(values, "container")
-	if err != nil {
-		return "error checking port: misformatted values"
-	} else {
-		portVal, portExists := containerMap["port"]
-		if portExists {
-			portStr, pOK := portVal.(string)
-			if !pOK {
-				return "error checking port: no port in container"
-			}
+func validateHelmValues(values map[string]interface{}, shouldCreate bool) string {
+	// currently, we only validate port on initial app create, because this will break any updates to existing apps with lower port numbers
+	if shouldCreate {
+		containerMap, err := getNestedMap(values, "container")
+		if err != nil {
+			return "error checking port: misformatted values"
+		} else {
+			portVal, portExists := containerMap["port"]
+			if portExists {
+				portStr, pOK := portVal.(string)
+				if !pOK {
+					return "error checking port: no port in container"
+				}
 
-			port, err := strconv.Atoi(portStr)
-			if err != nil || port < 1024 || port > 65535 {
-				return "port must be a number between 1024 and 65535"
+				port, err := strconv.Atoi(portStr)
+				if err != nil || port < 1024 || port > 65535 {
+					return "port must be a number between 1024 and 65535"
+				}
+			} else {
+				return "must specify port if choosing to expose service externally"
 			}
-		} else {
-			return "must specify port if choosing to expose service externally"
 		}
 	}
 	return ""

+ 1 - 0
dashboard/src/main/home/app-dashboard/build-settings/buildpacks/BuildpackSettings.tsx

@@ -48,6 +48,7 @@ const BuildpackSettings: React.FC<{
           // in this case, we are not detecting buildpacks, so we just populate based on the DB
           if (porterApp.builder != null) {
             setSelectedStack(porterApp.builder);
+            setStackOptions([{ label: porterApp.builder, value: porterApp.builder }]);
           }
           if (porterApp.buildpacks != null) {
             setSelectedBuildpacks(porterApp.buildpacks.map(bp => ({

+ 3 - 0
dashboard/src/main/home/app-dashboard/expanded-app/ExpandedApp.tsx

@@ -348,9 +348,12 @@ const ExpandedApp: React.FC<Props> = ({ ...props }) => {
         }
         if (buildView === "docker") {
           updatedPorterApp.dockerfile = tempPorterApp.dockerfile;
+          updatedPorterApp.builder = "null";
+          updatedPorterApp.buildpacks = "null";
         } else {
           updatedPorterApp.builder = tempPorterApp.builder;
           updatedPorterApp.buildpacks = tempPorterApp.buildpacks.join(",");
+          updatedPorterApp.dockerfile = "null";
         }
 
         await api.createPorterApp(