Jelajahi Sumber

include necessary fields for build settings update (#3994)

ianedwards 2 tahun lalu
induk
melakukan
4897f91df9

+ 25 - 1
api/server/handlers/porter_app/update_build_settings.go

@@ -9,6 +9,7 @@ import (
 	"github.com/porter-dev/porter/api/server/shared"
 	"github.com/porter-dev/porter/api/server/shared/apierrors"
 	"github.com/porter-dev/porter/api/server/shared/config"
+	"github.com/porter-dev/porter/api/server/shared/requestutils"
 	"github.com/porter-dev/porter/api/types"
 	"github.com/porter-dev/porter/internal/models"
 	"github.com/porter-dev/porter/internal/telemetry"
@@ -32,7 +33,8 @@ func NewUpdateAppBuildSettingsHandler(
 
 // UpdateAppBuildSettingsRequest is the request object for the POST /apps/{porter_app_name}/build endpoint
 type UpdateAppBuildSettingsRequest struct {
-	BuildSettings BuildSettings `json:"build_settings"`
+	DeploymentTargetID string        `json:"deployment_target_id"`
+	BuildSettings      BuildSettings `json:"build_settings"`
 }
 
 // UpdateAppBuildSettingsResponse is the response object for the POST /apps/{porter_app_name}/build endpoint
@@ -45,6 +47,13 @@ func (c *UpdateAppBuildSettingsHandler) ServeHTTP(w http.ResponseWriter, r *http
 
 	project, _ := ctx.Value(types.ProjectScope).(*models.Project)
 
+	appName, reqErr := requestutils.GetURLParamString(r, types.URLParamPorterAppName)
+	if reqErr != nil {
+		e := telemetry.Error(ctx, span, reqErr, "error parsing app name from url")
+		c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(e, http.StatusBadRequest))
+		return
+	}
+
 	// read the request object from the decoder
 	request := &UpdateAppBuildSettingsRequest{}
 	if ok := c.DecodeAndValidate(w, r, request); !ok {
@@ -53,8 +62,20 @@ func (c *UpdateAppBuildSettingsHandler) ServeHTTP(w http.ResponseWriter, r *http
 		return
 	}
 
+	if request.DeploymentTargetID == "" {
+		err := telemetry.Error(ctx, span, nil, "deployment target id is empty")
+		c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
+		return
+	}
+	if request.BuildSettings.Method == "" {
+		err := telemetry.Error(ctx, span, nil, "build method must be specified")
+		c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
+		return
+	}
+
 	updateReq := connect.NewRequest(&porterv1.UpdateAppBuildSettingsRequest{
 		ProjectId: int64(project.ID),
+		AppName:   appName,
 		Build: &porterv1.Build{
 			Method:     request.BuildSettings.Method,
 			Context:    request.BuildSettings.Context,
@@ -63,6 +84,9 @@ func (c *UpdateAppBuildSettingsHandler) ServeHTTP(w http.ResponseWriter, r *http
 			Buildpacks: request.BuildSettings.Buildpacks,
 			CommitSha:  request.BuildSettings.CommitSHA,
 		},
+		DeploymentTargetIdentifier: &porterv1.DeploymentTargetIdentifier{
+			Id: request.DeploymentTargetID,
+		},
 	})
 
 	ccpResp, err := c.Config().ClusterControlPlaneClient.UpdateAppBuildSettings(ctx, updateReq)

+ 6 - 1
dashboard/src/main/home/app-dashboard/app-view/AppDataContainer.tsx

@@ -280,6 +280,7 @@ const AppDataContainer: React.FC<AppDataContainerProps> = ({ tabParam }) => {
             "<token>",
             {
               build_settings: validatedAppProto.build,
+              deployment_target_id: deploymentTarget.id,
             },
             {
               project_id: projectId,
@@ -519,7 +520,11 @@ const AppDataContainer: React.FC<AppDataContainerProps> = ({ tabParam }) => {
 
     base.push({ label: "Settings", value: "settings" });
     return base;
-  }, [deploymentTarget.isPreview, latestProto.build, latestNotifications.length]);
+  }, [
+    deploymentTarget.isPreview,
+    latestProto.build,
+    latestNotifications.length,
+  ]);
 
   useEffect(() => {
     const newProto = previewRevision

+ 1 - 0
dashboard/src/shared/api.tsx

@@ -1060,6 +1060,7 @@ const updateBuildSettings = baseApi<
       builder: string;
       buildpacks: string[];
     };
+    deployment_target_id: string;
   },
   {
     project_id: number;