Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions acceptance/bundle/apps/git_source/app/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Simple test app")
1 change: 1 addition & 0 deletions acceptance/bundle/apps/git_source/app/app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
command: ["python", "app.py"]
18 changes: 18 additions & 0 deletions acceptance/bundle/apps/git_source/databricks.yml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
bundle:
name: app-git-source-$UNIQUE_NAME

workspace:
root_path: "~/.bundle/app-git-source-$UNIQUE_NAME"

resources:
apps:
my_app:
name: app-$UNIQUE_NAME
description: "App with git source"
git_repository:
url: https://github.com/databricks/cli
provider: gitHub
git_source:
branch: main
source_code_path: internal/testdata/simple-app
source_code_path: ./app
6 changes: 6 additions & 0 deletions acceptance/bundle/apps/git_source/out.test.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

106 changes: 106 additions & 0 deletions acceptance/bundle/apps/git_source/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@

=== Validate bundle configuration
>>> [CLI] bundle validate
Name: app-git-source-[UNIQUE_NAME]
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/app-git-source-[UNIQUE_NAME]

Validation OK!

=== Plan bundle deployment
>>> [CLI] bundle plan
create apps.my_app

Plan: 1 to add, 0 to change, 0 to delete, 0 unchanged

=== Deploy bundle
>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/app-git-source-[UNIQUE_NAME]/files...
Deploying resources...
Updating deployment state...
Deployment complete!

=== Get app details and verify git_source configuration
>>> [CLI] bundle summary --output json

>>> [CLI] apps get [APP_NAME] --output json
{
"name": "[APP_NAME]",
"description": "App with git source",
"git_repository": {
"provider": "gitHub",
"url": "https://github.com/databricks/cli"
},
"git_source": null
}

=== Verify no drift after deployment
>>> [CLI] bundle plan
Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged

=== Run the app to verify it works
>>> cat out.app-run
✓ Getting the status of the app [APP_NAME]
✓ App is in RUNNING state
✓ App compute is in ACTIVE state
✓ Deployment succeeded
You can access the app at [APP_NAME]-123.cloud.databricksapps.com

=== Update git_source branch and redeploy
>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/app-git-source-[UNIQUE_NAME]/files...
Deploying resources...
Updating deployment state...
Deployment complete!

=== Verify config update was applied
>>> [CLI] apps get [APP_NAME] --output json
{
"name": "[APP_NAME]",
"git_source": null
}

=== Destroy bundle (via trap)
=== Verify app is deleted
>>> [CLI] apps get [APP_NAME]
{
"app_status": {
"message":"Application is running.",
"state":"RUNNING"
},
"compute_status": {
"message":"App compute is active.",
"state":"ACTIVE"
},
"description":"App with git source",
"git_repository": {
"provider":"gitHub",
"url":"https://github.com/databricks/cli"
},
"id":"1000",
"name":"[APP_NAME]",
"url":"[APP_NAME]-123.cloud.databricksapps.com"
}

>>> [CLI] bundle summary
Name: app-git-source-[UNIQUE_NAME]
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/app-git-source-[UNIQUE_NAME]
Resources:
Apps:
my_app:
Name: [APP_NAME]
URL: (not deployed)

>>> [CLI] bundle destroy --auto-approve
The following resources will be deleted:
delete resources.apps.my_app

All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/app-git-source-[UNIQUE_NAME]

Deleting files...
Destroy complete!
48 changes: 48 additions & 0 deletions acceptance/bundle/apps/git_source/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# Generate databricks.yml from template
envsubst < databricks.yml.tmpl > databricks.yml

# Set up cleanup trap to ensure resources are destroyed even on failure
cleanup() {
trace $CLI bundle destroy --auto-approve
}
trap cleanup EXIT

title "Validate bundle configuration"
trace $CLI bundle validate

title "Plan bundle deployment"
trace $CLI bundle plan

title "Deploy bundle"
trace $CLI bundle deploy

title "Get app details and verify git_source configuration"
app_name=$(trace $CLI bundle summary --output json | jq -r '.resources.apps.my_app.name')
echo "$app_name:APP_NAME" >> ACC_REPLS

trace $CLI apps get $app_name --output json | jq '{name, description, git_repository, git_source}'

title "Verify no drift after deployment"
trace $CLI bundle plan

title "Run the app to verify it works"
$CLI bundle run my_app &> out.app-run || true
trace cat out.app-run | head -20

title "Update git_source branch and redeploy"
# Change branch from main to a different value (still main, but via sed to test config change)
sed -i.bak 's/branch: main/branch: main # updated/' databricks.yml
trace $CLI bundle deploy

title "Verify config update was applied"
trace $CLI apps get $app_name --output json | jq '{name, git_source}'

title "Destroy bundle (via trap)"
# Destroy will be called by trap on EXIT

title "Verify app is deleted"
errcode trace $CLI apps get $app_name

trace $CLI bundle summary
50 changes: 50 additions & 0 deletions acceptance/bundle/apps/git_source/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Test that git_repository and git_source fields are properly configured for apps
Local = true
# Temporary disable cloud tests because it fails with "Git repository cannot be defined in this workspace. Please try again later."
Cloud = false
RecordRequests = false
RequiresWarehouse = true

Ignore = [".databricks", "databricks.yml", "databricks.yml.bak", "out.app-run"]

# Apps can take longer to deploy
TimeoutCloud = "5m"

# Mock responses for app deployment
[[Server]]
Pattern = "POST /api/2.0/apps/{app_name}/deployments"
Response.Body = '''
{
"deployment_id": "test-deployment-123",
"status": {
"state": "SUCCEEDED",
"message": "Deployment succeeded"
},
"git_source": {
"branch": "main",
"source_code_path": "internal/testdata/simple-app",
"resolved_commit": "abc123def456"
},
"source_code_path": "/Workspace/Users/tester@databricks.com/.bundle/files/app",
"mode": "SNAPSHOT"
}
'''

[[Server]]
Pattern = "GET /api/2.0/apps/{app_name}/deployments/{deployment_id}"
Response.Body = '''
{
"deployment_id": "test-deployment-123",
"status": {
"state": "SUCCEEDED",
"message": "Deployment succeeded"
},
"git_source": {
"branch": "main",
"source_code_path": "internal/testdata/simple-app",
"resolved_commit": "abc123def456"
},
"source_code_path": "/Workspace/Users/tester@databricks.com/.bundle/files/app",
"mode": "SNAPSHOT"
}
'''
5 changes: 5 additions & 0 deletions bundle/config/resources/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type AppEnvVar struct {
type App struct {
BaseResource
apps.App // nolint App struct also defines Id and URL field with the same json tag "id" and "url"
// Note: apps.App already includes GitRepository field from the SDK

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

// GitSource specifies the git reference (branch, tag, or commit) to use during deployment.
// This is used in conjunction with GitRepository (from apps.App) and is passed to the Deploy API.
GitSource *apps.GitSource `json:"git_source,omitempty"`

Permissions []AppPermission `json:"permissions,omitempty"`
}

Expand Down
6 changes: 6 additions & 0 deletions bundle/internal/schema/annotations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,12 @@ github.com/databricks/cli/bundle/config/resources.AlertPermission:
"user_name":
"description": |-
PLACEHOLDER
github.com/databricks/cli/bundle/config/resources.App:
"git_source":
"description": |-
Git source configuration for app deployments. Specifies which git reference (branch, tag, or commit)
to use when deploying the app. Used in conjunction with git_repository to deploy code directly from git.
The source_code_path within git_source specifies the relative path to the app code within the repository.
github.com/databricks/cli/bundle/config/resources.AppConfig:
"command":
"description": |-
Expand Down
1 change: 1 addition & 0 deletions bundle/internal/validation/generated/required_fields.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions bundle/run/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ func (a *appRunner) buildAppDeployment() apps.AppDeployment {
SourceCodePath: a.app.SourceCodePath,
}

// Add git source if provided
if a.app.GitSource != nil {
deployment.GitSource = a.app.GitSource
}

// Add inline config if provided
if a.app.Config != nil {
if len(a.app.Config.Command) > 0 {
Expand Down
4 changes: 4 additions & 0 deletions bundle/schema/jsonschema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading