Răsfoiți Sursa

move build success to end of post apply (#3331)

Feroze Mohideen 2 ani în urmă
părinte
comite
569718a543
1 a modificat fișierele cu 14 adăugiri și 10 ștergeri
  1. 14 10
      cli/cmd/stack/hooks.go

+ 14 - 10
cli/cmd/stack/hooks.go

@@ -47,14 +47,6 @@ func (t *DeployAppHook) DataQueries() map[string]interface{} {
 
 // deploy the app
 func (t *DeployAppHook) PostApply(driverOutput map[string]interface{}) error {
-	eventRequest := types.CreateOrUpdatePorterAppEventRequest{
-		Status:   "SUCCESS",
-		Type:     types.PorterAppEventType_Build,
-		Metadata: map[string]any{},
-		ID:       t.BuildEventID,
-	}
-	_, _ = t.Client.CreateOrUpdatePorterAppEvent(context.Background(), t.ProjectID, t.ClusterID, t.ApplicationName, &eventRequest)
-
 	namespace := fmt.Sprintf("porter-stack-%s", t.ApplicationName)
 
 	_, err := t.Client.GetRelease(
@@ -73,10 +65,22 @@ func (t *DeployAppHook) PostApply(driverOutput map[string]interface{}) error {
 		color.New(color.FgGreen).Printf("Found release for app %s: attempting update\n", t.ApplicationName)
 	}
 
-	return t.applyApp(shouldCreate, driverOutput)
+	err = t.createOrUpdateApplication(shouldCreate, driverOutput)
+	if err != nil {
+		return err
+	}
+	eventRequest := types.CreateOrUpdatePorterAppEventRequest{
+		Status:   "SUCCESS",
+		Type:     types.PorterAppEventType_Build,
+		Metadata: map[string]any{},
+		ID:       t.BuildEventID,
+	}
+	_, _ = t.Client.CreateOrUpdatePorterAppEvent(context.Background(), t.ProjectID, t.ClusterID, t.ApplicationName, &eventRequest)
+
+	return nil
 }
 
-func (t *DeployAppHook) applyApp(shouldCreate bool, driverOutput map[string]interface{}) error {
+func (t *DeployAppHook) createOrUpdateApplication(shouldCreate bool, driverOutput map[string]interface{}) error {
 	var imageInfo types.ImageInfo
 	image, ok := driverOutput["image"].(string)
 	// if it contains a $, then it means the query didn't resolve to anything