Skip to content

Commit

Permalink
Tune output of bundle deploy command (#1047)
Browse files Browse the repository at this point in the history
## 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/[email protected]/.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/[email protected]/.bundle/my_project/dev/files!

Starting resource deployment
Resource deployment completed!
```
  • Loading branch information
lennartkats-db authored Dec 21, 2023
1 parent 42f21d8 commit 875c9d2
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 11 deletions.
5 changes: 3 additions & 2 deletions bundle/artifacts/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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))
}
}
Expand Down
7 changes: 3 additions & 4 deletions bundle/artifacts/whl/autodetect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion bundle/artifacts/whl/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions bundle/deploy/files/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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
Expand All @@ -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
}

Expand Down
5 changes: 3 additions & 2 deletions bundle/deploy/terraform/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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 {
Expand All @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions bundle/deploy/terraform/state_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down
27 changes: 27 additions & 0 deletions bundle/log_string.go
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions bundle/phases/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func Deploy() bundle.Mutator {
lock.Release(lock.GoalDeploy),
),
scripts.Execute(config.ScriptPostDeploy),
bundle.LogString("Deployment complete!"),
)

return newPhase(
Expand Down
1 change: 1 addition & 0 deletions bundle/phases/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func Destroy() bundle.Mutator {
),
lock.Release(lock.GoalDestroy),
),
bundle.LogString("Destroy complete!"),
)

return newPhase(
Expand Down

0 comments on commit 875c9d2

Please sign in to comment.