From 857c618d4bdf6ba822cd0eebdde7c04ed17953f8 Mon Sep 17 00:00:00 2001 From: Pedro Enrique Date: Tue, 22 Jul 2025 18:19:36 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Added=20=E2=80=94dry-run=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/cloud.go | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/cmd/cloud.go b/cmd/cloud.go index da820403..96fc9557 100644 --- a/cmd/cloud.go +++ b/cmd/cloud.go @@ -167,12 +167,14 @@ and starts the deployment process. It will reconcile any differences between local and remote agents. Flags: - --dir The directory containing the project to deploy + --dir The directory containing the project to deploy + --dry-run Save deployment zip file to specified directory instead of uploading Examples: agentuity cloud deploy agentuity deploy - agentuity cloud deploy --dir /path/to/project`, + agentuity cloud deploy --dir /path/to/project + agentuity deploy --dry-run ./output`, Run: func(cmd *cobra.Command, args []string) { parentCtx := context.Background() ctx, cancel := signal.NotifyContext(parentCtx, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) @@ -195,6 +197,7 @@ Examples: tags, _ := cmd.Flags().GetStringArray("tag") description, _ := cmd.Flags().GetString("description") message, _ := cmd.Flags().GetString("message") + dryRun, _ := cmd.Flags().GetString("dry-run") // remove duplicates and empty strings tags = util.RemoveDuplicates(tags) @@ -535,6 +538,37 @@ Examples: tui.ShowSpinner("Packaging ...", zipaction) + // Handle dry-run case - check if flag was specified + dryRunSpecified := cmd.Flags().Changed("dry-run") + if dryRunSpecified { + // Default to current directory if empty string + if dryRun == "" { + dryRun = "." + } + + // Create the output filename + outputFile := filepath.Join(dryRun, fmt.Sprintf("agentuity-deploy-%s.zip", theproject.ProjectId)) + + // Copy the zip file to the specified location + if _, err := util.CopyFile(tmpfile.Name(), outputFile); err != nil { + errsystem.New(errsystem.ErrCreateZipFile, err, + errsystem.WithContextMessage("Error copying deployment zip file")).ShowErrorAndExit() + } + + format, _ := cmd.Flags().GetString("format") + if format == "json" { + result := map[string]interface{}{ + "dry_run": true, + "zip_file": outputFile, + "project_id": theproject.ProjectId, + } + json.NewEncoder(os.Stdout).Encode(result) + } else { + tui.ShowSuccess("Deployment zip saved to: %s", outputFile) + } + return + } + dof, err := os.Open(tmpfile.Name()) if err != nil { errsystem.New(errsystem.ErrOpenFile, err, @@ -972,6 +1006,7 @@ func init() { cloudDeployCmd.Flags().String("description", "", "Description for the deployment") cloudDeployCmd.Flags().String("message", "", "A shorter description for the deployment") cloudDeployCmd.Flags().Bool("force", false, "Force the processing of environment files") + cloudDeployCmd.Flags().String("dry-run", "", "Save deployment zip file to specified directory (defaults to current directory) instead of uploading") cloudDeployCmd.Flags().MarkHidden("deploymentId") cloudDeployCmd.Flags().MarkHidden("ci") From 5be73a97fbab44bca2b02d631c6b3c6864f52c76 Mon Sep 17 00:00:00 2001 From: Pedro Enrique Date: Tue, 22 Jul 2025 18:21:02 +0200 Subject: [PATCH 2/3] unused check --- cmd/cloud.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/cmd/cloud.go b/cmd/cloud.go index 96fc9557..816ef10b 100644 --- a/cmd/cloud.go +++ b/cmd/cloud.go @@ -538,18 +538,10 @@ Examples: tui.ShowSpinner("Packaging ...", zipaction) - // Handle dry-run case - check if flag was specified - dryRunSpecified := cmd.Flags().Changed("dry-run") - if dryRunSpecified { - // Default to current directory if empty string - if dryRun == "" { - dryRun = "." - } + if dryRun != "" { - // Create the output filename outputFile := filepath.Join(dryRun, fmt.Sprintf("agentuity-deploy-%s.zip", theproject.ProjectId)) - // Copy the zip file to the specified location if _, err := util.CopyFile(tmpfile.Name(), outputFile); err != nil { errsystem.New(errsystem.ErrCreateZipFile, err, errsystem.WithContextMessage("Error copying deployment zip file")).ShowErrorAndExit() From 35a9fda9fa4ae14316014c18249b8e2e4e735965 Mon Sep 17 00:00:00 2001 From: Pedro Enrique Date: Tue, 22 Jul 2025 18:29:11 +0200 Subject: [PATCH 3/3] check if dir exists and is writable --- cmd/cloud.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/cloud.go b/cmd/cloud.go index 816ef10b..8e0f0da9 100644 --- a/cmd/cloud.go +++ b/cmd/cloud.go @@ -540,6 +540,14 @@ Examples: if dryRun != "" { + // Validate and create the dryRun directory if it doesn't exist + if !util.Exists(dryRun) { + if err := os.MkdirAll(dryRun, 0755); err != nil { + errsystem.New(errsystem.ErrCreateZipFile, err, + errsystem.WithContextMessage(fmt.Sprintf("Error creating dry run directory '%s': %v", dryRun, err))).ShowErrorAndExit() + } + } + outputFile := filepath.Join(dryRun, fmt.Sprintf("agentuity-deploy-%s.zip", theproject.ProjectId)) if _, err := util.CopyFile(tmpfile.Name(), outputFile); err != nil {