Skip to content

Commit 7b39509

Browse files
committed
added test for changing config
1 parent 8c21f2d commit 7b39509

File tree

9 files changed

+266
-5
lines changed

9 files changed

+266
-5
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Hello world!")
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
bundle:
2+
name: config-drift-$UNIQUE_NAME
3+
4+
resources:
5+
apps:
6+
myapp:
7+
name: $UNIQUE_NAME
8+
description: my_app
9+
source_code_path: ./app
10+
config:
11+
command:
12+
- python
13+
- app.py
14+
env:
15+
- name: MY_VAR
16+
value: original_value
17+
lifecycle:
18+
started: true
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
{
2+
"active_deployment": {
3+
"action": "skip",
4+
"reason": "spec:output_only",
5+
"remote": {
6+
"command": [
7+
"streamlit",
8+
"run",
9+
"dashboard.py"
10+
],
11+
"deployment_id": "deploy-[NUMID]",
12+
"env_vars": [
13+
{
14+
"name": "MY_VAR",
15+
"value": "changed_value"
16+
},
17+
{
18+
"name": "NEW_VAR",
19+
"value": "new_value"
20+
}
21+
],
22+
"mode": "SNAPSHOT",
23+
"source_code_path": "./app",
24+
"status": {
25+
"message": "Deployment succeeded.",
26+
"state": "SUCCEEDED"
27+
}
28+
}
29+
},
30+
"app_status": {
31+
"action": "skip",
32+
"reason": "spec:output_only",
33+
"remote": {
34+
"message": "Application is running.",
35+
"state": "RUNNING"
36+
}
37+
},
38+
"compute_status": {
39+
"action": "skip",
40+
"reason": "spec:output_only",
41+
"remote": {
42+
"message": "App compute is active.",
43+
"state": "ACTIVE"
44+
}
45+
},
46+
"config.command": {
47+
"action": "update",
48+
"old": [
49+
"python",
50+
"app.py"
51+
],
52+
"new": [
53+
"python",
54+
"app.py"
55+
],
56+
"remote": [
57+
"streamlit",
58+
"run",
59+
"dashboard.py"
60+
]
61+
},
62+
"config.env": {
63+
"action": "update",
64+
"old": [
65+
{
66+
"name": "MY_VAR",
67+
"value": "original_value"
68+
}
69+
],
70+
"new": [
71+
{
72+
"name": "MY_VAR",
73+
"value": "original_value"
74+
}
75+
],
76+
"remote": [
77+
{
78+
"name": "MY_VAR",
79+
"value": "changed_value"
80+
},
81+
{
82+
"name": "NEW_VAR",
83+
"value": "new_value"
84+
}
85+
]
86+
},
87+
"id": {
88+
"action": "skip",
89+
"reason": "spec:output_only",
90+
"remote": "1000"
91+
},
92+
"service_principal_client_id": {
93+
"action": "skip",
94+
"reason": "spec:output_only",
95+
"remote": "[UUID]"
96+
},
97+
"service_principal_id": {
98+
"action": "skip",
99+
"reason": "spec:output_only",
100+
"remote": [NUMID]
101+
},
102+
"service_principal_name": {
103+
"action": "skip",
104+
"reason": "spec:output_only",
105+
"remote": "app-[UNIQUE_NAME]"
106+
},
107+
"source_code_path": {
108+
"action": "skip",
109+
"reason": "local_only",
110+
"old": "/Workspace/Users/[USERNAME]/.bundle/config-drift-[UNIQUE_NAME]/default/files/app",
111+
"new": "/Workspace/Users/[USERNAME]/.bundle/config-drift-[UNIQUE_NAME]/default/files/app"
112+
},
113+
"url": {
114+
"action": "skip",
115+
"reason": "spec:output_only",
116+
"remote": "[UNIQUE_NAME]-123.cloud.databricksapps.com"
117+
}
118+
}

acceptance/bundle/resources/apps/config-drift/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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
=== First deploy: creates app
3+
>>> [CLI] bundle deploy
4+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/config-drift-[UNIQUE_NAME]/default/files...
5+
Deploying resources...
6+
Updating deployment state...
7+
Deployment complete!
8+
9+
=== Second deploy: pushes code with config
10+
>>> [CLI] bundle deploy
11+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/config-drift-[UNIQUE_NAME]/default/files...
12+
Deploying resources...
13+
✓ Deployment succeeded.
14+
Updating deployment state...
15+
Deployment complete!
16+
17+
=== Verify no drift after deploy
18+
>>> [CLI] bundle plan
19+
Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged
20+
21+
=== Simulate out-of-band deployment with changed command and env
22+
=== Plan should detect config drift
23+
>>> [CLI] bundle plan
24+
update apps.myapp
25+
26+
Plan: 0 to add, 1 to change, 0 to delete, 0 unchanged
27+
28+
=== Redeploy to fix drift
29+
>>> [CLI] bundle deploy
30+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/config-drift-[UNIQUE_NAME]/default/files...
31+
Deploying resources...
32+
✓ Deployment succeeded.
33+
Updating deployment state...
34+
Deployment complete!
35+
36+
=== Verify no drift after fix
37+
>>> [CLI] bundle plan
38+
Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged
39+
40+
=== Simulate out-of-band deployment with git_source added
41+
=== Plan should detect git_source drift
42+
>>> [CLI] bundle plan
43+
update apps.myapp
44+
45+
Plan: 0 to add, 1 to change, 0 to delete, 0 unchanged
46+
47+
>>> [CLI] bundle destroy --auto-approve
48+
The following resources will be deleted:
49+
delete resources.apps.myapp
50+
51+
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/config-drift-[UNIQUE_NAME]/default
52+
53+
Deleting files...
54+
Destroy complete!
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
envsubst < databricks.yml.tmpl > databricks.yml
2+
3+
cleanup() {
4+
trace $CLI bundle destroy --auto-approve
5+
rm -f out.requests.txt
6+
}
7+
trap cleanup EXIT
8+
9+
title "First deploy: creates app"
10+
trace $CLI bundle deploy
11+
12+
title "Second deploy: pushes code with config"
13+
trace $CLI bundle deploy
14+
15+
title "Verify no drift after deploy"
16+
trace $CLI bundle plan
17+
18+
title "Simulate out-of-band deployment with changed command and env"
19+
$CLI apps deploy $UNIQUE_NAME --no-wait --json '{
20+
"source_code_path": "./app",
21+
"mode": "SNAPSHOT",
22+
"command": ["streamlit", "run", "dashboard.py"],
23+
"env_vars": [
24+
{"name": "MY_VAR", "value": "changed_value"},
25+
{"name": "NEW_VAR", "value": "new_value"}
26+
]
27+
}' > /dev/null
28+
29+
title "Plan should detect config drift"
30+
trace $CLI bundle plan
31+
$CLI bundle plan -o json | jq '.plan."resources.apps.myapp".changes.config // .plan."resources.apps.myapp".changes' > out.plan.direct.json
32+
33+
title "Redeploy to fix drift"
34+
trace $CLI bundle deploy
35+
36+
title "Verify no drift after fix"
37+
trace $CLI bundle plan
38+
39+
title "Simulate out-of-band deployment with git_source added"
40+
$CLI apps deploy $UNIQUE_NAME --no-wait --json '{
41+
"source_code_path": "./app",
42+
"mode": "SNAPSHOT",
43+
"git_source": {"branch": "feature-branch"},
44+
"command": ["python", "app.py"],
45+
"env_vars": [{"name": "MY_VAR", "value": "original_value"}]
46+
}' > /dev/null
47+
48+
title "Plan should detect git_source drift"
49+
trace $CLI bundle plan
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Local = true
2+
Cloud = true
3+
RecordRequests = true
4+
5+
Ignore = [".databricks", "databricks.yml"]
6+
7+
[EnvMatrix]
8+
DATABRICKS_BUNDLE_ENGINE = ["direct"]

bundle/direct/dresources/app.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,9 @@ func deploymentToAppConfig(d *apps.AppDeployment) *resources.AppConfig {
266266
if len(d.Command) == 0 && len(d.EnvVars) == 0 {
267267
return nil
268268
}
269-
config := &resources.AppConfig{}
270-
if len(d.Command) > 0 {
271-
config.Command = d.Command
269+
config := &resources.AppConfig{
270+
Command: d.Command,
271+
Env: nil,
272272
}
273273
if len(d.EnvVars) > 0 {
274274
config.Env = make([]resources.AppEnvVar, len(d.EnvVars))
@@ -321,7 +321,12 @@ func (r *ResourceApp) waitForApp(ctx context.Context, w *databricks.WorkspaceCli
321321
return nil, err
322322
}
323323
started := !isComputeStopped(app)
324-
remote := &AppRemote{App: *app, Lifecycle: &AppStateLifecycle{Started: &started}}
324+
remote := &AppRemote{
325+
App: *app,
326+
Config: nil,
327+
GitSource: nil,
328+
Lifecycle: &AppStateLifecycle{Started: &started},
329+
}
325330
if app.ActiveDeployment != nil {
326331
remote.GitSource = app.ActiveDeployment.GitSource
327332
remote.Config = deploymentToAppConfig(app.ActiveDeployment)

libs/testserver/apps.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (s *FakeWorkspace) AppsGetUpdate(_ Request, name string) Response {
9292
func (s *FakeWorkspace) AppsCreateDeployment(req Request, name string) Response {
9393
defer s.LockUnlock()()
9494

95-
_, ok := s.Apps[name]
95+
app, ok := s.Apps[name]
9696
if !ok {
9797
return Response{StatusCode: 404}
9898
}
@@ -108,6 +108,9 @@ func (s *FakeWorkspace) AppsCreateDeployment(req Request, name string) Response
108108
Message: "Deployment succeeded.",
109109
}
110110

111+
app.ActiveDeployment = &deployment
112+
s.Apps[name] = app
113+
111114
return Response{Body: deployment}
112115
}
113116

0 commit comments

Comments
 (0)