Skip to content

Commit

Permalink
Created fallback when we cannot find app deployment workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
BSick7 committed Nov 21, 2024
1 parent fb0b5ec commit 6ec1c72
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 0.0.130 (Nov 21, 2024)
* Created fallback when we cannot find app deployment workflow.

# 0.0.129 (Nov 12, 2024)
* Added `nullstone iac generate` command to export workspace config to an IaC file.

Expand Down
10 changes: 8 additions & 2 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"context"
"fmt"
"github.com/mitchellh/colorstring"
"github.com/nullstone-io/deployment-sdk/app"
"github.com/nullstone-io/deployment-sdk/logging"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -113,10 +114,12 @@ func streamDeployIntentLogs(ctx context.Context, osWriters logging.OsWriters, cf
if iw, err = waitForRunningIntentWorkflow(ctx, cfg, iw); err != nil {
return err
} else if iw.Status == types.IntentWorkflowStatusCompleted {
fmt.Fprintln(stderr, "Deployment completed.")
colorstring.Fprintln(stderr, "[green]Deployment completed.[reset]")
return nil
}

colorstring.Fprintln(stderr, "[green]Deployment started.[reset]")

var wflow types.WorkspaceWorkflow
for _, ww := range iw.WorkspaceWorkflows {
if ww.BlockId == appDetails.App.Id && ww.EnvId == appDetails.Env.Id && ww.StackId == appDetails.App.StackId {
Expand All @@ -125,7 +128,10 @@ func streamDeployIntentLogs(ctx context.Context, osWriters logging.OsWriters, cf
}
}
if wflow.Id == 0 {
return fmt.Errorf("deployment workflow is missing")
colorstring.Fprintln(stderr, "[yellow]We cannot find the deployment workflow to report the deployment logs.[reset]")
colorstring.Fprintln(stderr, "[bold]Waiting for successful deployment without reporting deployment logs...[reset]")
iw, err = waitForCompletedIntentWorkflow(ctx, cfg, iw)
return err
}

activities, err := client.WorkspaceWorkflows().GetActivities(ctx, wflow.StackId, wflow.BlockId, wflow.EnvId, wflow.Id)
Expand Down
27 changes: 27 additions & 0 deletions cmd/wait_for.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,33 @@ func waitForRunningIntentWorkflow(ctx context.Context, cfg api.Config, iw types.
}
}

func waitForCompletedIntentWorkflow(ctx context.Context, cfg api.Config, iw types.IntentWorkflow) (types.IntentWorkflow, error) {
client := api.Client{Config: cfg}
intentWorkflow, ch, err := client.IntentWorkflows().WatchGet(ctx, iw.StackId, iw.Id, ws.RetryInfinite(time.Second))
if err != nil {
return iw, fmt.Errorf("error waiting for deployment: %w", err)
} else if intentWorkflow == nil {
return iw, context.Canceled
}

cur := *intentWorkflow
for {
switch cur.Status {
case types.IntentWorkflowStatusCompleted:
return cur, nil
case types.IntentWorkflowStatusFailed:
return cur, fmt.Errorf("Deployment failed: %s", cur.StatusMessage)
case types.IntentWorkflowStatusCancelled:
return cur, fmt.Errorf("Deployment was cancelled.")
}
so := <-ch
if so.Err != nil {
return cur, fmt.Errorf("error waiting for deployment: %w", so.Err)
}
cur = so.Object.ApplyTo(cur)
}
}

func waitForWorkspaceWorkflowRun(ctx context.Context, cfg api.Config, ww types.WorkspaceWorkflow) (types.Run, error) {
client := api.Client{Config: cfg}
workspaceWorkflow, ch, err := client.WorkspaceWorkflows().WatchGet(ctx, ww.StackId, ww.BlockId, ww.EnvId, ww.Id, ws.RetryInfinite(time.Second))
Expand Down

0 comments on commit 6ec1c72

Please sign in to comment.