Skip to content

Added support for experimental scripts section - #632

Merged
andrewnester merged 6 commits into
mainfrom
experimental-scripts
Sep 14, 2023
Merged

Added support for experimental scripts section#632
andrewnester merged 6 commits into
mainfrom
experimental-scripts

Conversation

@andrewnester

Copy link
Copy Markdown
Contributor

Changes

Added support for experimental scripts section

It allows execution of arbitrary bash commands during certain bundle lifecycle steps.

Tests

Example of configuration

bundle:
name: wheel-taskworkspace:
host: ***experimental:
scripts:
prebuild: | echo 'Prebuild 1' echo 'Prebuild 2'postbuild: "echo 'Postbuild 1' && echo 'Postbuild 2'"predeploy: | echo 'Checking go version...' go versionpostdeploy: | echo 'Checking python version...' python --versionresources:
jobs:
test_job:
name: "[${bundle.environment}] My Wheel Job"tasks:
- task_key: TestTaskexisting_cluster_id: "***"python_wheel_task:
package_name: "my_test_code"entry_point: "run"libraries:
- whl: ./dist/*.whl

Output

andrew.nester@HFW9Y94129 wheel % databricks bundle deploy
artifacts.whl.AutoDetect: Detecting Python wheel project...
artifacts.whl.AutoDetect: Found Python wheel project at /Users/andrew.nester/dabs/wheel
'Prebuild 1''Prebuild 2'
artifacts.whl.Build(my_test_code): Building...
artifacts.whl.Build(my_test_code): Build succeeded
'Postbuild 1''Postbuild 2''Checking go version...'
go version go1.19.9 darwin/arm64
Starting upload of bundle files
Uploaded bundle files at /Users/andrew.nester@databricks.com/.bundle/wheel-task/default/files!
artifacts.Upload(my_test_code-0.0.0a0-py3-none-any.whl): Uploading...
artifacts.Upload(my_test_code-0.0.0a0-py3-none-any.whl): Upload succeeded
Starting resource deployment
Resource deployment completed!'Checking python version...'
Python 2.7.18

@shreyas-goenkashreyas-goenka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment threadbundle/scripts/scripts.go Outdated
Comment threadbundle/scripts/scripts.go Outdated
Comment threadbundle/scripts/scripts.go Outdated
Comment threadbundle/scripts/scripts.go Outdated
Comment threadbundle/scripts/scripts.go Outdated
Comment threadbundle/scripts/scripts.go Outdated
Comment threadbundle/scripts/scripts.go Outdated
Comment threadbundle/scripts/scripts.go Outdated
Comment threadbundle/scripts/scripts.go Outdated
@kanterov

Copy link
Copy Markdown
Collaborator

I've given it a try, and it worked for "databricks bundle deploy". I've found a few issues:

  1. Files generated in "prebuild" can't be used in "include"
  2. "prebuild" isn't called for "databricks bundle validate", so it can't be used in CI checks

@andrewnester

Copy link
Copy Markdown
ContributorAuthor

@kanterov Build is not part of validate command so the hook is not executed. I've added postinit hook which can be used in CI and executed after initialisation.

Comment threadbundle/config/scripts.go Outdated

func DefaultMutators() []bundle.Mutator {
return []bundle.Mutator{
scripts.Execute(config.ScriptPreInit),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this is not where this hook should be executed in the non-experimental version.

Before executing anything, we'd need to have already done:

  1. target selection,
  2. variable interpolation,
  3. confirmed that our workspace is configured correctly.

Then to pick up new configuration (e.g. resources) from these scripts, we'd need a different mechanism. For example, we could set an environment variable DATABRICKS_BUNDLE_RESOURCES to some temporary file path that the script can write to, and we subsequently load + merge.

Given that this will be empty/a no-op for regular usage, I'm OK merging this and addressing this later.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with the above. Let's merge at current version as an experimental and iterate over it

@andrewnester
andrewnester added this pull request to the merge queueSep 14, 2023
Merged via the queue into main with commit 953dcb4Sep 14, 2023
@andrewnester
andrewnester deleted the experimental-scripts branch September 14, 2023 10:20
pietern added a commit that referenced this pull request Sep 20, 2023
Bundles:
* Use enums for default python template ([#765](#765)).
* Make bundle deploy work if no resources are defined ([#767](#767)).
* Added support for experimental scripts section ([#632](#632)).
* Error when unknown keys are encounters during template execution ([#766](#766)).
* Fall back to full Git clone if shallow clone is not supported ([#775](#775)).
* Enable environment overrides for job tasks ([#779](#779)).
* Increase timeout waiting for job run to 1 day ([#786](#786)).
Internal:
* Update Go SDK to v0.19.3 (unreleased) ([#778](#778)).
@pieternpietern mentioned this pull request Sep 20, 2023
github-merge-queueBot pushed a commit that referenced this pull request Sep 20, 2023
Bundles:
* Use enums for default python template
([#765](#765)).
* Make bundle deploy work if no resources are defined
([#767](#767)).
* Added support for experimental scripts section
([#632](#632)).
* Error when unknown keys are encounters during template execution
([#766](#766)).
* Fall back to full Git clone if shallow clone is not supported
([#775](#775)).
* Enable environment overrides for job tasks
([#779](#779)).
* Increase timeout waiting for job run to 1 day
([#786](#786)).
Internal:
* Update Go SDK to v0.19.3 (unreleased)
([#778](#778)).
hectorcast-db pushed a commit that referenced this pull request Oct 13, 2023
## Changes
Added support for experimental scripts section
It allows execution of arbitrary bash commands during certain bundle
lifecycle steps.
## Tests
Example of configuration
```yaml
bundle:
name: wheel-task
workspace:
host: ***
experimental:
scripts:
prebuild: |
echo 'Prebuild 1'
echo 'Prebuild 2'
postbuild: "echo 'Postbuild 1' && echo 'Postbuild 2'" predeploy: |
echo 'Checking go version...'
go version
postdeploy: |
echo 'Checking python version...'
python --version
resources:
jobs:
test_job:
name: "[${bundle.environment}] My Wheel Job"
tasks:
- task_key: TestTask
existing_cluster_id: "***"
python_wheel_task:
package_name: "my_test_code"
entry_point: "run"
libraries:
- whl: ./dist/*.whl
```
Output
```bash
andrew.nester@HFW9Y94129 wheel % databricks bundle deploy
artifacts.whl.AutoDetect: Detecting Python wheel project...
artifacts.whl.AutoDetect: Found Python wheel project at /Users/andrew.nester/dabs/wheel
'Prebuild 1'
'Prebuild 2'
artifacts.whl.Build(my_test_code): Building...
artifacts.whl.Build(my_test_code): Build succeeded
'Postbuild 1'
'Postbuild 2'
'Checking go version...'
go version go1.19.9 darwin/arm64
Starting upload of bundle files
Uploaded bundle files at /Users/andrew.nester@databricks.com/.bundle/wheel-task/default/files!
artifacts.Upload(my_test_code-0.0.0a0-py3-none-any.whl): Uploading...
artifacts.Upload(my_test_code-0.0.0a0-py3-none-any.whl): Upload succeeded
Starting resource deployment
Resource deployment completed!
'Checking python version...'
Python 2.7.18
```
hectorcast-db pushed a commit that referenced this pull request Oct 13, 2023
Bundles:
* Use enums for default python template
([#765](#765)).
* Make bundle deploy work if no resources are defined
([#767](#767)).
* Added support for experimental scripts section
([#632](#632)).
* Error when unknown keys are encounters during template execution
([#766](#766)).
* Fall back to full Git clone if shallow clone is not supported
([#775](#775)).
* Enable environment overrides for job tasks
([#779](#779)).
* Increase timeout waiting for job run to 1 day
([#786](#786)).
Internal:
* Update Go SDK to v0.19.3 (unreleased)
([#778](#778)).
denik pushed a commit that referenced this pull request May 20, 2026
## Changes
Added support for experimental scripts section
It allows execution of arbitrary bash commands during certain bundle
lifecycle steps.
## Tests
Example of configuration
```yaml
bundle:
name: wheel-task
workspace:
host: ***
experimental:
scripts:
prebuild: |
echo 'Prebuild 1'
echo 'Prebuild 2'
postbuild: "echo 'Postbuild 1' && echo 'Postbuild 2'" predeploy: |
echo 'Checking go version...'
go version
postdeploy: |
echo 'Checking python version...'
python --version
resources:
jobs:
test_job:
name: "[${bundle.environment}] My Wheel Job"
tasks:
- task_key: TestTask
existing_cluster_id: "***"
python_wheel_task:
package_name: "my_test_code"
entry_point: "run"
libraries:
- whl: ./dist/*.whl
```
Output
```bash
andrew.nester@HFW9Y94129 wheel % databricks bundle deploy
artifacts.whl.AutoDetect: Detecting Python wheel project...
artifacts.whl.AutoDetect: Found Python wheel project at /Users/andrew.nester/dabs/wheel
'Prebuild 1'
'Prebuild 2'
artifacts.whl.Build(my_test_code): Building...
artifacts.whl.Build(my_test_code): Build succeeded
'Postbuild 1'
'Postbuild 2'
'Checking go version...'
go version go1.19.9 darwin/arm64
Starting upload of bundle files
Uploaded bundle files at /Users/andrew.nester@databricks.com/.bundle/wheel-task/default/files!
artifacts.Upload(my_test_code-0.0.0a0-py3-none-any.whl): Uploading...
artifacts.Upload(my_test_code-0.0.0a0-py3-none-any.whl): Upload succeeded
Starting resource deployment
Resource deployment completed!
'Checking python version...'
Python 2.7.18
```
denik pushed a commit that referenced this pull request May 20, 2026
Bundles:
* Use enums for default python template
([#765](#765)).
* Make bundle deploy work if no resources are defined
([#767](#767)).
* Added support for experimental scripts section
([#632](#632)).
* Error when unknown keys are encounters during template execution
([#766](#766)).
* Fall back to full Git clone if shallow clone is not supported
([#775](#775)).
* Enable environment overrides for job tasks
([#779](#779)).
* Increase timeout waiting for job run to 1 day
([#786](#786)).
Internal:
* Update Go SDK to v0.19.3 (unreleased)
([#778](#778)).
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@andrewnester@kanterov@pietern@mgyucht@lennartkats-db@shreyas-goenka