diff --git a/NEXT_CHANGELOG.md b/NEXT_CHANGELOG.md index bf95dcc27d..e04e044016 100644 --- a/NEXT_CHANGELOG.md +++ b/NEXT_CHANGELOG.md @@ -11,6 +11,7 @@ ### Bundles * engine/direct: Added support for Vector Search Endpoints ([#4887](https://github.com/databricks/cli/pull/4887)) +* Fixed `--force-pull` on `bundle summary` and `bundle open` so the flag bypasses the local state cache and reads state from the workspace. ### Dependency updates diff --git a/acceptance/bundle/state/force_pull_commands/databricks.yml b/acceptance/bundle/state/force_pull_commands/databricks.yml new file mode 100644 index 0000000000..0d4ab71b68 --- /dev/null +++ b/acceptance/bundle/state/force_pull_commands/databricks.yml @@ -0,0 +1,16 @@ +bundle: + name: force-pull-commands + +resources: + jobs: + foo: + name: foo + tasks: + - task_key: task + spark_python_task: + python_file: ./foo.py + environment_key: default + environments: + - environment_key: default + spec: + client: "2" diff --git a/acceptance/bundle/state/force_pull_commands/foo.py b/acceptance/bundle/state/force_pull_commands/foo.py new file mode 100644 index 0000000000..11b15b1a45 --- /dev/null +++ b/acceptance/bundle/state/force_pull_commands/foo.py @@ -0,0 +1 @@ +print("hello") diff --git a/acceptance/bundle/state/force_pull_commands/open b/acceptance/bundle/state/force_pull_commands/open new file mode 100755 index 0000000000..5c6c78d6a7 --- /dev/null +++ b/acceptance/bundle/state/force_pull_commands/open @@ -0,0 +1,2 @@ +#!/bin/bash +echo "I AM BROWSER" diff --git a/acceptance/bundle/state/force_pull_commands/out.test.toml b/acceptance/bundle/state/force_pull_commands/out.test.toml new file mode 100644 index 0000000000..216969a761 --- /dev/null +++ b/acceptance/bundle/state/force_pull_commands/out.test.toml @@ -0,0 +1,9 @@ +Local = true +Cloud = false + +[GOOS] + linux = false + windows = false + +[EnvMatrix] + DATABRICKS_BUNDLE_ENGINE = ["terraform", "direct"] diff --git a/acceptance/bundle/state/force_pull_commands/output.txt b/acceptance/bundle/state/force_pull_commands/output.txt new file mode 100644 index 0000000000..a2f9010918 --- /dev/null +++ b/acceptance/bundle/state/force_pull_commands/output.txt @@ -0,0 +1,35 @@ + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/force-pull-commands/default/files... +Deploying resources... +Updating deployment state... +Deployment complete! + +=== Modify PATH so that real open is not run +=== bundle summary without --force-pull: no remote state read + +>>> [CLI] bundle summary + +=== bundle summary --force-pull: remote state read + +>>> [CLI] bundle summary --force-pull +{ + "method": "GET", + "path": "/api/2.0/workspace-files/Workspace/Users/[USERNAME]/.bundle/force-pull-commands/default/state/STATE_FILENAME" +} + +=== bundle open without --force-pull: no remote state read + +>>> [CLI] bundle open foo +Opening browser at [DATABRICKS_URL]/jobs/[NUMID]?o=[NUMID] +Error: exec: "open": cannot run executable found relative to current directory + +=== bundle open --force-pull: remote state read + +>>> [CLI] bundle open foo --force-pull +Opening browser at [DATABRICKS_URL]/jobs/[NUMID]?o=[NUMID] +Error: exec: "open": cannot run executable found relative to current directory +{ + "method": "GET", + "path": "/api/2.0/workspace-files/Workspace/Users/[USERNAME]/.bundle/force-pull-commands/default/state/STATE_FILENAME" +} diff --git a/acceptance/bundle/state/force_pull_commands/script b/acceptance/bundle/state/force_pull_commands/script new file mode 100644 index 0000000000..177d047d2e --- /dev/null +++ b/acceptance/bundle/state/force_pull_commands/script @@ -0,0 +1,21 @@ +trace $CLI bundle deploy > /dev/null +rm -f out.requests.txt + +title "Modify PATH so that real open is not run" +export PATH=.:$PATH + +title "bundle summary without --force-pull: no remote state read\n" +trace $CLI bundle summary > /dev/null +print_requests.py --get //workspace-files/ + +title "bundle summary --force-pull: remote state read\n" +trace $CLI bundle summary --force-pull > /dev/null +print_requests.py --get //workspace-files/ + +title "bundle open without --force-pull: no remote state read\n" +musterr trace $CLI bundle open foo > /dev/null +print_requests.py --get //workspace-files/ + +title "bundle open --force-pull: remote state read\n" +musterr trace $CLI bundle open foo --force-pull > /dev/null +print_requests.py --get //workspace-files/ diff --git a/acceptance/bundle/state/force_pull_commands/test.toml b/acceptance/bundle/state/force_pull_commands/test.toml new file mode 100644 index 0000000000..1a1df4f588 --- /dev/null +++ b/acceptance/bundle/state/force_pull_commands/test.toml @@ -0,0 +1,17 @@ +Local = true +Cloud = false +RecordRequests = true + +# bundle open opens a browser; restrict to darwin to get stable output +# (mirrors acceptance/bundle/open/test.toml). +GOOS.windows = false +GOOS.linux = false + +Ignore = [".databricks"] + +[EnvMatrix] + DATABRICKS_BUNDLE_ENGINE = ["terraform", "direct"] + +[[Repls]] +Old = '(resources\.json|terraform\.tfstate)' +New = 'STATE_FILENAME' diff --git a/cmd/bundle/open.go b/cmd/bundle/open.go index e7fa960c3d..ab75505e2f 100644 --- a/cmd/bundle/open.go +++ b/cmd/bundle/open.go @@ -75,7 +75,8 @@ Use after deployment to quickly navigate to your resources in the workspace.`, arg, err = resolveOpenArgument(ctx, b, args) return err }, - InitIDs: true, + AlwaysPull: forcePull, + InitIDs: true, }) if err != nil { return err diff --git a/cmd/bundle/summary.go b/cmd/bundle/summary.go index 9f2aa3e54b..ff7356e2c6 100644 --- a/cmd/bundle/summary.go +++ b/cmd/bundle/summary.go @@ -46,6 +46,7 @@ Useful after deployment to see what was created and where to find it.`, } else { b, err := utils.ProcessBundle(cmd, utils.ProcessOptions{ ReadState: true, + AlwaysPull: forcePull, IncludeLocations: includeLocations, InitIDs: true, })