From a2b14f733dc37639ed644ec3b87727ffbde51fd6 Mon Sep 17 00:00:00 2001 From: Lionello Lunesu Date: Tue, 14 Jan 2025 19:29:05 -0800 Subject: [PATCH] Fix cd cancel and cd refresh --- src/cmd/cli/command/cd.go | 34 ++++++++++++++++++-------- src/pkg/cli/client/byoc/aws/byoc.go | 2 ++ src/pkg/cli/client/byoc/gcp/byoc.go | 2 ++ src/pkg/clouds/do/appPlatform/setup.go | 2 +- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/cmd/cli/command/cd.go b/src/cmd/cli/command/cd.go index 0a747fc3..2081e114 100644 --- a/src/cmd/cli/command/cd.go +++ b/src/cmd/cli/command/cd.go @@ -18,8 +18,8 @@ var cdCmd = &cobra.Command{ var cdDestroyCmd = &cobra.Command{ Use: "destroy", - Annotations: authNeededAnnotation, - Args: cobra.NoArgs, // TODO: set MaximumNArgs(1), + Annotations: authNeededAnnotation, // need subscription + Args: cobra.NoArgs, // TODO: set MaximumNArgs(1), Short: "Destroy the service stack", RunE: func(cmd *cobra.Command, args []string) error { loader := configureLoader(cmd) @@ -44,8 +44,8 @@ var cdDestroyCmd = &cobra.Command{ var cdDownCmd = &cobra.Command{ Use: "down", - Annotations: authNeededAnnotation, - Args: cobra.NoArgs, // TODO: set MaximumNArgs(1), + Annotations: authNeededAnnotation, // need subscription + Args: cobra.NoArgs, // TODO: set MaximumNArgs(1), Short: "Refresh and then destroy the service stack", RunE: func(cmd *cobra.Command, args []string) error { loader := configureLoader(cmd) @@ -69,9 +69,10 @@ var cdDownCmd = &cobra.Command{ } var cdRefreshCmd = &cobra.Command{ - Use: "refresh", - Args: cobra.NoArgs, // TODO: set MaximumNArgs(1), - Short: "Refresh the service stack", + Use: "refresh", + Annotations: authNeededAnnotation, // need subscription + Args: cobra.NoArgs, // TODO: set MaximumNArgs(1), + Short: "Refresh the service stack", RunE: func(cmd *cobra.Command, args []string) error { loader := configureLoader(cmd) provider, err := getProvider(cmd.Context(), loader) @@ -83,14 +84,21 @@ var cdRefreshCmd = &cobra.Command{ if err != nil { return err } + + err = canIUseProvider(cmd.Context(), provider, projectName) + if err != nil { + return err + } + return cli.BootstrapCommand(cmd.Context(), projectName, client, provider, "refresh") }, } var cdCancelCmd = &cobra.Command{ - Use: "cancel", - Args: cobra.NoArgs, // TODO: set MaximumNArgs(1), - Short: "Cancel the current CD operation", + Use: "cancel", + Annotations: authNeededAnnotation, // need subscription + Args: cobra.NoArgs, // TODO: set MaximumNArgs(1), + Short: "Cancel the current CD operation", RunE: func(cmd *cobra.Command, args []string) error { loader := configureLoader(cmd) provider, err := getProvider(cmd.Context(), loader) @@ -102,6 +110,12 @@ var cdCancelCmd = &cobra.Command{ if err != nil { return err } + + err = canIUseProvider(cmd.Context(), provider, projectName) + if err != nil { + return err + } + return cli.BootstrapCommand(cmd.Context(), projectName, client, provider, "cancel") }, } diff --git a/src/pkg/cli/client/byoc/aws/byoc.go b/src/pkg/cli/client/byoc/aws/byoc.go index da99105b..2e0d48ad 100644 --- a/src/pkg/cli/client/byoc/aws/byoc.go +++ b/src/pkg/cli/client/byoc/aws/byoc.go @@ -137,6 +137,8 @@ func (b *ByocAws) setUpCD(ctx context.Context) error { return nil } + term.Debugf("Using CD image: %q", b.CDImage) + cdTaskName := byoc.CdTaskPrefix containers := []types.Container{ { diff --git a/src/pkg/cli/client/byoc/gcp/byoc.go b/src/pkg/cli/client/byoc/gcp/byoc.go index 1fe9da14..00d5a2b2 100644 --- a/src/pkg/cli/client/byoc/gcp/byoc.go +++ b/src/pkg/cli/client/byoc/gcp/byoc.go @@ -188,6 +188,8 @@ func (b *ByocGcp) setUpCD(ctx context.Context) error { } // 5. Setup Cloud Run Job + term.Debugf("Using CD image: %q", b.CDImage) + serviceAccount := path.Base(b.cdServiceAccount) if err := b.driver.SetupJob(ctx, "defang-cd", serviceAccount, []types.Container{ { diff --git a/src/pkg/clouds/do/appPlatform/setup.go b/src/pkg/clouds/do/appPlatform/setup.go index d7c4b904..af8bbb38 100644 --- a/src/pkg/clouds/do/appPlatform/setup.go +++ b/src/pkg/clouds/do/appPlatform/setup.go @@ -98,7 +98,7 @@ func shellQuote(args ...string) string { } func getImageSourceSpec(cdImagePath string) (*godo.ImageSourceSpec, error) { - term.Debugf("Using CD image: %s", cdImagePath) + term.Debugf("Using CD image: %q", cdImagePath) image, err := ParseImage(cdImagePath) if err != nil { return nil, err