Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
75 changes: 10 additions & 65 deletions acceptance/bundle/variables/prepend-workspace-var/output.txt
Original file line number Diff line number Diff line change
@@ -1,67 +1,12 @@
/Workspace should be prepended on all paths, but it is not the case:
Warning: required field "entry_point" is not set
at resources.jobs.my_job.tasks[0].python_wheel_task
in databricks.yml:26:13

Warning: required field "package_name" is not set
at resources.jobs.my_job.tasks[0].python_wheel_task
in databricks.yml:26:13

{
"bundle": {
"environment": "dev",
"git": {
"bundle_root_path": "."
},
"name": "test-bundle",
"target": "dev"
},
"resources": {
"jobs": {
"my_job": {
"deployment": {
"kind": "BUNDLE",
"metadata_file_path": "/Users/[USERNAME]/path/to/root/state/metadata.json"
},
"edit_mode": "UI_LOCKED",
"format": "MULTI_TASK",
"max_concurrent_runs": 1,
"name": "Untitled",
"queue": {
"enabled": true
},
"tasks": [
{
"existing_cluster_id": "500",
"python_wheel_task": {
"named_parameters": {
"conf-file": "/Users/[USERNAME]/path/to/root/files/path/to/config.yaml"
}
},
"task_key": ""
}
]
}
}
},
"sync": {
"paths": [
"."
]
},
"variables": {
"workspace_root": {
"default": "/Users/[USERNAME]",
"description": "root directory in the Databricks workspace to store the Declarative Automation Bundle and associated artifacts",
"value": "/Users/[USERNAME]"
}
},
"workspace": {
"artifact_path": "/Users/[USERNAME]/path/to/root/artifacts",
"file_path": "/Users/[USERNAME]/path/to/root/files",
"profile": "profile_name",
"resource_path": "/Users/[USERNAME]/path/to/root/resources",
"root_path": "/Users/[USERNAME]/path/to/root",
"state_path": "/Users/[USERNAME]/path/to/root/state"
}
"target": "dev",
"root_path": "/Workspace/Users/[USERNAME]/path/to/root",
"file_path": "/Workspace/Users/[USERNAME]/path/to/root/files",
"conf_file": "/Workspace/Users/[USERNAME]/path/to/root/files/path/to/config.yaml"
}
{
"target": "prod",
"root_path": "/Workspace/Shared/path/to/root",
"file_path": "/Workspace/Shared/path/to/root/files",
"conf_file": "/Workspace/Shared/path/to/root/files/path/to/config.yaml"
}
5 changes: 3 additions & 2 deletions acceptance/bundle/variables/prepend-workspace-var/script
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
echo /Workspace should be prepended on all paths, but it is not the case: #2181
$CLI bundle validate -o json | jq 'del(.workspace.current_user)'
for target in dev prod; do
$CLI bundle validate -t "$target" -o json 2>/dev/null | jq '{target: .bundle.target, root_path: .workspace.root_path, file_path: .workspace.file_path, conf_file: .resources.jobs.my_job.tasks[0].python_wheel_task.named_parameters["conf-file"]}'
done
4 changes: 4 additions & 0 deletions bundle/config/mutator/prepend_workspace_prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func prependWorkspacePrefixTo(path string) string {
return path
}

if path == "/Workspace" || path == "/Volumes" {
return path
}

for _, prefix := range skipPrefixes {
if strings.HasPrefix(path, prefix) {
return path
Expand Down
35 changes: 35 additions & 0 deletions bundle/config/mutator/prepend_workspace_prefix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,38 @@ func TestPrependWorkspaceForDefaultConfig(t *testing.T) {
require.Equal(t, "/Workspace/Users/jane@doe.com/.bundle/test/dev/state", b.Config.Workspace.StatePath)
require.Equal(t, "/Workspace/Users/jane@doe.com/.bundle/test/dev/resources", b.Config.Workspace.ResourcePath)
}

func TestFactory96162B875C12(t *testing.T) {
for _, root := range []string{"/Users/jane@doe.com", "/Shared"} {
t.Run(root, func(t *testing.T) {
b := &bundle.Bundle{
Config: config.Root{
Bundle: config.Bundle{Name: root},
Workspace: config.Workspace{
RootPath: "${bundle.name}/path/to/root",
},
},
}

diags := bundle.ApplySeq(t.Context(), b,
DefineDefaultWorkspacePaths(),
PrependWorkspacePrefix(),
ResolveVariableReferencesWithoutResources(),
)
require.NoError(t, diags.Error())
require.Equal(t, root+"/path/to/root", b.Config.Workspace.RootPath)

diags = bundle.Apply(t.Context(), b, PrependWorkspacePrefix())
require.NoError(t, diags.Error())
require.Equal(t, "/Workspace"+root+"/path/to/root", b.Config.Workspace.RootPath)
require.Equal(t, "/Workspace"+root+"/path/to/root/files", b.Config.Workspace.FilePath)
require.Equal(t, "/Workspace"+root+"/path/to/root/artifacts", b.Config.Workspace.ArtifactPath)
require.Equal(t, "/Workspace"+root+"/path/to/root/state", b.Config.Workspace.StatePath)
require.Equal(t, "/Workspace"+root+"/path/to/root/resources", b.Config.Workspace.ResourcePath)
})
}

for _, path := range []string{"/Workspace", "/Volumes"} {
require.Equal(t, path, prependWorkspacePrefixTo(path))
}
}
2 changes: 2 additions & 0 deletions bundle/phases/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ func Initialize(ctx context.Context, b *bundle.Bundle) {
// Resolves variable references in configuration (except resources) using bundle, workspace,
// and variables prefixes
mutator.ResolveVariableReferencesWithoutResources(),
// Variable-based workspace paths can become absolute only after resolution.
mutator.PrependWorkspacePrefix(),

// Check for invalid use of /Volumes in workspace paths
validate.ValidateVolumePath(),
Expand Down
Loading