Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for experimental scripts section #632

Merged
merged 6 commits into from
Sep 14, 2023

Conversation

andrewnester
Copy link
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-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

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

Copy link
Contributor

@shreyas-goenka shreyas-goenka left a comment

Choose a reason for hiding this comment

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

LGTM!

bundle/scripts/scripts.go Outdated Show resolved Hide resolved
bundle/scripts/scripts.go Outdated Show resolved Hide resolved
bundle/scripts/scripts.go Outdated Show resolved Hide resolved
bundle/scripts/scripts.go Outdated Show resolved Hide resolved
bundle/scripts/scripts.go Outdated Show resolved Hide resolved
bundle/scripts/scripts.go Outdated Show resolved Hide resolved
bundle/scripts/scripts.go Outdated Show resolved Hide resolved
bundle/scripts/scripts.go Outdated Show resolved Hide resolved
bundle/scripts/scripts.go Outdated Show resolved Hide resolved
@kanterov
Copy link
Contributor

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
Contributor Author

@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.

bundle/config/scripts.go Outdated Show resolved Hide resolved
)

func DefaultMutators() []bundle.Mutator {
return []bundle.Mutator{
scripts.Execute(config.ScriptPreInit),
Copy link
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
Contributor Author

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 queue Sep 14, 2023
Merged via the queue into main with commit 953dcb4 Sep 14, 2023
4 checks passed
@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)).
@pietern pietern mentioned this pull request Sep 20, 2023
github-merge-queue bot 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)).
Sign up for free to 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.

None yet

6 participants