Skip to content

Commit

Permalink
Prototype for in-place deployments in DEV mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyakuz-db committed Nov 5, 2024
1 parent 2bbdd04 commit 6b22fde
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
10 changes: 10 additions & 0 deletions bundle/config/mutator/apply_presets.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/libs/diag"
"github.com/databricks/cli/libs/dyn"
"github.com/databricks/cli/libs/env"
"github.com/databricks/cli/libs/textutil"
"github.com/databricks/databricks-sdk-go/service/catalog"
"github.com/databricks/databricks-sdk-go/service/jobs"
Expand Down Expand Up @@ -221,6 +222,15 @@ func (m *applyPresets) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos
dashboard.DisplayName = prefix + dashboard.DisplayName
}

root := b.SyncRoot.Native()
_, ok := env.Lookup(ctx, envDatabricksRuntimeVersion)
isInWorkspace := ok && strings.HasPrefix(root, "/Workspace/")

if !isInWorkspace {
disabled := false
b.Config.Presets.InPlaceDeployment = &disabled
}

return diags
}

Expand Down
5 changes: 5 additions & 0 deletions bundle/config/mutator/process_target_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func transformDevelopmentMode(ctx context.Context, b *bundle.Bundle) {
t.TriggerPauseStatus = config.Paused
}

if !config.IsExplicitlyDisabled(t.InPlaceDeployment) {
enabled := true
t.InPlaceDeployment = &enabled
}

if !config.IsExplicitlyDisabled(t.PipelinesDevelopment) {
enabled := true
t.PipelinesDevelopment = &enabled
Expand Down
23 changes: 23 additions & 0 deletions bundle/config/mutator/translate_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"strings"

"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/libraries"
"github.com/databricks/cli/libs/diag"
"github.com/databricks/cli/libs/dyn"
"github.com/databricks/cli/libs/notebook"
Expand Down Expand Up @@ -129,6 +131,9 @@ func (t *translateContext) translateNotebookPath(literal, localFullPath, localRe
return "", ErrIsNotNotebook{localFullPath}
}

if t.shouldTranslateRemotePaths(localFullPath) {
return localFullPath, nil
}
// Upon import, notebooks are stripped of their extension.
return strings.TrimSuffix(remotePath, filepath.Ext(localFullPath)), nil
}
Expand All @@ -144,6 +149,9 @@ func (t *translateContext) translateFilePath(literal, localFullPath, localRelPat
if nb {
return "", ErrIsNotebook{localFullPath}
}
if t.shouldTranslateRemotePaths(localFullPath) {
return localFullPath, nil
}
return remotePath, nil
}

Expand All @@ -155,10 +163,16 @@ func (t *translateContext) translateDirectoryPath(literal, localFullPath, localR
if !info.IsDir() {
return "", fmt.Errorf("%s is not a directory", localFullPath)
}
if t.shouldTranslateRemotePaths(localFullPath) {
return localFullPath, nil
}
return remotePath, nil
}

func (t *translateContext) translateNoOp(literal, localFullPath, localRelPath, remotePath string) (string, error) {
if t.shouldTranslateRemotePaths(localFullPath) {
return localFullPath, nil
}
return localRelPath, nil
}

Expand All @@ -177,6 +191,10 @@ func (t *translateContext) retainLocalAbsoluteFilePath(literal, localFullPath, l
}

func (t *translateContext) translateNoOpWithPrefix(literal, localFullPath, localRelPath, remotePath string) (string, error) {
if t.shouldTranslateRemotePaths(localFullPath) {
return localFullPath, nil
}

if !strings.HasPrefix(localRelPath, ".") {
localRelPath = "." + string(filepath.Separator) + localRelPath
}
Expand Down Expand Up @@ -217,6 +235,11 @@ func (t *translateContext) rewriteRelativeTo(p dyn.Path, v dyn.Value, fn rewrite
return dyn.InvalidValue, err
}

func (t *translateContext) shouldTranslateRemotePaths(localFullPath string) bool {
return config.IsExplicitlyEnabled(t.b.Config.Presets.InPlaceDeployment) &&
libraries.IsWorkspacePath(localFullPath)
}

func (m *translatePaths) Apply(_ context.Context, b *bundle.Bundle) diag.Diagnostics {
t := &translateContext{
b: b,
Expand Down
5 changes: 5 additions & 0 deletions bundle/config/presets.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ type Presets struct {
// JobsMaxConcurrentRuns is the default value for the max concurrent runs of jobs.
JobsMaxConcurrentRuns int `json:"jobs_max_concurrent_runs,omitempty"`

// InPlaceDeployment indicates whether in-place deployment is enabled. Works only in workspace
// When set to true, resources created during deployment will point to source files in the workspace instead of their workspace copies.
// No resources will be uploaded to workspace
InPlaceDeployment *bool `json:"in_place_deployment,omitempty"`

// Tags to add to all resources.
Tags map[string]string `json:"tags,omitempty"`
}
Expand Down
6 changes: 6 additions & 0 deletions bundle/deploy/files/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/fs"

"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/permissions"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/diag"
Expand All @@ -23,6 +24,11 @@ func (m *upload) Name() string {
}

func (m *upload) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
if config.IsExplicitlyEnabled(b.Config.Presets.InPlaceDeployment) {
cmdio.LogString(ctx, "Bundle files uploading skipped: in-place deployment is enabled")
return nil
}

cmdio.LogString(ctx, fmt.Sprintf("Uploading bundle files to %s...", b.Config.Workspace.FilePath))
opts, err := GetSyncOptions(ctx, bundle.ReadOnly(b))
if err != nil {
Expand Down

0 comments on commit 6b22fde

Please sign in to comment.