mirror of https://github.com/databricks/cli.git
Added a warning when `config` section is used in apps (#2416)
## 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
This commit is contained in:
parent
8b7e0ba683
commit
010f88f84e
|
@ -0,0 +1,3 @@
|
||||||
|
command:
|
||||||
|
- python
|
||||||
|
- app.py
|
|
@ -0,0 +1,8 @@
|
||||||
|
bundle:
|
||||||
|
name: apps_yaml
|
||||||
|
|
||||||
|
resources:
|
||||||
|
apps:
|
||||||
|
myapp:
|
||||||
|
name: myapp
|
||||||
|
source_code_path: ./app
|
|
@ -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"
|
||||||
|
}
|
|
@ -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!
|
|
@ -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
|
|
@ -0,0 +1 @@
|
||||||
|
print("Hello world!")
|
|
@ -0,0 +1,12 @@
|
||||||
|
bundle:
|
||||||
|
name: apps_config_section
|
||||||
|
|
||||||
|
resources:
|
||||||
|
apps:
|
||||||
|
myapp:
|
||||||
|
name: myapp
|
||||||
|
source_code_path: ./app
|
||||||
|
config:
|
||||||
|
command:
|
||||||
|
- python
|
||||||
|
- app.py
|
|
@ -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"
|
||||||
|
}
|
|
@ -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
|
||||||
|
|
|
@ -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
|
|
@ -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."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'''
|
|
@ -3,8 +3,6 @@ package apps
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/databricks/cli/bundle"
|
"github.com/databricks/cli/bundle"
|
||||||
"github.com/databricks/cli/libs/diag"
|
"github.com/databricks/cli/libs/diag"
|
||||||
|
@ -14,7 +12,6 @@ type validate struct{}
|
||||||
|
|
||||||
func (v *validate) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
func (v *validate) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
||||||
var diags diag.Diagnostics
|
var diags diag.Diagnostics
|
||||||
possibleConfigFiles := []string{"app.yml", "app.yaml"}
|
|
||||||
usedSourceCodePaths := make(map[string]string)
|
usedSourceCodePaths := make(map[string]string)
|
||||||
|
|
||||||
for key, app := range b.Config.Resources.Apps {
|
for key, app := range b.Config.Resources.Apps {
|
||||||
|
@ -28,16 +25,12 @@ func (v *validate) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics
|
||||||
}
|
}
|
||||||
usedSourceCodePaths[app.SourceCodePath] = key
|
usedSourceCodePaths[app.SourceCodePath] = key
|
||||||
|
|
||||||
for _, configFile := range possibleConfigFiles {
|
if app.Config != nil {
|
||||||
appPath := strings.TrimPrefix(app.SourceCodePath, b.Config.Workspace.FilePath)
|
diags = append(diags, diag.Diagnostic{
|
||||||
cf := path.Join(appPath, configFile)
|
Severity: diag.Warning,
|
||||||
if _, err := b.SyncRoot.Stat(cf); err == nil {
|
Summary: "App config section detected",
|
||||||
diags = append(diags, diag.Diagnostic{
|
Detail: fmt.Sprintf("remove 'config' from app resource '%s' section and use app.yml file in the root of this app instead", key),
|
||||||
Severity: diag.Error,
|
})
|
||||||
Summary: configFile + " detected",
|
|
||||||
Detail: fmt.Sprintf("remove %s and use 'config' property for app resource '%s' instead", cf, app.Name),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,46 +17,6 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"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) {
|
func TestAppsValidateSameSourcePath(t *testing.T) {
|
||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
testutil.Touch(t, tmpDir, "app1", "app.py")
|
testutil.Touch(t, tmpDir, "app1", "app.py")
|
||||||
|
|
|
@ -2,3 +2,7 @@ Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/$UNIQUE_PRJ/files.
|
||||||
Deploying resources...
|
Deploying resources...
|
||||||
Updating deployment state...
|
Updating deployment state...
|
||||||
Deployment complete!
|
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
|
||||||
|
|
||||||
|
|
|
@ -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
|
Name: basic
|
||||||
Target: default
|
Target: default
|
||||||
Workspace:
|
Workspace:
|
||||||
User: [USERNAME]
|
User: [USERNAME]
|
||||||
Path: /Workspace/Users/[USERNAME]/.bundle/$UNIQUE_PRJ
|
Path: /Workspace/Users/[USERNAME]/.bundle/$UNIQUE_PRJ
|
||||||
|
|
||||||
Validation OK!
|
Found 1 warning
|
||||||
|
|
Loading…
Reference in New Issue