Skip to content

Commit a0e0f98

Browse files
authored
Added support for git_source and git_repository for Apps (#4538)
## Changes Added support for git_source and git_repository for Apps ## Why These are new fields exposed by Apps API ## Tests Added an acceptance test. Cloud test temporarily disabled until the feature is enabled in the workspace <!-- 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 a50e230 commit a0e0f98

File tree

16 files changed

+223
-4
lines changed

16 files changed

+223
-4
lines changed

NEXT_CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
### CLI
66
* Add `completion install`, `uninstall`, and `status` subcommands ([#4581](https://github.com/databricks/cli/pull/4581))
77

8-
### Internal
8+
### Bundles
9+
* Added support for git_source and git_repository for Apps ([#4538](https://github.com/databricks/cli/pull/4538))
910

1011
### Dependency updates
1112
* Upgrade TF provider to 1.109.0 ([#4561](https://github.com/databricks/cli/pull/4561))
1213
* Upgrade Go SDK to v0.110.0 ([#4552](https://github.com/databricks/cli/pull/4552))
1314

1415
### API Changes
15-
16-
- Bump databricks-sdk-go from v0.111.0 to v0.112.0.
16+
* Bump databricks-sdk-go from v0.111.0 to v0.112.0.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Simple test app")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
command: ["python", "app.py"]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
bundle:
2+
name: app-git-source-$UNIQUE_NAME
3+
4+
workspace:
5+
root_path: "~/.bundle/app-git-source-$UNIQUE_NAME"
6+
7+
resources:
8+
apps:
9+
my_app:
10+
name: app-$UNIQUE_NAME
11+
description: "App with git source"
12+
git_repository:
13+
url: https://github.com/databricks/cli
14+
provider: gitHub
15+
git_source:
16+
branch: main
17+
source_code_path: internal/testdata/simple-app
18+
source_code_path: ./app

acceptance/bundle/apps/git_source/out.test.toml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
2+
=== Validate bundle configuration
3+
>>> [CLI] bundle validate
4+
Name: app-git-source-[UNIQUE_NAME]
5+
Target: default
6+
Workspace:
7+
User: [USERNAME]
8+
Path: /Workspace/Users/[USERNAME]/.bundle/app-git-source-[UNIQUE_NAME]
9+
10+
Validation OK!
11+
12+
=== Plan bundle deployment
13+
>>> [CLI] bundle plan
14+
create apps.my_app
15+
16+
Plan: 1 to add, 0 to change, 0 to delete, 0 unchanged
17+
18+
=== Deploy bundle
19+
>>> [CLI] bundle deploy
20+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/app-git-source-[UNIQUE_NAME]/files...
21+
Deploying resources...
22+
Updating deployment state...
23+
Deployment complete!
24+
25+
=== Get app details and verify git_source configuration
26+
>>> [CLI] bundle summary --output json
27+
28+
>>> [CLI] apps get [APP_NAME] --output json
29+
{
30+
"name": "[APP_NAME]",
31+
"description": "App with git source",
32+
"git_repository": {
33+
"provider": "gitHub",
34+
"url": "https://github.com/databricks/cli"
35+
},
36+
"git_source": null
37+
}
38+
39+
=== Verify no drift after deployment
40+
>>> [CLI] bundle plan
41+
Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged
42+
43+
=== Run the app to verify it works
44+
>>> cat out.app-run
45+
✓ Getting the status of the app [APP_NAME]
46+
✓ App is in RUNNING state
47+
✓ App compute is in ACTIVE state
48+
✓ Deployment succeeded
49+
You can access the app at [APP_NAME]-123.cloud.databricksapps.com
50+
51+
=== Update git_source branch and redeploy
52+
>>> [CLI] bundle deploy
53+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/app-git-source-[UNIQUE_NAME]/files...
54+
Deploying resources...
55+
Updating deployment state...
56+
Deployment complete!
57+
58+
=== Verify config update was applied
59+
>>> [CLI] apps get [APP_NAME] --output json
60+
{
61+
"name": "[APP_NAME]",
62+
"git_source": null
63+
}
64+
65+
>>> [CLI] bundle destroy --auto-approve
66+
The following resources will be deleted:
67+
delete resources.apps.my_app
68+
69+
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/app-git-source-[UNIQUE_NAME]
70+
71+
Deleting files...
72+
Destroy complete!
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
# Generate databricks.yml from template
4+
envsubst < databricks.yml.tmpl > databricks.yml
5+
6+
# Set up cleanup trap to ensure resources are destroyed even on failure
7+
cleanup() {
8+
trace $CLI bundle destroy --auto-approve
9+
}
10+
trap cleanup EXIT
11+
12+
title "Validate bundle configuration"
13+
trace $CLI bundle validate
14+
15+
title "Plan bundle deployment"
16+
trace $CLI bundle plan
17+
18+
title "Deploy bundle"
19+
trace $CLI bundle deploy
20+
21+
title "Get app details and verify git_source configuration"
22+
app_name=$(trace $CLI bundle summary --output json | jq -r '.resources.apps.my_app.name')
23+
echo "$app_name:APP_NAME" >> ACC_REPLS
24+
25+
trace $CLI apps get $app_name --output json | jq '{name, description, git_repository, git_source}'
26+
27+
title "Verify no drift after deployment"
28+
trace $CLI bundle plan
29+
30+
title "Run the app to verify it works"
31+
$CLI bundle run my_app &> out.app-run || true
32+
trace cat out.app-run | head -20
33+
34+
title "Update git_source branch and redeploy"
35+
# Change branch from main to a different value (still main, but via sed to test config change)
36+
sed -i.bak 's/branch: main/branch: main # updated/' databricks.yml
37+
trace $CLI bundle deploy
38+
39+
title "Verify config update was applied"
40+
trace $CLI apps get $app_name --output json | jq '{name, git_source}'
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Test that git_repository and git_source fields are properly configured for apps
2+
Local = true
3+
# Temporary disable cloud tests because it fails with "Git repository cannot be defined in this workspace. Please try again later."
4+
Cloud = false
5+
RecordRequests = false
6+
RequiresWarehouse = true
7+
8+
Ignore = [".databricks", "databricks.yml", "databricks.yml.bak", "out.app-run"]
9+
10+
# Apps can take longer to deploy
11+
TimeoutCloud = "5m"
12+
13+
# Mock responses for app deployment
14+
[[Server]]
15+
Pattern = "POST /api/2.0/apps/{app_name}/deployments"
16+
Response.Body = '''
17+
{
18+
"deployment_id": "test-deployment-123",
19+
"status": {
20+
"state": "SUCCEEDED",
21+
"message": "Deployment succeeded"
22+
},
23+
"git_source": {
24+
"branch": "main",
25+
"source_code_path": "internal/testdata/simple-app",
26+
"resolved_commit": "abc123def456"
27+
},
28+
"source_code_path": "/Workspace/Users/tester@databricks.com/.bundle/files/app",
29+
"mode": "SNAPSHOT"
30+
}
31+
'''
32+
33+
[[Server]]
34+
Pattern = "GET /api/2.0/apps/{app_name}/deployments/{deployment_id}"
35+
Response.Body = '''
36+
{
37+
"deployment_id": "test-deployment-123",
38+
"status": {
39+
"state": "SUCCEEDED",
40+
"message": "Deployment succeeded"
41+
},
42+
"git_source": {
43+
"branch": "main",
44+
"source_code_path": "internal/testdata/simple-app",
45+
"resolved_commit": "abc123def456"
46+
},
47+
"source_code_path": "/Workspace/Users/tester@databricks.com/.bundle/files/app",
48+
"mode": "SNAPSHOT"
49+
}
50+
'''

acceptance/bundle/refschema/out.fields.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ resources.apps.*.effective_user_api_scopes[*] string ALL
119119
resources.apps.*.git_repository *apps.GitRepository ALL
120120
resources.apps.*.git_repository.provider string ALL
121121
resources.apps.*.git_repository.url string ALL
122+
resources.apps.*.git_source *apps.GitSource INPUT
123+
resources.apps.*.git_source.branch string INPUT
124+
resources.apps.*.git_source.commit string INPUT
125+
resources.apps.*.git_source.git_repository *apps.GitRepository INPUT
126+
resources.apps.*.git_source.git_repository.provider string INPUT
127+
resources.apps.*.git_source.git_repository.url string INPUT
128+
resources.apps.*.git_source.resolved_commit string INPUT
129+
resources.apps.*.git_source.source_code_path string INPUT
130+
resources.apps.*.git_source.tag string INPUT
122131
resources.apps.*.id string ALL
123132
resources.apps.*.lifecycle resources.Lifecycle INPUT
124133
resources.apps.*.lifecycle.prevent_destroy bool INPUT

bundle/config/resources/apps.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type AppEnvVar struct {
3535
type App struct {
3636
BaseResource
3737
apps.App // nolint App struct also defines Id and URL field with the same json tag "id" and "url"
38+
// Note: apps.App already includes GitRepository field from the SDK
3839

3940
// SourceCodePath is a required field used by DABs to point to Databricks app source code
4041
// on local disk and to the corresponding workspace path during app deployment.
@@ -45,6 +46,10 @@ type App struct {
4546
// This allows users to define app configuration directly in the bundle YAML instead of maintaining a separate app.yaml file.
4647
Config *AppConfig `json:"config,omitempty"`
4748

49+
// GitSource specifies the git reference (branch, tag, or commit) to use during deployment.
50+
// This is used in conjunction with GitRepository (from apps.App) and is passed to the Deploy API.
51+
GitSource *apps.GitSource `json:"git_source,omitempty"`
52+
4853
Permissions []AppPermission `json:"permissions,omitempty"`
4954
}
5055

0 commit comments

Comments
 (0)