mirror of https://github.com/databricks/cli.git
execute scripts from bundle root
This commit is contained in:
parent
6002e0d040
commit
1b5ff48873
|
@ -17,5 +17,8 @@
|
||||||
"python.envFile": "${workspaceRoot}/.env",
|
"python.envFile": "${workspaceRoot}/.env",
|
||||||
"python.analysis.stubPath": ".vscode",
|
"python.analysis.stubPath": ".vscode",
|
||||||
"jupyter.interactiveWindow.cellMarker.codeRegex": "^# COMMAND ----------|^# Databricks notebook source|^(#\\s*%%|#\\s*\\<codecell\\>|#\\s*In\\[\\d*?\\]|#\\s*In\\[ \\])",
|
"jupyter.interactiveWindow.cellMarker.codeRegex": "^# COMMAND ----------|^# Databricks notebook source|^(#\\s*%%|#\\s*\\<codecell\\>|#\\s*In\\[\\d*?\\]|#\\s*In\\[ \\])",
|
||||||
"jupyter.interactiveWindow.cellMarker.default": "# COMMAND ----------"
|
"jupyter.interactiveWindow.cellMarker.default": "# COMMAND ----------",
|
||||||
|
"files.associations": {
|
||||||
|
"script": "shellscript"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
>>> errcode [CLI] bundle exec -- echo hello
|
>>> [CLI] bundle exec -- echo hello, world
|
||||||
hello
|
hello, world
|
||||||
Error: Error waiting for command: exec: Wait was already called
|
|
||||||
|
|
||||||
Exit code: 1
|
>>> [CLI] bundle exec -- pwd
|
||||||
|
[TMPDIR]
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
trace errcode $CLI bundle exec -- echo hello
|
trace $CLI bundle exec -- echo "hello, world"
|
||||||
|
|
||||||
|
trace $CLI bundle exec -- pwd
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
bundle:
|
||||||
|
name: foobar
|
|
@ -0,0 +1,8 @@
|
||||||
|
|
||||||
|
>>> cd a/b/c
|
||||||
|
|
||||||
|
>>> pwd
|
||||||
|
[TMPDIR]/a/b/c
|
||||||
|
|
||||||
|
>>> [CLI] bundle exec -- pwd
|
||||||
|
[TMPDIR]
|
|
@ -0,0 +1,6 @@
|
||||||
|
trace cd a/b/c
|
||||||
|
|
||||||
|
trace pwd
|
||||||
|
|
||||||
|
# Scripts that bundle exec executes should run from the bundle root.
|
||||||
|
trace $CLI bundle exec -- pwd
|
|
@ -0,0 +1,2 @@
|
||||||
|
bundle:
|
||||||
|
name: foobar
|
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
>>> [CLI] bundle exec -- echo hello
|
||||||
|
hello
|
||||||
|
|
||||||
|
>>> [CLI] bundle exec -- pwd
|
||||||
|
[TMPDIR]
|
|
@ -0,0 +1,8 @@
|
||||||
|
export DATABRICKS_HOST=""
|
||||||
|
export DATABRICKS_TOKEN=""
|
||||||
|
|
||||||
|
# Confirm that bundle exec works for commands that do not require authentication,
|
||||||
|
# even if authentication is not provided.
|
||||||
|
trace $CLI bundle exec -- echo hello
|
||||||
|
|
||||||
|
trace $CLI bundle exec -- pwd
|
|
@ -0,0 +1,5 @@
|
||||||
|
|
||||||
|
>>> [CLI] bundle exec -- echo hello
|
||||||
|
Error: unable to locate bundle root: databricks.yml not found
|
||||||
|
|
||||||
|
Exit code: 1
|
|
@ -0,0 +1 @@
|
||||||
|
trace $CLI bundle exec -- echo hello
|
|
@ -24,7 +24,13 @@ func newExecCommand() *cobra.Command {
|
||||||
Use: "exec",
|
Use: "exec",
|
||||||
Short: "Execute a command using the same authentication context as the bundle",
|
Short: "Execute a command using the same authentication context as the bundle",
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: cobra.MinimumNArgs(1),
|
||||||
Long: `Examples:
|
// TODO: format once we have all the documentation here.
|
||||||
|
// TODO: implement and pass the cwd environment variable. Maybe we can defer
|
||||||
|
// it until we have a scripts section.
|
||||||
|
Long: `
|
||||||
|
Note: This command executes scripts
|
||||||
|
|
||||||
|
Examples:
|
||||||
1. databricks bundle exec -- echo hello
|
1. databricks bundle exec -- echo hello
|
||||||
2. databricks bundle exec -- /bin/bash -c "echo hello""
|
2. databricks bundle exec -- /bin/bash -c "echo hello""
|
||||||
3. databricks bundle exec -- uv run pytest"`,
|
3. databricks bundle exec -- uv run pytest"`,
|
||||||
|
@ -36,7 +42,7 @@ func newExecCommand() *cobra.Command {
|
||||||
// Load the bundle configuration to get the authentication credentials
|
// Load the bundle configuration to get the authentication credentials
|
||||||
// set in the context.
|
// set in the context.
|
||||||
// TODO: What happens when no bundle is configured?
|
// TODO: What happens when no bundle is configured?
|
||||||
_, diags := root.MustConfigureBundle(cmd)
|
b, diags := root.MustConfigureBundle(cmd)
|
||||||
if diags.HasError() {
|
if diags.HasError() {
|
||||||
return diags.Error()
|
return diags.Error()
|
||||||
}
|
}
|
||||||
|
@ -44,7 +50,11 @@ func newExecCommand() *cobra.Command {
|
||||||
childCmd := exec.Command(args[0], args[1:]...)
|
childCmd := exec.Command(args[0], args[1:]...)
|
||||||
childCmd.Env = auth.ProcessEnv(root.ConfigUsed(cmd.Context()))
|
childCmd.Env = auth.ProcessEnv(root.ConfigUsed(cmd.Context()))
|
||||||
|
|
||||||
// Create pipes for stdout and stderr
|
// Execute all scripts from the bundle root directory.
|
||||||
|
childCmd.Dir = b.BundleRootPath
|
||||||
|
|
||||||
|
// Create pipes for stdout and stderr.
|
||||||
|
// TODO: Test streaming of this? Is there a way?
|
||||||
stdout, err := childCmd.StdoutPipe()
|
stdout, err := childCmd.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error creating stdout pipe: %w", err)
|
return fmt.Errorf("Error creating stdout pipe: %w", err)
|
||||||
|
@ -87,8 +97,7 @@ func newExecCommand() *cobra.Command {
|
||||||
if exitErr, ok := err.(*exec.ExitError); ok {
|
if exitErr, ok := err.(*exec.ExitError); ok {
|
||||||
return fmt.Errorf("Command exited with code: %d", exitErr.ExitCode())
|
return fmt.Errorf("Command exited with code: %d", exitErr.ExitCode())
|
||||||
}
|
}
|
||||||
|
if err != nil {
|
||||||
if err := childCmd.Wait(); err != nil {
|
|
||||||
return fmt.Errorf("Error waiting for command: %w", err)
|
return fmt.Errorf("Error waiting for command: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue