Skip to content

Commit

Permalink
Added a warning when config section is used in apps (#2416)
Browse files Browse the repository at this point in the history
## Changes
Added a warning when `config` section is used in apps

## Why
To avoid the confusion between using apps in DABs and outside of DABs,
we want to provide only one way of configuring apps runtime
configuration - by using `app.yml` file in the root of the app.

## Tests
Added acceptance tests
  • Loading branch information
andrewnester authored Mar 3, 2025
1 parent 8b7e0ba commit 010f88f
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 54 deletions.
Empty file.
3 changes: 3 additions & 0 deletions acceptance/bundle/apps/app_yaml/app/app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
command:
- python
- app.py
8 changes: 8 additions & 0 deletions acceptance/bundle/apps/app_yaml/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
bundle:
name: apps_yaml

resources:
apps:
myapp:
name: myapp
source_code_path: ./app
5 changes: 5 additions & 0 deletions acceptance/bundle/apps/app_yaml/out.app.yml.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"method": "POST",
"path": "/api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/apps_yaml/default/files/app/app.yml",
"raw_body": "command:\n - python\n - app.py\n"
}
15 changes: 15 additions & 0 deletions acceptance/bundle/apps/app_yaml/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

>>> [CLI] bundle validate
Name: apps_yaml
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/apps_yaml/default

Validation OK!

>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/apps_yaml/default/files...
Deploying resources...
Updating deployment state...
Deployment complete!
4 changes: 4 additions & 0 deletions acceptance/bundle/apps/app_yaml/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
trace $CLI bundle validate
trace $CLI bundle deploy
jq 'select(.path == "/api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/apps_yaml/default/files/app/app.yml")' out.requests.txt | sed 's/\\r//g' > out.app.yml.txt
rm out.requests.txt
1 change: 1 addition & 0 deletions acceptance/bundle/apps/config_section/app/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hello world!")
12 changes: 12 additions & 0 deletions acceptance/bundle/apps/config_section/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
bundle:
name: apps_config_section

resources:
apps:
myapp:
name: myapp
source_code_path: ./app
config:
command:
- python
- app.py
5 changes: 5 additions & 0 deletions acceptance/bundle/apps/config_section/out.app.yml.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"method": "POST",
"path": "/api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/apps_config_section/default/files/app/app.yml",
"raw_body": "command:\n - python\n - app.py\n"
}
23 changes: 23 additions & 0 deletions acceptance/bundle/apps/config_section/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

>>> [CLI] bundle validate
Warning: App config section detected

remove 'config' from app resource 'myapp' section and use app.yml file in the root of this app instead

Name: apps_config_section
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/apps_config_section/default

Found 1 warning

>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/apps_config_section/default/files...
Deploying resources...
Updating deployment state...
Deployment complete!
Warning: App config section detected

remove 'config' from app resource 'myapp' section and use app.yml file in the root of this app instead

4 changes: 4 additions & 0 deletions acceptance/bundle/apps/config_section/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
trace $CLI bundle validate
trace $CLI bundle deploy
jq 'select(.path == "/api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/apps_config_section/default/files/app/app.yml")' out.requests.txt > out.app.yml.txt
rm out.requests.txt
26 changes: 26 additions & 0 deletions acceptance/bundle/apps/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Cloud = false
RecordRequests = true

Ignore = [
'.databricks',
]

[[Server]]
Pattern = "POST /api/2.0/apps"

[[Server]]
Pattern = "GET /api/2.0/apps/myapp"
Response.Body = '''
{
"name": "myapp",
"description": "",
"compute_status": {
"state": "ACTIVE",
"message": "App compute is active."
},
"app_status": {
"state": "RUNNING",
"message": "Application is running."
}
}
'''
19 changes: 6 additions & 13 deletions bundle/apps/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package apps
import (
"context"
"fmt"
"path"
"strings"

"github.com/databricks/cli/bundle"
"github.com/databricks/cli/libs/diag"
Expand All @@ -14,7 +12,6 @@ type validate struct{}

func (v *validate) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
var diags diag.Diagnostics
possibleConfigFiles := []string{"app.yml", "app.yaml"}
usedSourceCodePaths := make(map[string]string)

for key, app := range b.Config.Resources.Apps {
Expand All @@ -28,16 +25,12 @@ func (v *validate) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics
}
usedSourceCodePaths[app.SourceCodePath] = key

for _, configFile := range possibleConfigFiles {
appPath := strings.TrimPrefix(app.SourceCodePath, b.Config.Workspace.FilePath)
cf := path.Join(appPath, configFile)
if _, err := b.SyncRoot.Stat(cf); err == nil {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: configFile + " detected",
Detail: fmt.Sprintf("remove %s and use 'config' property for app resource '%s' instead", cf, app.Name),
})
}
if app.Config != nil {
diags = append(diags, diag.Diagnostic{
Severity: diag.Warning,
Summary: "App config section detected",
Detail: fmt.Sprintf("remove 'config' from app resource '%s' section and use app.yml file in the root of this app instead", key),
})
}
}

Expand Down
40 changes: 0 additions & 40 deletions bundle/apps/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,6 @@ import (
"github.com/stretchr/testify/require"
)

func TestAppsValidate(t *testing.T) {
tmpDir := t.TempDir()
testutil.Touch(t, tmpDir, "app1", "app.yml")
testutil.Touch(t, tmpDir, "app2", "app.py")

b := &bundle.Bundle{
BundleRootPath: tmpDir,
SyncRootPath: tmpDir,
SyncRoot: vfs.MustNew(tmpDir),
Config: config.Root{
Workspace: config.Workspace{
FilePath: "/foo/bar/",
},
Resources: config.Resources{
Apps: map[string]*resources.App{
"app1": {
App: &apps.App{
Name: "app1",
},
SourceCodePath: "./app1",
},
"app2": {
App: &apps.App{
Name: "app2",
},
SourceCodePath: "./app2",
},
},
},
},
}

bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(tmpDir, "databricks.yml")}})

diags := bundle.ApplySeq(context.Background(), b, mutator.TranslatePaths(), Validate())
require.Len(t, diags, 1)
require.Equal(t, "app.yml detected", diags[0].Summary)
require.Contains(t, diags[0].Detail, "app.yml and use 'config' property for app resource")
}

func TestAppsValidateSameSourcePath(t *testing.T) {
tmpDir := t.TempDir()
testutil.Touch(t, tmpDir, "app1", "app.py")
Expand Down
4 changes: 4 additions & 0 deletions integration/bundle/testdata/apps/bundle_deploy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/$UNIQUE_PRJ/files.
Deploying resources...
Updating deployment state...
Deployment complete!
Warning: App config section detected

remove 'config' from app resource 'test_app' section and use app.yml file in the root of this app instead

6 changes: 5 additions & 1 deletion integration/bundle/testdata/apps/bundle_validate.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
Warning: App config section detected

remove 'config' from app resource 'test_app' section and use app.yml file in the root of this app instead

Name: basic
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/$UNIQUE_PRJ

Validation OK!
Found 1 warning

0 comments on commit 010f88f

Please sign in to comment.