From 875c9d2db13a1d5649627443b935b73c1c854845 Mon Sep 17 00:00:00 2001 From: "Lennart Kats (databricks)" Date: Thu, 21 Dec 2023 09:00:37 +0100 Subject: [PATCH] Tune output of bundle deploy command (#1047) ## Changes Update the output of the `deploy` command to be more concise and consistent: ``` $ databricks bundle deploy Building my_project... Uploading my_project-0.0.1+20231207.205106-py3-none-any.whl... Uploading bundle files to /Users/lennart.kats@databricks.com/.bundle/my_project/dev/files... Deploying resources... Updating deployment state... Deployment complete! ``` This does away with the intermediate success messages, makes consistent use of `...`, and only prints the success message at the very end after everything is completed. Below is the original output for comparison: ``` $ databricks bundle deploy Detecting Python wheel project... Found Python wheel project at /tmp/output/my_project Building my_project... Build succeeded Uploading my_project-0.0.1+20231207.205134-py3-none-any.whl... Upload succeeded Starting upload of bundle files Uploaded bundle files at /Users/lennart.kats@databricks.com/.bundle/my_project/dev/files! Starting resource deployment Resource deployment completed! ``` --- bundle/artifacts/artifacts.go | 5 +++-- bundle/artifacts/whl/autodetect.go | 7 +++---- bundle/artifacts/whl/build.go | 3 ++- bundle/deploy/files/upload.go | 5 +++-- bundle/deploy/terraform/apply.go | 5 +++-- bundle/deploy/terraform/state_push.go | 2 ++ bundle/log_string.go | 27 +++++++++++++++++++++++++++ bundle/phases/deploy.go | 1 + bundle/phases/destroy.go | 1 + 9 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 bundle/log_string.go diff --git a/bundle/artifacts/artifacts.go b/bundle/artifacts/artifacts.go index dd261d3b..76d29f56 100644 --- a/bundle/artifacts/artifacts.go +++ b/bundle/artifacts/artifacts.go @@ -14,6 +14,7 @@ import ( "github.com/databricks/cli/bundle/config" "github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/filer" + "github.com/databricks/cli/libs/log" ) type mutatorFactory = func(name string) bundle.Mutator @@ -67,7 +68,7 @@ func (m *basicBuild) Apply(ctx context.Context, b *bundle.Bundle) error { if err != nil { return fmt.Errorf("build for %s failed, error: %w, output: %s", m.name, err, out) } - cmdio.LogString(ctx, "Build succeeded") + log.Infof(ctx, "Build succeeded") return nil } @@ -124,7 +125,7 @@ func uploadArtifact(ctx context.Context, a *config.Artifact, uploadPath string, if err != nil { return err } - cmdio.LogString(ctx, "Upload succeeded") + log.Infof(ctx, "Upload succeeded") f.RemotePath = path.Join(uploadPath, filepath.Base(f.Source)) } } diff --git a/bundle/artifacts/whl/autodetect.go b/bundle/artifacts/whl/autodetect.go index 7c1c59d4..c858a38c 100644 --- a/bundle/artifacts/whl/autodetect.go +++ b/bundle/artifacts/whl/autodetect.go @@ -11,7 +11,6 @@ import ( "github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle/config" "github.com/databricks/cli/bundle/libraries" - "github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/log" ) @@ -32,17 +31,17 @@ func (m *detectPkg) Apply(ctx context.Context, b *bundle.Bundle) error { log.Infof(ctx, "No local wheel tasks in databricks.yml config, skipping auto detect") return nil } - cmdio.LogString(ctx, "Detecting Python wheel project...") + log.Infof(ctx, "Detecting Python wheel project...") // checking if there is setup.py in the bundle root setupPy := filepath.Join(b.Config.Path, "setup.py") _, err := os.Stat(setupPy) if err != nil { - cmdio.LogString(ctx, "No Python wheel project found at bundle root folder") + log.Infof(ctx, "No Python wheel project found at bundle root folder") return nil } - cmdio.LogString(ctx, fmt.Sprintf("Found Python wheel project at %s", b.Config.Path)) + log.Infof(ctx, fmt.Sprintf("Found Python wheel project at %s", b.Config.Path)) module := extractModuleName(setupPy) if b.Config.Artifacts == nil { diff --git a/bundle/artifacts/whl/build.go b/bundle/artifacts/whl/build.go index c1e7e8fa..aeec31a6 100644 --- a/bundle/artifacts/whl/build.go +++ b/bundle/artifacts/whl/build.go @@ -9,6 +9,7 @@ import ( "github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle/config" "github.com/databricks/cli/libs/cmdio" + "github.com/databricks/cli/libs/log" "github.com/databricks/cli/libs/python" ) @@ -44,7 +45,7 @@ func (m *build) Apply(ctx context.Context, b *bundle.Bundle) error { if err != nil { return fmt.Errorf("build failed %s, error: %w, output: %s", m.name, err, out) } - cmdio.LogString(ctx, "Build succeeded") + log.Infof(ctx, "Build succeeded") wheels := python.FindFilesWithSuffixInPath(distPath, ".whl") if len(wheels) == 0 { diff --git a/bundle/deploy/files/upload.go b/bundle/deploy/files/upload.go index aebbf6d5..26d1ef4b 100644 --- a/bundle/deploy/files/upload.go +++ b/bundle/deploy/files/upload.go @@ -6,6 +6,7 @@ import ( "github.com/databricks/cli/bundle" "github.com/databricks/cli/libs/cmdio" + "github.com/databricks/cli/libs/log" ) type upload struct{} @@ -15,7 +16,7 @@ func (m *upload) Name() string { } func (m *upload) Apply(ctx context.Context, b *bundle.Bundle) error { - cmdio.LogString(ctx, "Starting upload of bundle files") + cmdio.LogString(ctx, fmt.Sprintf("Uploading bundle files to %s...", b.Config.Workspace.FilePath)) sync, err := getSync(ctx, b) if err != nil { return err @@ -26,7 +27,7 @@ func (m *upload) Apply(ctx context.Context, b *bundle.Bundle) error { return err } - cmdio.LogString(ctx, fmt.Sprintf("Uploaded bundle files at %s!\n", b.Config.Workspace.FilePath)) + log.Infof(ctx, "Uploaded bundle files") return nil } diff --git a/bundle/deploy/terraform/apply.go b/bundle/deploy/terraform/apply.go index ab868f76..117cdfc1 100644 --- a/bundle/deploy/terraform/apply.go +++ b/bundle/deploy/terraform/apply.go @@ -6,6 +6,7 @@ import ( "github.com/databricks/cli/bundle" "github.com/databricks/cli/libs/cmdio" + "github.com/databricks/cli/libs/log" "github.com/hashicorp/terraform-exec/tfexec" ) @@ -21,7 +22,7 @@ func (w *apply) Apply(ctx context.Context, b *bundle.Bundle) error { return fmt.Errorf("terraform not initialized") } - cmdio.LogString(ctx, "Starting resource deployment") + cmdio.LogString(ctx, "Deploying resources...") err := tf.Init(ctx, tfexec.Upgrade(true)) if err != nil { @@ -33,7 +34,7 @@ func (w *apply) Apply(ctx context.Context, b *bundle.Bundle) error { return fmt.Errorf("terraform apply: %w", err) } - cmdio.LogString(ctx, "Resource deployment completed!") + log.Infof(ctx, "Resource deployment completed") return nil } diff --git a/bundle/deploy/terraform/state_push.go b/bundle/deploy/terraform/state_push.go index 30a43596..a5140329 100644 --- a/bundle/deploy/terraform/state_push.go +++ b/bundle/deploy/terraform/state_push.go @@ -6,6 +6,7 @@ import ( "path/filepath" "github.com/databricks/cli/bundle" + "github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/filer" "github.com/databricks/cli/libs/log" ) @@ -37,6 +38,7 @@ func (l *statePush) Apply(ctx context.Context, b *bundle.Bundle) error { defer local.Close() // Upload state file from local cache directory to filer. + cmdio.LogString(ctx, "Updating deployment state...") log.Infof(ctx, "Writing local state file to remote state directory") err = f.Write(ctx, TerraformStateFileName, local, filer.CreateParentDirectories, filer.OverwriteIfExists) if err != nil { diff --git a/bundle/log_string.go b/bundle/log_string.go new file mode 100644 index 00000000..63800d6d --- /dev/null +++ b/bundle/log_string.go @@ -0,0 +1,27 @@ +package bundle + +import ( + "context" + + "github.com/databricks/cli/libs/cmdio" +) + +type LogStringMutator struct { + message string +} + +func (d *LogStringMutator) Name() string { + return "log_string" +} + +func LogString(message string) Mutator { + return &LogStringMutator{ + message: message, + } +} + +func (m *LogStringMutator) Apply(ctx context.Context, b *Bundle) error { + cmdio.LogString(ctx, m.message) + + return nil +} diff --git a/bundle/phases/deploy.go b/bundle/phases/deploy.go index 6f0d3a6c..20fe2e41 100644 --- a/bundle/phases/deploy.go +++ b/bundle/phases/deploy.go @@ -45,6 +45,7 @@ func Deploy() bundle.Mutator { lock.Release(lock.GoalDeploy), ), scripts.Execute(config.ScriptPostDeploy), + bundle.LogString("Deployment complete!"), ) return newPhase( diff --git a/bundle/phases/destroy.go b/bundle/phases/destroy.go index 5841916d..216d2921 100644 --- a/bundle/phases/destroy.go +++ b/bundle/phases/destroy.go @@ -24,6 +24,7 @@ func Destroy() bundle.Mutator { ), lock.Release(lock.GoalDestroy), ), + bundle.LogString("Destroy complete!"), ) return newPhase(