Skip to content

Commit c75194b

Browse files
authored
Add support for configuring app.yaml options for apps via bundle config (#4271)
## Changes Add support for configuring app.yaml options for apps via bundle config This change uses new fields from Apps.Deploy call: `Command` and `EnvVars`. ## Why This change allows users to configure their Databricks Apps differently for different targets Fixes #3679 ## Tests Added an acceptance test <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent d34bce2 commit c75194b

14 files changed

Lines changed: 229 additions & 11 deletions

File tree

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ To disable this, set the environment variable DATABRICKS_CACHE_ENABLED to false.
1010
* Add commands to pipelines command group ([#4275](https://github.com/databricks/cli/pull/4275))
1111

1212
### Bundles
13+
* Add support for configuring app.yaml options for apps via bundle config ([#4271](https://github.com/databricks/cli/pull/4271))
1314
* Enable caching user identity by default ([#4202](https://github.com/databricks/cli/pull/4202))
1415
* Do not show single node warning when is_single_node option is explicitly set ([#4272](https://github.com/databricks/cli/pull/4272))
1516
* Fix false positive folder permission warnings and make them more actionable ([#4216](https://github.com/databricks/cli/pull/4216))

acceptance/bundle/refschema/out.fields.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ resources.apps.*.compute_size apps.ComputeSize ALL
9999
resources.apps.*.compute_status *apps.ComputeStatus ALL
100100
resources.apps.*.compute_status.message string ALL
101101
resources.apps.*.compute_status.state apps.ComputeState ALL
102+
resources.apps.*.config *resources.AppConfig INPUT
103+
resources.apps.*.config.command []string INPUT
104+
resources.apps.*.config.command[*] string INPUT
105+
resources.apps.*.config.env []resources.AppEnvVar INPUT
106+
resources.apps.*.config.env[*] resources.AppEnvVar INPUT
107+
resources.apps.*.config.env[*].name string INPUT
108+
resources.apps.*.config.env[*].value string INPUT
102109
resources.apps.*.create_time string ALL
103110
resources.apps.*.creator string ALL
104111
resources.apps.*.default_source_code_path string ALL
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import os
2+
3+
from flask import Flask
4+
5+
app = Flask(__name__)
6+
7+
8+
@app.route("/")
9+
def home():
10+
return "Hello from inline config app!"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
command:
2+
- python
3+
- app.py
4+
5+
env:
6+
- name: MY_ENV_VAR
7+
value: test_value_old
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
bundle:
2+
name: app-inline-config-$UNIQUE_NAME
3+
4+
resources:
5+
apps:
6+
myapp:
7+
name: $UNIQUE_NAME
8+
description: my_app_description
9+
source_code_path: ./app
10+
config:
11+
command: ["flask", "--app", "app", "run"]
12+
env:
13+
- name: MY_ENV_VAR
14+
value: test_value
15+
- name: ANOTHER_VAR
16+
value: another_value

acceptance/bundle/resources/apps/inline_config/out.test.toml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
>>> [CLI] bundle deploy
3+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/app-inline-config-[UNIQUE_NAME]/default/files...
4+
Deploying resources...
5+
Updating deployment state...
6+
Deployment complete!
7+
8+
>>> [CLI] apps get-deployment [UNIQUE_NAME] [DEPLOYMENT_ID]
9+
{
10+
"command": [
11+
"flask",
12+
"--app",
13+
"app",
14+
"run"
15+
],
16+
"env_vars": [
17+
{
18+
"name": "MY_ENV_VAR"
19+
},
20+
{
21+
"name": "ANOTHER_VAR"
22+
}
23+
]
24+
}
25+
26+
>>> [CLI] bundle destroy --auto-approve
27+
The following resources will be deleted:
28+
delete resources.apps.myapp
29+
30+
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/app-inline-config-[UNIQUE_NAME]/default
31+
32+
Deleting files...
33+
Destroy complete!
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
envsubst < databricks.yml.tmpl > databricks.yml
2+
3+
cleanup() {
4+
trace $CLI bundle destroy --auto-approve
5+
rm out.requests.txt
6+
}
7+
trap cleanup EXIT
8+
9+
trace $CLI bundle deploy
10+
11+
APP_NAME=$($CLI bundle summary -o json | jq -r '.resources.apps.myapp.name')
12+
$CLI bundle run myapp > /dev/null 2>&1
13+
14+
DEPLOYMENT_ID=$($CLI apps get "$APP_NAME" | jq -r '.active_deployment.deployment_id')
15+
echo $DEPLOYMENT_ID:DEPLOYMENT_ID >> ACC_REPLS
16+
17+
trace $CLI apps get-deployment "$APP_NAME" "$DEPLOYMENT_ID" | jq '{command, env_vars}'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Local = false
2+
Cloud = true

bundle/config/resources/apps.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,25 @@ import (
1010
"github.com/databricks/databricks-sdk-go/service/apps"
1111
)
1212

13+
// AppConfig represents the inline app.yaml configuration structure.
14+
// This matches the structure of an app.yaml file that can be used to configure how the app runs.
15+
type AppConfig struct {
16+
// Command specifies the command to run the app (e.g., ["streamlit", "run", "app.py"])
17+
Command []string `json:"command,omitempty" yaml:"command,omitempty"`
18+
19+
// Env contains environment variables to set for the app
20+
Env []AppEnvVar `json:"env,omitempty" yaml:"env,omitempty"`
21+
}
22+
23+
// AppEnvVar represents an environment variable configuration for an app
24+
type AppEnvVar struct {
25+
// Name is the environment variable name
26+
Name string `json:"name" yaml:"name"`
27+
28+
// Value is the environment variable value
29+
Value string `json:"value" yaml:"value"`
30+
}
31+
1332
type App struct {
1433
BaseResource
1534
apps.App // nolint App struct also defines Id and URL field with the same json tag "id" and "url"
@@ -18,6 +37,11 @@ type App struct {
1837
// on local disk and to the corresponding workspace path during app deployment.
1938
SourceCodePath string `json:"source_code_path"`
2039

40+
// Config represents inline app.yaml configuration for the app.
41+
// When specified, this configuration is written to an app.yaml file in the source code path during deployment.
42+
// This allows users to define app configuration directly in the bundle YAML instead of maintaining a separate app.yaml file.
43+
Config *AppConfig `json:"config,omitempty"`
44+
2145
Permissions []AppPermission `json:"permissions,omitempty"`
2246
}
2347

0 commit comments

Comments
 (0)