Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions bundle/deploy/metadata/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package metadata
import (
"context"
"path/filepath"
"strings"

"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
Expand Down Expand Up @@ -83,6 +84,13 @@ func (m *compute) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics
// In source-linked deployment files are not copied and resources use source files, therefore we use sync path as file path in metadata
if config.IsExplicitlyEnabled(b.Config.Presets.SourceLinkedDeployment) {
b.Metadata.Config.Workspace.FilePath = b.SyncRootPath
b.Metadata.Config.Presets.SourceLinkedDeployment = true
}

// Set the git folder path for deployments from the workspace
if b.WorktreeRoot != nil && strings.HasPrefix(b.WorktreeRoot.Native(), "/Workspace/") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI we already have some of this information captured in the metadata today:

b.Config.Bundle.Git.BundleRootPath = filepath.ToSlash(relBundlePath)

Do we need the absolute git folder path separately? Just curious about the usecase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we need to capture the absolute git folder path so we can reconstruct the full path to a resource definition YAML file. e.g. to get the path to a pipeline definition file we combine
GitFolderPath + BundleRootPath + Pipelines[pipelineName].RelativePath

This will be used for breakglass UI where we want to link to where a deployed resource is defined in its DAB

b.Metadata.Extra.GitFolderPath = b.WorktreeRoot.Native()
}

return nil
}
22 changes: 22 additions & 0 deletions bundle/deploy/metadata/compute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package metadata

import (
"context"
"runtime"
"testing"

"github.com/databricks/cli/bundle"
Expand All @@ -10,6 +11,7 @@ import (
"github.com/databricks/cli/bundle/internal/bundletest"
"github.com/databricks/cli/bundle/metadata"
"github.com/databricks/cli/libs/dyn"
"github.com/databricks/cli/libs/vfs"
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/databricks/databricks-sdk-go/service/pipelines"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -136,4 +138,24 @@ func TestComputeMetadataMutatorSourceLinked(t *testing.T) {
require.NoError(t, diags.Error())

assert.Equal(t, syncRootPath, b.Metadata.Config.Workspace.FilePath)
assert.True(t, b.Metadata.Config.Presets.SourceLinkedDeployment)
}

func TestComputeMetadataMutatorGitFolderPath(t *testing.T) {
// The native path of the worktree root on Windows will never match the /Workspace prefix,
// so `GitFolderPath` will never be set and this test will never pass
if runtime.GOOS == "windows" {
t.Skip("this test is not applicable on Windows")
}
gitFolderPath := "/Workspace/Users/test.user@databricks.com/git_folder"
path := vfs.MustNew(gitFolderPath)
b := &bundle.Bundle{
Config: config.Root{},
WorktreeRoot: path,
}

diags := bundle.Apply(context.Background(), b, Compute())
require.NoError(t, diags.Error())

assert.Equal(t, gitFolderPath, b.Metadata.Extra.GitFolderPath)
}
11 changes: 11 additions & 0 deletions bundle/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,19 @@ type Resources struct {
Pipelines map[string]*Resource `json:"pipelines,omitempty"`
}

type Presets struct {
SourceLinkedDeployment bool `json:"source_linked_deployment"`
}

type Config struct {
Bundle Bundle `json:"bundle,omitempty"`
Workspace Workspace `json:"workspace,omitempty"`
Resources Resources `json:"resources,omitempty"`
Presets Presets `json:"presets,omitempty"`
}

type Extra struct {
GitFolderPath string `json:"git_folder_path,omitempty"`
}

// Metadata about the bundle deployment. This is the interface Databricks services
Expand All @@ -43,4 +52,6 @@ type Metadata struct {
Version int `json:"version"`

Config Config `json:"config"`
// Fields that don't map 1-to-1 with the bundle configuration schema
Extra Extra `json:"extra"`
}
Loading