From ad3f17b8509b5086986437888609eab10663c79d Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Thu, 7 Nov 2024 10:49:23 +1100 Subject: [PATCH] feat: timeout for deploy command Also limit test deploy to 1m to help diagnose issues --- frontend/cli/cmd_deploy.go | 24 +++++++++++++++++++----- internal/integration/actions.go | 2 +- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/frontend/cli/cmd_deploy.go b/frontend/cli/cmd_deploy.go index d010bfb769..b7537952ba 100644 --- a/frontend/cli/cmd_deploy.go +++ b/frontend/cli/cmd_deploy.go @@ -2,6 +2,8 @@ package main import ( "context" + "fmt" + "time" "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/ftlv1connect" "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1beta1/provisioner/provisionerconnect" @@ -10,9 +12,10 @@ import ( ) type deployCmd struct { - Replicas int32 `short:"n" help:"Number of replicas to deploy." default:"1"` - NoWait bool `help:"Do not wait for deployment to complete." default:"false"` - Build buildCmd `embed:""` + Replicas int32 `short:"n" help:"Number of replicas to deploy." default:"1"` + NoWait bool `help:"Do not wait for deployment to complete." default:"false"` + Build buildCmd `embed:""` + Timeout time.Duration `short:"t" help:"Timeout for the deployment."` } func (d *deployCmd) Run( @@ -22,7 +25,13 @@ func (d *deployCmd) Run( schemaClient ftlv1connect.SchemaServiceClient, ) error { // Cancel build engine context to ensure all language plugins are killed. - ctx, cancel := context.WithCancel(ctx) + var cancel context.CancelFunc + if d.Timeout > 0 { + ctx, cancel = context.WithTimeout(ctx, d.Timeout) + defer cancel() + } else { + ctx, cancel = context.WithCancel(ctx) + } defer cancel() engine, err := buildengine.New( ctx, provisionerClient, schemaClient, projConfig, d.Build.Dirs, @@ -32,5 +41,10 @@ func (d *deployCmd) Run( if err != nil { return err } - return engine.BuildAndDeploy(ctx, d.Replicas, !d.NoWait) + + err = engine.BuildAndDeploy(ctx, d.Replicas, !d.NoWait) + if err != nil { + return fmt.Errorf("failed to deploy: %w", err) + } + return nil } diff --git a/internal/integration/actions.go b/internal/integration/actions.go index b68a2ce6a8..c36a5d9aa3 100644 --- a/internal/integration/actions.go +++ b/internal/integration/actions.go @@ -224,7 +224,7 @@ func ExpectError(action Action, expectedErrorMsg ...string) Action { func Deploy(module string) Action { return Chain( func(t testing.TB, ic TestContext) { - args := []string{"deploy"} + args := []string{"deploy", "-t", "4m"} if ic.Provisioner != nil { args = append(args, "--provisioner-endpoint=http://localhost:8893") }