|
@@ -11,6 +11,7 @@ import (
|
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/porter-dev/porter/api/server/handlers/porter_app"
|
|
"github.com/porter-dev/porter/api/server/handlers/porter_app"
|
|
|
|
|
+ "github.com/porter-dev/porter/api/types"
|
|
|
|
|
|
|
|
"github.com/cli/cli/git"
|
|
"github.com/cli/cli/git"
|
|
|
|
|
|
|
@@ -105,6 +106,8 @@ func Apply(ctx context.Context, cliConf config.CLIConfig, client api.Client, por
|
|
|
if applyResp.CLIAction == porterv1.EnumCLIAction_ENUM_CLI_ACTION_BUILD {
|
|
if applyResp.CLIAction == porterv1.EnumCLIAction_ENUM_CLI_ACTION_BUILD {
|
|
|
color.New(color.FgGreen).Printf("Building new image...\n") // nolint:errcheck,gosec
|
|
color.New(color.FgGreen).Printf("Building new image...\n") // nolint:errcheck,gosec
|
|
|
|
|
|
|
|
|
|
+ eventID, _ := createBuildEvent(ctx, client, appName, cliConf.Project, cliConf.Cluster)
|
|
|
|
|
+
|
|
|
if commitSHA == "" {
|
|
if commitSHA == "" {
|
|
|
return errors.New("Build is required but commit SHA cannot be identified. Please set the PORTER_COMMIT_SHA environment variable or run apply in git repository with access to the git CLI.")
|
|
return errors.New("Build is required but commit SHA cannot be identified. Please set the PORTER_COMMIT_SHA environment variable or run apply in git repository with access to the git CLI.")
|
|
|
}
|
|
}
|
|
@@ -138,11 +141,14 @@ func Apply(ctx context.Context, cliConf config.CLIConfig, client api.Client, por
|
|
|
|
|
|
|
|
err = build(ctx, client, buildSettings)
|
|
err = build(ctx, client, buildSettings)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
|
|
+ _ = updateExistingEvent(ctx, client, appName, cliConf.Project, cliConf.Cluster, eventID, types.PorterAppEventStatus_Failed, nil)
|
|
|
return fmt.Errorf("error building app: %w", err)
|
|
return fmt.Errorf("error building app: %w", err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
color.New(color.FgGreen).Printf("Successfully built image (tag: %s)\n", buildSettings.ImageTag) // nolint:errcheck,gosec
|
|
color.New(color.FgGreen).Printf("Successfully built image (tag: %s)\n", buildSettings.ImageTag) // nolint:errcheck,gosec
|
|
|
|
|
|
|
|
|
|
+ _ = updateExistingEvent(ctx, client, appName, cliConf.Project, cliConf.Cluster, eventID, types.PorterAppEventStatus_Success, nil)
|
|
|
|
|
+
|
|
|
applyResp, err = client.ApplyPorterApp(ctx, cliConf.Project, cliConf.Cluster, "", "", applyResp.AppRevisionId)
|
|
applyResp, err = client.ApplyPorterApp(ctx, cliConf.Project, cliConf.Cluster, "", "", applyResp.AppRevisionId)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return fmt.Errorf("apply error post-build: %w", err)
|
|
return fmt.Errorf("apply error post-build: %w", err)
|
|
@@ -153,6 +159,9 @@ func Apply(ctx context.Context, cliConf config.CLIConfig, client api.Client, por
|
|
|
color.New(color.FgGreen).Printf("Waiting for predeploy to complete...\n") // nolint:errcheck,gosec
|
|
color.New(color.FgGreen).Printf("Waiting for predeploy to complete...\n") // nolint:errcheck,gosec
|
|
|
|
|
|
|
|
now := time.Now().UTC()
|
|
now := time.Now().UTC()
|
|
|
|
|
+ eventID, _ := createPredeployEvent(ctx, client, appName, cliConf.Project, cliConf.Cluster, now)
|
|
|
|
|
+
|
|
|
|
|
+ eventStatus := types.PorterAppEventStatus_Success
|
|
|
for {
|
|
for {
|
|
|
if time.Since(now) > checkPredeployTimeout {
|
|
if time.Since(now) > checkPredeployTimeout {
|
|
|
return errors.New("timed out waiting for predeploy to complete")
|
|
return errors.New("timed out waiting for predeploy to complete")
|
|
@@ -163,13 +172,21 @@ func Apply(ctx context.Context, cliConf config.CLIConfig, client api.Client, por
|
|
|
return fmt.Errorf("error calling predeploy status endpoint: %w", err)
|
|
return fmt.Errorf("error calling predeploy status endpoint: %w", err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if predeployStatusResp.Status == porter_app.PredeployStatus_Failed || predeployStatusResp.Status == porter_app.PredeployStatus_Successful {
|
|
|
|
|
|
|
+ if predeployStatusResp.Status == porter_app.PredeployStatus_Failed {
|
|
|
|
|
+ eventStatus = types.PorterAppEventStatus_Failed
|
|
|
|
|
+ break
|
|
|
|
|
+ }
|
|
|
|
|
+ if predeployStatusResp.Status == porter_app.PredeployStatus_Successful {
|
|
|
break
|
|
break
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(checkPredeployFrequency)
|
|
time.Sleep(checkPredeployFrequency)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ metadata := make(map[string]interface{})
|
|
|
|
|
+ metadata["end_time"] = time.Now().UTC()
|
|
|
|
|
+ _ = updateExistingEvent(ctx, client, appName, cliConf.Project, cliConf.Cluster, eventID, eventStatus, metadata)
|
|
|
|
|
+
|
|
|
applyResp, err = client.ApplyPorterApp(ctx, cliConf.Project, cliConf.Cluster, "", "", applyResp.AppRevisionId)
|
|
applyResp, err = client.ApplyPorterApp(ctx, cliConf.Project, cliConf.Cluster, "", "", applyResp.AppRevisionId)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return fmt.Errorf("apply error post-predeploy: %w", err)
|
|
return fmt.Errorf("apply error post-predeploy: %w", err)
|