Commit Graph

613 Commits

Author SHA1 Message Date
Ilya Kuznetsov 1e41e6140d
fix: Apps fixes after merge 2025-01-14 12:59:44 +01:00
Ilya Kuznetsov f684afe452
Merge branch 'main' of github.com:databricks/cli into feat/config-reference-doc-autogen 2025-01-14 11:52:44 +01:00
Pieter Noordhuis 5d9bc3b553
Allow artifact path to be located outside the sync root (#2128)
## Changes

We perform a check during path translation that the path being
referenced is contained in the bundle's sync root. If it isn't, it's not
a valid remote reference. However, this doesn't apply to paths that are
_always_ local, such as the artifact path. An artifact's build command
is executed in its path. Files created by the artifact build (e.g.
wheels or JARs) don't need to be in the sync root because they have a
dedicated and different upload path into `${workspace.artifact_path}`.

Therefore, this check that a path is contained in the bundle's sync root
doesn't apply to artifact paths. This change modifies the structure of
path translation to allow opting out of this check.

Fixes #1927.

## Tests

* Existing and new tests pass.
* Manually confirmed that building and using a wheel built outside the
sync root path works as expected.
* No acceptance tests because we don't run build as part of validate.
2025-01-14 08:34:55 +00:00
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
Ilya Kuznetsov 2591172370 fix: Circular types 2025-01-13 15:55:49 +01:00
Ilya Kuznetsov 3e0d2324b5
fix: Allow empty fields 2025-01-13 15:28:41 +01:00
Ilya Kuznetsov c88498eb56
fix: Schema update 2025-01-13 15:27:36 +01:00
Ilya Kuznetsov ad81e1f0af fix: Few links updates 2025-01-13 15:16:47 +01:00
Denis Bilenko 1ead1b2e36
Move merge fix-ups after variable resolution (#2125)
## Changes
Move mutator.Merge{JobClusters,JobParameters,JobTasks,PipelineClusters}
after variable resolution. This helps with the case when key contains a
variable.

@pietern mentioned here
https://github.com/databricks/cli/pull/2101#pullrequestreview-2539168762
it should be safe.

## Tests
Existing acceptance that was capturing the bug is updated with corrected
output.
2025-01-13 13:01:31 +00:00
Lennart Kats (databricks) 3e40a0c2f1
Encourage the use of root_path in production to ensure single deployment (#1712)
## Changes

This updates `mode: production` to allow `root_path` to indicate
uniqueness. Historically, we required `run_as` for this, which isn't
actually very effective for that purpose. `run_as` also had the problem
that it doesn't work for pipelines.

This is a cherry-pick from https://github.com/databricks/cli/pull/1387

---------

Co-authored-by: Pieter Noordhuis <pcnoordhuis@gmail.com>
2025-01-13 12:19:12 +00:00
Gleb Kanterov f8f804fe17
PythonMutator: update instrumentation (#2124)
## Changes
Update instrumentation for PythonMutator to handle `experimental/python`
config.

## Tests
Unit tests
2025-01-13 09:16:29 +00:00
Ilya Kuznetsov 5fb4fa000b fix: Add field-name for some properties 2025-01-10 21:01:15 +01:00
Ilya Kuznetsov fd88e4c97a fix: Use markdown from original pages 2025-01-10 20:35:44 +01:00
Ilya Kuznetsov 90cafad8c8 fix: Allow nodes with only description 2025-01-10 19:57:02 +01:00
Ilya Kuznetsov c546604cc4
fix: Schema bump 2025-01-10 19:29:43 +01:00
Ilya Kuznetsov 880a4cf49e
fix: Few extra links 2025-01-10 19:29:16 +01:00
Ilya Kuznetsov 0bd7b524db
fix: Invalid refrences 2025-01-10 19:26:45 +01:00
Ilya Kuznetsov ee5db187c0
fix: Move logic to separate fiels 2025-01-10 18:33:58 +01:00
Ilya Kuznetsov 4b01f6b1bc
fix: Add links 2025-01-10 18:09:18 +01:00
Ilya Kuznetsov 151a6f86dd
fix: Multiple links 2025-01-10 17:51:22 +01:00
Ilya Kuznetsov 1fbec371e5
fix: Link 2025-01-10 17:47:06 +01:00
Ilya Kuznetsov d5d433e9d7
fix: More descriptions 2025-01-10 16:37:22 +01:00
Ilya Kuznetsov 954ef76fe9
Merge branch 'main' of github.com:databricks/cli into feat/config-reference-doc-autogen 2025-01-10 16:07:13 +01:00
Ilya Kuznetsov bad77bd358
fix: Sync annotations 2025-01-10 16:01:52 +01:00
Ilya Kuznetsov 6c5268aaaa fix: Missing array types 2025-01-10 12:52:20 +01:00
Denis Bilenko a0455bcaef
Migrate bundle/tests/undefined_resources_test.go to acceptance test (#2106)
Add sort_blocks.py helper to deal with non-determinism.
2025-01-09 15:21:24 +00:00
Denis Bilenko df17e4b4ea
Convert some resolve variables tests to acceptance test (#2100) 2025-01-08 17:44:52 +00:00
Ilya Kuznetsov f9278c2b4d docs: Add override for volume spec 2025-01-08 16:11:58 +01:00
Ilya Kuznetsov c355fbfcb2 fix: Description of root types with additional properties 2025-01-08 16:11:35 +01:00
Ilya Kuznetsov 0289becea8
Handle `${workspace.file_path}` references in source-linked deployments (#2046)
## Changes

1. Updates `workspace.file_path` during source-linked deployment to
address cases like this
https://github.com/databricks/bundle-examples/blob/main/default_python/resources/default_python_pipeline.yml#L13
2. Updates `workspace.file_path` in `metadata.json`
3. Prints warning for users when `workspace.file_path` is explicitly set
but deploy is running in source-linked mode

## Tests

Unit test
2025-01-08 12:43:56 +00:00
Denis Bilenko 185bbd28e4
Add acceptance tests (#2081)
## Changes
- New kind of test is added - acceptance tests. See acceptance/README.md
for explanation.
- A few tests are converted to acceptance tests by moving databricks.yml
to acceptance/ and adding corresponding script files.

As these tests run against compiled binary and can capture full output
of the command, they can be useful to support major changes such as
refactoring internal logging / diagnostics or complex variable
interpolation.

These are currently run as part of 'make test' but the intention is to
run them as part of integration tests as well.

### Benefits

- Full binary is tested, exactly as users get it.
  - We're not testing custom set of mutators like many existing tests.
- Not mocking anything, real SDK is used (although the HTTP endpoint is
not a real Databricks env).
- Easy to maintain: output can be updated automatically.
- Can easily set up external env, such as env vars, CLI args,
.databrickscfg location etc.

### Gaps

The tests currently share the test server and there is global place to
define handlers. We should have a way for tests to override / add new
handlers.

## Tests
I manually checked that output of new acceptance tests matches previous
asserts.
2025-01-08 12:41:08 +00:00
Gleb Kanterov 02c7df39f6
Add 'experimental/python' support (#2052)
## Changes
Add `experimental/python` section replacing `experimental/pydabs`.

Add 2 new mutators into existing pipeline:
- `ApplyPythonMutator(load_resources)` - loads resources from Python
code
- `ApplyPythonMutator(apply_mutators)` - transforms existing resources
defined in Python/YAML

Example:
```yaml
experimental:
  python:
    resources:
    - "resources:load_resources"
    mutators:
    - "mutators:add_email_notifications"
```

## Tests
Unit tests and manually

---------

Co-authored-by: Pieter Noordhuis <pieter.noordhuis@databricks.com>
2025-01-08 09:29:45 +00:00
Ilya Kuznetsov fe6ba76b7d fix: Styling 2025-01-07 16:52:01 +01:00
Denis Bilenko e2cd8c2f34
Enable perfsprint linter and apply autofix (#2071)
https://github.com/catenacyber/perfsprint
2025-01-07 10:49:23 +00:00
Ilya Kuznetsov c6703c1363 fix: Updated styles 2025-01-03 13:52:59 +01:00
Denis Bilenko 8e8399da83
Enable linter 'mirror' and autofix existing issues (#2070)
https://github.com/butuzov/mirror
2025-01-03 10:13:12 +00:00
Denis Bilenko 39d1e8093f
Enable intrange linter and apply autofix (#2069)
New construct in Go1.22+ for integer iteration:
https://github.com/ckaznocha/intrange?tab=readme-ov-file#intrange
2025-01-03 09:25:07 +00:00
Ilya Kuznetsov 2aadfcbcb2
feat: Support for resources 2025-01-02 18:24:18 +01:00
Ilya Kuznetsov 541c3e3fb5
feat: More explicit type for arrays 2025-01-02 16:56:36 +01:00
Ilya Kuznetsov 460a4558e0
chore: Extract annotation package 2025-01-02 16:40:06 +01:00
Ilya Kuznetsov 820dd5f34c
feat: Add examples to the docs 2025-01-02 16:13:24 +01:00
shreyas-goenka 7beb0fb8b5
Add validation mutator for volume `artifact_path` (#2050)
## Changes
This PR:
1. Incrementally improves the error messages shown to the user when the
volume they are referring to in `workspace.artifact_path` does not
exist.
2. Performs this validation in both `bundle validate` and `bundle
deploy` compared to before on just deployments.
3. It runs "fast" validations on `bundle deploy`, which earlier were
only run on `bundle validate`.


## Tests
Unit tests and manually. Also, existing integration tests provide
coverage (`TestUploadArtifactToVolumeNotYetDeployed`,
`TestUploadArtifactFileToVolumeThatDoesNotExist`)

Examples:
```
.venv➜  bundle-playground git:(master) ✗ cli bundle validate
Error: cannot access volume capital.whatever.my_volume: User does not have READ VOLUME on Volume 'capital.whatever.my_volume'.
  at workspace.artifact_path
  in databricks.yml:7:18
```

and

```
.venv➜  bundle-playground git:(master) ✗ cli bundle validate
Error: volume capital.whatever.foobar does not exist
  at workspace.artifact_path
     resources.volumes.foo
  in databricks.yml:7:18
     databricks.yml:12:7

You are using a volume in your artifact_path that is managed by
this bundle but which has not been deployed yet. Please first deploy
the volume using 'bundle deploy' and then switch over to using it in
the artifact_path.
```
2025-01-02 17:23:15 +05:30
Denis Bilenko 0b80784df7
Enable testifylint and fix the issues (#2065)
## Changes
- Enable new linter: testifylint.
- Apply fixes with --fix.
- Fix remaining issues (mostly with aider).

There were 2 cases we --fix did the wrong thing - this seems to a be a
bug in linter: https://github.com/Antonboom/testifylint/issues/210

Nonetheless, I kept that check enabled, it seems useful, just need to be
fixed manually after autofix.

## Tests
Existing tests
2025-01-02 12:03:41 +01:00
Denis Bilenko 3f523b45cc
Fix lost diags across different mutators (#2057)
## Changes
Fix cases where accumulated diagnostics are lost instead of being
propagated further. In some cases it's not possible, add a comment
there.

## Tests
Existing tests
2024-12-31 14:01:45 +00:00
shreyas-goenka 511db52bb7
Remove unnecessary GET call in pipeline runner (#1850)
## Changes
This GET API call is unnecessary and serves no purpose. Let's remove it.
Noticed this when I was adding a unit test for the pipeline runner here:
https://github.com/databricks/cli/pull/1849

## Tests
Manually. 

### Case 1: The pipeline does not exist

Before:
```
➜  my_project git:(master) ✗ databricks bundle run my_project_pipeline -p dogfood
Error: User shreyas.goenka@databricks.com does not have View permissions on pipeline 9941901a-e48b-4d04-b6ba-e0072ad126bg.
```

After:
```
➜  my_project git:(master) ✗ cli bundle run my_project_pipeline -p dogfood
Error: User shreyas.goenka@databricks.com does not have Run permissions on pipeline 9941901a-e48b-4d04-b6ba-e0072ad126bg.
```

### Case 2: Pipeline exists

Before:
```
➜  my_project git:(master) ✗ databricks bundle run my_project_pipeline -p dogfood --restart
Update URL: https://e2-dogfood.staging.cloud.databricks.com/#joblist/pipelines/9941901a-e48b-4d04-b6ba-e0072ad126bf/updates/0f988d62-9ec7-49f1-b429-5572ece3a9aa

2024-11-18T15:30:36.054Z update_progress INFO "Update 0f988d is WAITING_FOR_RESOURCES."
```

After:
```
➜  my_project git:(master) ✗ cli bundle run my_project_pipeline -p dogfood --restart
Update URL: https://e2-dogfood.staging.cloud.databricks.com/#joblist/pipelines/9941901a-e48b-4d04-b6ba-e0072ad126bf/updates/87b43350-6186-4a9b-9d0e-38da2ecf33ae

2024-11-18T15:28:27.144Z update_progress INFO "Update 87b433 is WAITING_FOR_RESOURCES."
```
2024-12-31 09:51:13 +00:00
Ilya Kuznetsov 793bf2b995
fix: Empty schema fields in OpenAPI spec (#2045)
## Changes

1. Removes default yaml-fields during schema generation, caused by [this
PR](https://github.com/databricks/cli/pull/2032) (current yaml package
can't read `json` annotations in struct fields)
2. Addresses missing annotations for fields from OpenAPI spec, which are
named differently in go SDK
3. Adds filtering for annotations.yaml to include only CLI package
fields
4. Implements alphabetical sort for yaml keys to avoid unnecessary diff
in PRs

## Tests

Manually tested
2024-12-23 12:08:01 +00:00
Ilya Kuznetsov 40c4b3a40a
Merge branch 'main' of github.com:databricks/cli into feat/config-reference-doc-autogen 2024-12-23 12:25:29 +01:00
Denis Bilenko dd9f59837e
Upgrade go to 1.23.4 (#2038)
## Changes
`git grep -l 1.23.2 | xargs -n 1 sed -i '' 's/1.23.2/1.23.4/'`

## Tests
Existing tests
2024-12-20 09:21:36 +00:00
Denis Bilenko 2fee243586
Fix finding Python within virtualenv on Windows (#2034)
## Changes
Simplify logic for selecting Python to run when calculating default whl
build command: "python" on Windows and "python3" everywhere.

Python installers from python.org do not install python3.exe. In
virtualenv there is no python3.exe.

## Tests
Added new unit tests to create real venv with uv and simulate activation
by prepending venv/bin to PATH.
2024-12-20 07:45:32 +00:00
Pieter Noordhuis 965a3fcd53
Remove dependency on ghodss/yaml (#2032)
## Changes

I noticed that #1957 took a dep on this library even though we no longer
need it. This change removes the dep and cleans up other (unused) uses
of the library. We originally relied on this library to deserialize
bundle configuration and JSON payloads to non-bundle CLI commands.

Relevant commits:
* The YAML flag was added to support apps (very early), and is not
longer used: e408b701
* First use for bundle configuration loading: e47fa619
* Switch bundle configuration loading to use `libs/dyn`: 87dd46a3

## Tests

The build works without the dependency.
2024-12-19 08:23:05 +00:00