databricks-cli/bundle/config/mutator
Andrew Nester 913e10a037
Added support for Databricks Apps in DABs (#1928)
## Changes
Now it's possible to configure new `app` resource in bundle and point it
to the custom `source_code_path` location where Databricks App code is
defined.

On `databricks bundle deploy` DABs will create an app. All consecutive
`databricks bundle deploy` execution will update an existing app if
there are any updated

On `databricks bundle run <my_app>` DABs will execute app deployment. If
the app is not started yet, it will start the app first.

### Bundle configuration

```
bundle:
  name: apps

variables:
  my_job_id:
    description: "ID of job to run app"
    lookup:
      job: "My Job"
  databricks_name:
    description: "Name for app user"
  additional_flags:
    description: "Additional flags to run command app"
    default: ""
  my_app_config:
    type: complex
    description: "Configuration for my Databricks App"
    default:
      command:
        - flask
        - --app
        - hello
        - run
        - ${var.additional_flags}
      env:
        - name: DATABRICKS_NAME
          value: ${var.databricks_name}

resources:
  apps:
    my_app:
      name: "anester-app" # required and has to be unique
      description: "My App"
      source_code_path: ./app # required and points to location of app code
      config: ${var.my_app_config}
      resources:
        - name: "my-job"
          description: "A job for app to be able to run"
          job:
            id: ${var.my_job_id}
            permission: "CAN_MANAGE_RUN"
      permissions:
        - user_name: "foo@bar.com"
          level: "CAN_VIEW"
        - service_principal_name: "my_sp"
          level: "CAN_MANAGE"

targets:
  dev:
    variables:
      databricks_name: "Andrew (from dev)"
      additional_flags: --debug
  
  prod:
    variables:
      databricks_name: "Andrew (from prod)"
```

### Execution
1. `databricks bundle deploy -t dev`
2. `databricks bundle run my_app -t dev`

**If app is started**
```
✓ Getting the status of the app my-app
✓ App is in RUNNING state
✓ Preparing source code for new app deployment.
✓ Deployment is pending
✓ Starting app with command: flask --app hello run --debug
✓ App started successfully
You can access the app at <app-url>
```

**If app is not started**
```
✓ Getting the status of the app my-app
✓ App is in UNAVAILABLE state
✓ Starting the app my-app
✓ App is starting...
....
✓ App is starting...
✓ App is started!
✓ Preparing source code for new app deployment.
✓ Downloading source code from /Workspace/Users/...
✓ Starting app with command: flask --app hello run --debug
✓ App started successfully
You can access the app at <app-url>
```

## Tests
Added unit and config tests + manual test.

```
--- PASS: TestAccDeployBundleWithApp (404.59s)
PASS
coverage: 36.8% of statements in ./...
ok      github.com/databricks/cli/internal/bundle       405.035s        coverage: 36.8% of statements in ./...
```
2025-01-13 16:43:48 +00:00
..
paths Enable gofumpt and goimports in golangci-lint (#1999) 2024-12-12 10:28:42 +01:00
python Add 'experimental/python' support (#2052) 2025-01-08 09:29:45 +00:00
apply_presets.go Added support for Databricks Apps in DABs (#1928) 2025-01-13 16:43:48 +00:00
apply_presets_test.go Handle `${workspace.file_path}` references in source-linked deployments (#2046) 2025-01-08 12:43:56 +00:00
apply_source_linked_deployment_preset.go Added support for Databricks Apps in DABs (#1928) 2025-01-13 16:43:48 +00:00
apply_source_linked_deployment_preset_test.go Added support for Databricks Apps in DABs (#1928) 2025-01-13 16:43:48 +00:00
compute_id_compat.go Enable gofumpt and goimports in golangci-lint (#1999) 2024-12-12 10:28:42 +01:00
compute_id_compate_test.go Added support for creating all-purpose clusters (#1698) 2024-09-23 10:42:34 +00:00
configure_dashboard_defaults.go Add support for AI/BI dashboards (#1743) 2024-10-29 09:11:08 +00:00
configure_dashboard_defaults_test.go Enable testifylint and fix the issues (#2065) 2025-01-02 12:03:41 +01:00
configure_volume_defaults.go Add default value for `volume_type` for DABs (#1952) 2024-12-04 11:05:54 +00:00
configure_volume_defaults_test.go Add default value for `volume_type` for DABs (#1952) 2024-12-04 11:05:54 +00:00
configure_wsfs.go Extract functionality to detect if the CLI is running on DBR (#1889) 2024-11-14 16:10:45 +00:00
configure_wsfs_test.go Extract functionality to detect if the CLI is running on DBR (#1889) 2024-11-14 16:10:45 +00:00
default_queueing.go Enable job queueing by default (#1385) 2024-04-22 10:36:39 +00:00
default_queueing_test.go Enable testifylint and fix the issues (#2065) 2025-01-02 12:03:41 +01:00
default_target.go Return `diag.Diagnostics` from mutators (#1305) 2024-03-25 14:18:47 +00:00
default_target_test.go Return `diag.Diagnostics` from mutators (#1305) 2024-03-25 14:18:47 +00:00
default_workspace_paths.go Add resource path field to bundle workspace configuration (#1800) 2024-10-02 13:55:40 +00:00
default_workspace_paths_test.go Add resource path field to bundle workspace configuration (#1800) 2024-10-02 13:55:40 +00:00
default_workspace_root.go Return `diag.Diagnostics` from mutators (#1305) 2024-03-25 14:18:47 +00:00
default_workspace_root_test.go Return `diag.Diagnostics` from mutators (#1305) 2024-03-25 14:18:47 +00:00
environments_compat.go Compare `.Kind()` instead of direct equality checks on a `dyn.Value` (#1520) 2024-06-27 13:28:19 +00:00
environments_compat_test.go Enable testifylint and fix the issues (#2065) 2025-01-02 12:03:41 +01:00
expand_pipeline_glob_paths.go Track multiple locations associated with a `dyn.Value` (#1510) 2024-07-16 11:27:27 +00:00
expand_pipeline_glob_paths_test.go Enable gofumpt and goimports in golangci-lint (#1999) 2024-12-12 10:28:42 +01:00
expand_workspace_root.go Enable perfsprint linter and apply autofix (#2071) 2025-01-07 10:49:23 +00:00
expand_workspace_root_test.go Always prepend bundle remote paths with /Workspace (#1724) 2024-10-02 15:34:00 +00:00
initialize_urls.go Enable gofumpt and goimports in golangci-lint (#1999) 2024-12-12 10:28:42 +01:00
initialize_urls_test.go Add error checking in tests and enable errcheck there (#1980) 2024-12-09 13:56:41 +01:00
initialize_variables.go Return `diag.Diagnostics` from mutators (#1305) 2024-03-25 14:18:47 +00:00
initialize_variables_test.go Return `diag.Diagnostics` from mutators (#1305) 2024-03-25 14:18:47 +00:00
initialize_workspace_client.go Return `diag.Diagnostics` from mutators (#1305) 2024-03-25 14:18:47 +00:00
load_git_details.go Switch to `folders.FindDirWithLeaf` (#1963) 2024-12-11 09:44:22 +01:00
merge_apps.go Added support for Databricks Apps in DABs (#1928) 2025-01-13 16:43:48 +00:00
merge_apps_test.go Added support for Databricks Apps in DABs (#1928) 2025-01-13 16:43:48 +00:00
merge_job_clusters.go Compare `.Kind()` instead of direct equality checks on a `dyn.Value` (#1520) 2024-06-27 13:28:19 +00:00
merge_job_clusters_test.go Bump github.com/databricks/databricks-sdk-go from 0.36.0 to 0.37.0 (#1326) 2024-04-03 10:39:53 +00:00
merge_job_parameters.go Merge job parameters based on their name (#1659) 2024-08-06 16:12:18 +00:00
merge_job_parameters_test.go Merge job parameters based on their name (#1659) 2024-08-06 16:12:18 +00:00
merge_job_tasks.go Compare `.Kind()` instead of direct equality checks on a `dyn.Value` (#1520) 2024-06-27 13:28:19 +00:00
merge_job_tasks_test.go Enable testifylint and fix the issues (#2065) 2025-01-02 12:03:41 +01:00
merge_pipeline_clusters.go Compare `.Kind()` instead of direct equality checks on a `dyn.Value` (#1520) 2024-06-27 13:28:19 +00:00
merge_pipeline_clusters_test.go Return `diag.Diagnostics` from mutators (#1305) 2024-03-25 14:18:47 +00:00
mutator.go Move loadGitDetails mutator to Initialize phase (#1944) 2024-12-02 09:49:32 +00:00
noop.go Return `diag.Diagnostics` from mutators (#1305) 2024-03-25 14:18:47 +00:00
override_compute.go Enable gofumpt and goimports in golangci-lint (#1999) 2024-12-12 10:28:42 +01:00
override_compute_test.go Show an error when using a cluster override with 'mode: production' (#1994) 2024-12-11 14:57:31 +00:00
populate_current_user.go Move utility functions dealing with IAM to libs/iamutil (#1820) 2024-10-10 13:02:25 +00:00
populate_current_user_test.go Add short_name helper function to bundle init templates (#1167) 2024-02-01 16:46:07 +00:00
prepend_workspace_prefix.go Enable perfsprint linter and apply autofix (#2071) 2025-01-07 10:49:23 +00:00
prepend_workspace_prefix_test.go Do not prepend paths starting with ~ or variable reference (#1905) 2024-11-15 15:03:59 +00:00
process_target_mode.go Encourage the use of root_path in production to ensure single deployment (#1712) 2025-01-13 12:19:12 +00:00
process_target_mode_test.go Added support for Databricks Apps in DABs (#1928) 2025-01-13 16:43:48 +00:00
resolve_resource_references.go Fix lost diags across different mutators (#2057) 2024-12-31 14:01:45 +00:00
resolve_resource_references_test.go Add error checking in tests and enable errcheck there (#1980) 2024-12-09 13:56:41 +01:00
resolve_variable_references.go Handle `${workspace.file_path}` references in source-linked deployments (#2046) 2025-01-08 12:43:56 +00:00
resolve_variable_references_test.go Convert some resolve variables tests to acceptance test (#2100) 2025-01-08 17:44:52 +00:00
rewrite_sync_paths.go Rename `RootPath` -> `BundleRootPath` (#1792) 2024-09-27 10:03:05 +00:00
rewrite_sync_paths_test.go Rename `RootPath` -> `BundleRootPath` (#1792) 2024-09-27 10:03:05 +00:00
rewrite_workspace_prefix.go Enable gofumpt and goimports in golangci-lint (#1999) 2024-12-12 10:28:42 +01:00
rewrite_workspace_prefix_test.go Enable testifylint and fix the issues (#2065) 2025-01-02 12:03:41 +01:00
run_as.go Added support for Databricks Apps in DABs (#1928) 2025-01-13 16:43:48 +00:00
run_as_test.go Added support for Databricks Apps in DABs (#1928) 2025-01-13 16:43:48 +00:00
select_default_target.go Return `diag.Diagnostics` from mutators (#1305) 2024-03-25 14:18:47 +00:00
select_default_target_test.go Return `diag.Diagnostics` from mutators (#1305) 2024-03-25 14:18:47 +00:00
select_target.go Encourage the use of root_path in production to ensure single deployment (#1712) 2025-01-13 12:19:12 +00:00
select_target_test.go Return `diag.Diagnostics` from mutators (#1305) 2024-03-25 14:18:47 +00:00
set_variables.go Enable gofumpt and goimports in golangci-lint (#1999) 2024-12-12 10:28:42 +01:00
set_variables_test.go Enable testifylint and fix the issues (#2065) 2025-01-02 12:03:41 +01:00
sync_default_path.go Add paths field to bundle sync configuration (#1694) 2024-08-21 15:33:25 +00:00
sync_default_path_test.go Rename `RootPath` -> `BundleRootPath` (#1792) 2024-09-27 10:03:05 +00:00
sync_infer_root.go Enable gofumpt and goimports in golangci-lint (#1999) 2024-12-12 10:28:42 +01:00
sync_infer_root_internal_test.go Add paths field to bundle sync configuration (#1694) 2024-08-21 15:33:25 +00:00
sync_infer_root_test.go Rename `RootPath` -> `BundleRootPath` (#1792) 2024-09-27 10:03:05 +00:00
translate_paths.go Added support for Databricks Apps in DABs (#1928) 2025-01-13 16:43:48 +00:00
translate_paths_apps.go Added support for Databricks Apps in DABs (#1928) 2025-01-13 16:43:48 +00:00
translate_paths_apps_test.go Added support for Databricks Apps in DABs (#1928) 2025-01-13 16:43:48 +00:00
translate_paths_artifacts.go Add context type and value to path rewriting (#1525) 2024-06-25 10:04:22 +00:00
translate_paths_dashboards.go Add support for AI/BI dashboards (#1743) 2024-10-29 09:11:08 +00:00
translate_paths_dashboards_test.go Bump github.com/databricks/databricks-sdk-go from 0.49.0 to 0.51.0 (#1878) 2024-11-13 13:40:53 +00:00
translate_paths_jobs.go Refactor jobs path translation (#1782) 2024-09-24 13:51:54 +00:00
translate_paths_pipelines.go Add context type and value to path rewriting (#1525) 2024-06-25 10:04:22 +00:00
translate_paths_test.go Enable gofumpt and goimports in golangci-lint (#1999) 2024-12-12 10:28:42 +01:00
validate_git_details.go Return `diag.Diagnostics` from mutators (#1305) 2024-03-25 14:18:47 +00:00
validate_git_details_test.go Return `diag.Diagnostics` from mutators (#1305) 2024-03-25 14:18:47 +00:00
verify_cli_version.go Enable gofumpt and goimports in golangci-lint (#1999) 2024-12-12 10:28:42 +01:00
verify_cli_version_test.go Ignore CLI version check on development builds of the CLI (#1714) 2024-08-23 10:13:21 +00:00