2022-12-12 11:49:25 +00:00
|
|
|
package phases
|
|
|
|
|
|
|
|
import (
|
2023-05-16 16:35:39 +00:00
|
|
|
"github.com/databricks/cli/bundle"
|
2023-09-14 10:14:13 +00:00
|
|
|
"github.com/databricks/cli/bundle/config"
|
2023-05-16 16:35:39 +00:00
|
|
|
"github.com/databricks/cli/bundle/config/mutator"
|
2024-06-20 08:43:08 +00:00
|
|
|
pythonmutator "github.com/databricks/cli/bundle/config/mutator/python"
|
2024-08-13 12:50:15 +00:00
|
|
|
"github.com/databricks/cli/bundle/config/validate"
|
2023-12-19 07:38:52 +00:00
|
|
|
"github.com/databricks/cli/bundle/deploy/metadata"
|
2023-05-16 16:35:39 +00:00
|
|
|
"github.com/databricks/cli/bundle/deploy/terraform"
|
2023-11-13 11:29:40 +00:00
|
|
|
"github.com/databricks/cli/bundle/permissions"
|
2023-09-14 10:14:13 +00:00
|
|
|
"github.com/databricks/cli/bundle/scripts"
|
2024-09-27 09:32:54 +00:00
|
|
|
"github.com/databricks/cli/bundle/trampoline"
|
2022-12-12 11:49:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// The initialize phase fills in defaults and connects to the workspace.
|
|
|
|
// Interpolation of fields referring to the "bundle" and "workspace" keys
|
|
|
|
// happens upon completion of this phase.
|
|
|
|
func Initialize() bundle.Mutator {
|
|
|
|
return newPhase(
|
|
|
|
"initialize",
|
|
|
|
[]bundle.Mutator{
|
2024-08-13 12:50:15 +00:00
|
|
|
validate.AllResourcesHaveValues(),
|
2024-08-21 15:33:25 +00:00
|
|
|
|
|
|
|
// Update all path fields in the sync block to be relative to the bundle root path.
|
Use dynamic configuration model in bundles (#1098)
## Changes
This is a fundamental change to how we load and process bundle
configuration. We now depend on the configuration being represented as a
`dyn.Value`. This representation is functionally equivalent to Go's
`any` (it is variadic) and allows us to capture metadata associated with
a value, such as where it was defined (e.g. file, line, and column). It
also allows us to represent Go's zero values properly (e.g. empty
string, integer equal to 0, or boolean false).
Using this representation allows us to let the configuration model
deviate from the typed structure we have been relying on so far
(`config.Root`). We need to deviate from these types when using
variables for fields that are not a string themselves. For example,
using `${var.num_workers}` for an integer `workers` field was impossible
until now (though not implemented in this change).
The loader for a `dyn.Value` includes functionality to capture any and
all type mismatches between the user-defined configuration and the
expected types. These mismatches can be surfaced as validation errors in
future PRs.
Given that many mutators expect the typed struct to be the source of
truth, this change converts between the dynamic representation and the
typed representation on mutator entry and exit. Existing mutators can
continue to modify the typed representation and these modifications are
reflected in the dynamic representation (see `MarkMutatorEntry` and
`MarkMutatorExit` in `bundle/config/root.go`).
Required changes included in this change:
* The existing interpolation package is removed in favor of
`libs/dyn/dynvar`.
* Functionality to merge job clusters, job tasks, and pipeline clusters
are now all broken out into their own mutators.
To be implemented later:
* Allow variable references for non-string types.
* Surface diagnostics about the configuration provided by the user in
the validation output.
* Some mutators use a resource's configuration file path to resolve
related relative paths. These depend on `bundle/config/paths.Path` being
set and populated through `ConfigureConfigFilePath`. Instead, they
should interact with the dynamically typed configuration directly. Doing
this also unlocks being able to differentiate different base paths used
within a job (e.g. a task override with a relative path defined in a
directory other than the base job).
## Tests
* Existing unit tests pass (some have been modified to accommodate)
* Integration tests pass
2024-02-16 19:41:58 +00:00
|
|
|
mutator.RewriteSyncPaths(),
|
2024-08-21 15:33:25 +00:00
|
|
|
|
|
|
|
// Configure the default sync path to equal the bundle root if not explicitly configured.
|
|
|
|
// By default, this means all files in the bundle root directory are synchronized.
|
|
|
|
mutator.SyncDefaultPath(),
|
|
|
|
|
|
|
|
// Figure out if the sync root path is identical or an ancestor of the bundle root path.
|
|
|
|
// If it is an ancestor, this updates all paths to be relative to the sync root path.
|
|
|
|
mutator.SyncInferRoot(),
|
|
|
|
|
Use dynamic configuration model in bundles (#1098)
## Changes
This is a fundamental change to how we load and process bundle
configuration. We now depend on the configuration being represented as a
`dyn.Value`. This representation is functionally equivalent to Go's
`any` (it is variadic) and allows us to capture metadata associated with
a value, such as where it was defined (e.g. file, line, and column). It
also allows us to represent Go's zero values properly (e.g. empty
string, integer equal to 0, or boolean false).
Using this representation allows us to let the configuration model
deviate from the typed structure we have been relying on so far
(`config.Root`). We need to deviate from these types when using
variables for fields that are not a string themselves. For example,
using `${var.num_workers}` for an integer `workers` field was impossible
until now (though not implemented in this change).
The loader for a `dyn.Value` includes functionality to capture any and
all type mismatches between the user-defined configuration and the
expected types. These mismatches can be surfaced as validation errors in
future PRs.
Given that many mutators expect the typed struct to be the source of
truth, this change converts between the dynamic representation and the
typed representation on mutator entry and exit. Existing mutators can
continue to modify the typed representation and these modifications are
reflected in the dynamic representation (see `MarkMutatorEntry` and
`MarkMutatorExit` in `bundle/config/root.go`).
Required changes included in this change:
* The existing interpolation package is removed in favor of
`libs/dyn/dynvar`.
* Functionality to merge job clusters, job tasks, and pipeline clusters
are now all broken out into their own mutators.
To be implemented later:
* Allow variable references for non-string types.
* Surface diagnostics about the configuration provided by the user in
the validation output.
* Some mutators use a resource's configuration file path to resolve
related relative paths. These depend on `bundle/config/paths.Path` being
set and populated through `ConfigureConfigFilePath`. Instead, they
should interact with the dynamically typed configuration directly. Doing
this also unlocks being able to differentiate different base paths used
within a job (e.g. a task override with a relative path defined in a
directory other than the base job).
## Tests
* Existing unit tests pass (some have been modified to accommodate)
* Integration tests pass
2024-02-16 19:41:58 +00:00
|
|
|
mutator.MergeJobClusters(),
|
2024-08-06 16:12:18 +00:00
|
|
|
mutator.MergeJobParameters(),
|
Use dynamic configuration model in bundles (#1098)
## Changes
This is a fundamental change to how we load and process bundle
configuration. We now depend on the configuration being represented as a
`dyn.Value`. This representation is functionally equivalent to Go's
`any` (it is variadic) and allows us to capture metadata associated with
a value, such as where it was defined (e.g. file, line, and column). It
also allows us to represent Go's zero values properly (e.g. empty
string, integer equal to 0, or boolean false).
Using this representation allows us to let the configuration model
deviate from the typed structure we have been relying on so far
(`config.Root`). We need to deviate from these types when using
variables for fields that are not a string themselves. For example,
using `${var.num_workers}` for an integer `workers` field was impossible
until now (though not implemented in this change).
The loader for a `dyn.Value` includes functionality to capture any and
all type mismatches between the user-defined configuration and the
expected types. These mismatches can be surfaced as validation errors in
future PRs.
Given that many mutators expect the typed struct to be the source of
truth, this change converts between the dynamic representation and the
typed representation on mutator entry and exit. Existing mutators can
continue to modify the typed representation and these modifications are
reflected in the dynamic representation (see `MarkMutatorEntry` and
`MarkMutatorExit` in `bundle/config/root.go`).
Required changes included in this change:
* The existing interpolation package is removed in favor of
`libs/dyn/dynvar`.
* Functionality to merge job clusters, job tasks, and pipeline clusters
are now all broken out into their own mutators.
To be implemented later:
* Allow variable references for non-string types.
* Surface diagnostics about the configuration provided by the user in
the validation output.
* Some mutators use a resource's configuration file path to resolve
related relative paths. These depend on `bundle/config/paths.Path` being
set and populated through `ConfigureConfigFilePath`. Instead, they
should interact with the dynamically typed configuration directly. Doing
this also unlocks being able to differentiate different base paths used
within a job (e.g. a task override with a relative path defined in a
directory other than the base job).
## Tests
* Existing unit tests pass (some have been modified to accommodate)
* Integration tests pass
2024-02-16 19:41:58 +00:00
|
|
|
mutator.MergeJobTasks(),
|
|
|
|
mutator.MergePipelineClusters(),
|
2023-11-30 14:28:01 +00:00
|
|
|
mutator.InitializeWorkspaceClient(),
|
2022-12-12 11:49:25 +00:00
|
|
|
mutator.PopulateCurrentUser(),
|
2024-10-02 15:34:00 +00:00
|
|
|
|
2023-01-26 18:55:38 +00:00
|
|
|
mutator.DefineDefaultWorkspaceRoot(),
|
|
|
|
mutator.ExpandWorkspaceRoot(),
|
|
|
|
mutator.DefineDefaultWorkspacePaths(),
|
2024-10-02 15:34:00 +00:00
|
|
|
mutator.PrependWorkspacePrefix(),
|
|
|
|
|
|
|
|
// This mutator needs to be run before variable interpolation because it
|
|
|
|
// searches for strings with variable references in them.
|
|
|
|
mutator.RewriteWorkspacePrefix(),
|
|
|
|
|
2023-05-15 09:34:05 +00:00
|
|
|
mutator.SetVariables(),
|
2024-06-26 10:25:32 +00:00
|
|
|
// Intentionally placed before ResolveVariableReferencesInLookup, ResolveResourceReferences,
|
|
|
|
// ResolveVariableReferencesInComplexVariables and ResolveVariableReferences.
|
|
|
|
// See what is expected in PythonMutatorPhaseInit doc
|
2024-06-24 07:47:41 +00:00
|
|
|
pythonmutator.PythonMutator(pythonmutator.PythonMutatorPhaseInit),
|
2024-04-18 09:56:16 +00:00
|
|
|
mutator.ResolveVariableReferencesInLookup(),
|
2024-01-04 21:04:42 +00:00
|
|
|
mutator.ResolveResourceReferences(),
|
2024-06-26 10:25:32 +00:00
|
|
|
mutator.ResolveVariableReferencesInComplexVariables(),
|
Use dynamic configuration model in bundles (#1098)
## Changes
This is a fundamental change to how we load and process bundle
configuration. We now depend on the configuration being represented as a
`dyn.Value`. This representation is functionally equivalent to Go's
`any` (it is variadic) and allows us to capture metadata associated with
a value, such as where it was defined (e.g. file, line, and column). It
also allows us to represent Go's zero values properly (e.g. empty
string, integer equal to 0, or boolean false).
Using this representation allows us to let the configuration model
deviate from the typed structure we have been relying on so far
(`config.Root`). We need to deviate from these types when using
variables for fields that are not a string themselves. For example,
using `${var.num_workers}` for an integer `workers` field was impossible
until now (though not implemented in this change).
The loader for a `dyn.Value` includes functionality to capture any and
all type mismatches between the user-defined configuration and the
expected types. These mismatches can be surfaced as validation errors in
future PRs.
Given that many mutators expect the typed struct to be the source of
truth, this change converts between the dynamic representation and the
typed representation on mutator entry and exit. Existing mutators can
continue to modify the typed representation and these modifications are
reflected in the dynamic representation (see `MarkMutatorEntry` and
`MarkMutatorExit` in `bundle/config/root.go`).
Required changes included in this change:
* The existing interpolation package is removed in favor of
`libs/dyn/dynvar`.
* Functionality to merge job clusters, job tasks, and pipeline clusters
are now all broken out into their own mutators.
To be implemented later:
* Allow variable references for non-string types.
* Surface diagnostics about the configuration provided by the user in
the validation output.
* Some mutators use a resource's configuration file path to resolve
related relative paths. These depend on `bundle/config/paths.Path` being
set and populated through `ConfigureConfigFilePath`. Instead, they
should interact with the dynamically typed configuration directly. Doing
this also unlocks being able to differentiate different base paths used
within a job (e.g. a task override with a relative path defined in a
directory other than the base job).
## Tests
* Existing unit tests pass (some have been modified to accommodate)
* Integration tests pass
2024-02-16 19:41:58 +00:00
|
|
|
mutator.ResolveVariableReferences(
|
|
|
|
"bundle",
|
|
|
|
"workspace",
|
|
|
|
"variables",
|
2022-12-12 11:49:25 +00:00
|
|
|
),
|
2024-10-10 11:18:23 +00:00
|
|
|
// Provide permission config errors & warnings after initializing all variables
|
|
|
|
permissions.PermissionDiagnostics(),
|
2024-01-24 12:22:04 +00:00
|
|
|
mutator.SetRunAs(),
|
2023-07-12 06:51:54 +00:00
|
|
|
mutator.OverrideCompute(),
|
2024-10-29 09:11:08 +00:00
|
|
|
mutator.ConfigureDashboardDefaults(),
|
2023-08-17 15:22:32 +00:00
|
|
|
mutator.ProcessTargetMode(),
|
2024-08-19 18:18:50 +00:00
|
|
|
mutator.ApplyPresets(),
|
2024-04-22 10:36:39 +00:00
|
|
|
mutator.DefaultQueueing(),
|
2023-10-04 13:23:13 +00:00
|
|
|
mutator.ExpandPipelineGlobPaths(),
|
2024-07-03 11:55:42 +00:00
|
|
|
|
|
|
|
// Configure use of WSFS for reads if the CLI is running on Databricks.
|
|
|
|
mutator.ConfigureWSFS(),
|
|
|
|
|
2023-04-05 14:02:17 +00:00
|
|
|
mutator.TranslatePaths(),
|
2024-09-27 09:32:54 +00:00
|
|
|
trampoline.WrapperWarning(),
|
2024-10-18 15:37:16 +00:00
|
|
|
|
|
|
|
permissions.ValidateSharedRootPermissions(),
|
2023-11-13 11:29:40 +00:00
|
|
|
permissions.ApplyBundlePermissions(),
|
2024-03-11 15:05:15 +00:00
|
|
|
permissions.FilterCurrentUser(),
|
2024-10-18 15:37:16 +00:00
|
|
|
|
2023-12-19 07:38:52 +00:00
|
|
|
metadata.AnnotateJobs(),
|
2024-05-01 08:37:03 +00:00
|
|
|
metadata.AnnotatePipelines(),
|
2022-12-15 16:30:33 +00:00
|
|
|
terraform.Initialize(),
|
2023-09-14 10:14:13 +00:00
|
|
|
scripts.Execute(config.ScriptPostInit),
|
2022-12-12 11:49:25 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|