Skip to content

Commit c17de20

Browse files
authored
Do not use app config section in test templates and generated app configuration (#2599)
## Changes Do not use app config section in test templates and generated app configuration ## Why We're suggesting to use `app.yml` files in app root instead of `config` section for apps ## Tests Existing test pass ``` go test ./integration/bundle/ -update -run "TestDeployBundleWithApp" ok github.com/databricks/cli/integration/bundle 402.649s ```
1 parent 8afcf93 commit c17de20

11 files changed

Lines changed: 20 additions & 240 deletions

File tree

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
### CLI
1111

1212
### Bundles
13+
* Do not use app config section in test templates and generated app configuration ([#2599](https://github.com/databricks/cli/pull/2599))
1314
* Do not exit early when checking incompatible tasks for specified DBR ([#2692](https://github.com/databricks/cli/pull/2692))
1415
* Removed include/exclude flags support from bundle sync command ([#2718](https://github.com/databricks/cli/pull/2718))
1516
* Do not clean up Python artifacts dist and build folder in "bundle validate", do it in "bundle deploy". This reverts the behaviour introduced in 0.245.0 ([#2722](https://github.com/databricks/cli/pull/2722))

bundle/config/generate/app.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@ import (
66
"github.com/databricks/databricks-sdk-go/service/apps"
77
)
88

9-
func ConvertAppToValue(app *apps.App, sourceCodePath string, appConfig map[string]any) (dyn.Value, error) {
10-
ac, err := convert.FromTyped(appConfig, dyn.NilValue)
11-
if err != nil {
12-
return dyn.NilValue, err
13-
}
14-
9+
func ConvertAppToValue(app *apps.App, sourceCodePath string) (dyn.Value, error) {
1510
ar, err := convert.FromTyped(app.Resources, dyn.NilValue)
1611
if err != nil {
1712
return dyn.NilValue, err
@@ -25,10 +20,6 @@ func ConvertAppToValue(app *apps.App, sourceCodePath string, appConfig map[strin
2520
"source_code_path": dyn.NewValue(sourceCodePath, []dyn.Location{{Line: 3}}),
2621
}
2722

28-
if ac.Kind() != dyn.KindNil {
29-
dv["config"] = ac.WithLocations([]dyn.Location{{Line: 4}})
30-
}
31-
3223
if ar.Kind() != dyn.KindNil {
3324
dv["resources"] = ar.WithLocations([]dyn.Location{{Line: 5}})
3425
}

bundle/tests/apps/databricks.yml

Lines changed: 0 additions & 71 deletions
This file was deleted.

bundle/tests/apps_test.go

Lines changed: 0 additions & 58 deletions
This file was deleted.

cmd/bundle/generate/app.go

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
package generate
22

33
import (
4-
"context"
5-
"errors"
64
"fmt"
7-
"io"
8-
"io/fs"
95
"path/filepath"
106

117
"github.com/databricks/cli/bundle/config/generate"
128
"github.com/databricks/cli/cmd/root"
139
"github.com/databricks/cli/libs/cmdio"
1410
"github.com/databricks/cli/libs/dyn"
1511
"github.com/databricks/cli/libs/dyn/yamlsaver"
16-
"github.com/databricks/cli/libs/filer"
1712
"github.com/databricks/cli/libs/textutil"
18-
"github.com/databricks/databricks-sdk-go"
1913
"github.com/databricks/databricks-sdk-go/service/apps"
2014
"github.com/spf13/cobra"
21-
22-
"gopkg.in/yaml.v3"
2315
)
2416

2517
func NewGenerateAppCommand() *cobra.Command {
@@ -62,18 +54,13 @@ func NewGenerateAppCommand() *cobra.Command {
6254
return err
6355
}
6456

65-
appConfig, err := getAppConfig(ctx, app, w)
66-
if err != nil {
67-
return fmt.Errorf("failed to get app config: %w", err)
68-
}
69-
7057
// Making sure the source code path is relative to the config directory.
7158
rel, err := filepath.Rel(configDir, sourceDir)
7259
if err != nil {
7360
return err
7461
}
7562

76-
v, err := generate.ConvertAppToValue(app, filepath.ToSlash(rel), appConfig)
63+
v, err := generate.ConvertAppToValue(app, filepath.ToSlash(rel))
7764
if err != nil {
7865
return err
7966
}
@@ -91,12 +78,6 @@ func NewGenerateAppCommand() *cobra.Command {
9178
}),
9279
}
9380

94-
// If there are app.yaml or app.yml files in the source code path, they will be downloaded but we don't want to include them in the bundle.
95-
// We include this configuration inline, so we need to remove these files.
96-
for _, configFile := range []string{"app.yml", "app.yaml"} {
97-
delete(downloader.files, filepath.Join(sourceDir, configFile))
98-
}
99-
10081
err = downloader.FlushToDisk(ctx, force)
10182
if err != nil {
10283
return err
@@ -116,42 +97,3 @@ func NewGenerateAppCommand() *cobra.Command {
11697

11798
return cmd
11899
}
119-
120-
func getAppConfig(ctx context.Context, app *apps.App, w *databricks.WorkspaceClient) (map[string]any, error) {
121-
sourceCodePath := app.DefaultSourceCodePath
122-
123-
f, err := filer.NewWorkspaceFilesClient(w, sourceCodePath)
124-
if err != nil {
125-
return nil, err
126-
}
127-
128-
// The app config is stored in app.yml or app.yaml file in the source code path.
129-
configFileNames := []string{"app.yml", "app.yaml"}
130-
for _, configFile := range configFileNames {
131-
r, err := f.Read(ctx, configFile)
132-
if err != nil {
133-
if errors.Is(err, fs.ErrNotExist) {
134-
continue
135-
}
136-
return nil, err
137-
}
138-
defer r.Close()
139-
140-
cmdio.LogString(ctx, "Reading app configuration from "+configFile)
141-
content, err := io.ReadAll(r)
142-
if err != nil {
143-
return nil, err
144-
}
145-
146-
var appConfig map[string]any
147-
err = yaml.Unmarshal(content, &appConfig)
148-
if err != nil {
149-
cmdio.LogString(ctx, fmt.Sprintf("Failed to parse app configuration:\n%s\nerr: %v", string(content), err))
150-
return nil, nil
151-
}
152-
153-
return appConfig, nil
154-
}
155-
156-
return nil, nil
157-
}

integration/bundle/apps_test.go

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -87,36 +87,17 @@ func TestDeployBundleWithApp(t *testing.T) {
8787
data, err := io.ReadAll(reader)
8888
require.NoError(t, err)
8989

90-
job, err := wt.W.Jobs.GetBySettingsName(ctx, "test-job-with-cluster-"+uniqueId)
91-
require.NoError(t, err)
92-
9390
content := string(data)
94-
require.Contains(t, content, fmt.Sprintf(`command:
91+
// Replace windows line endings with unix line endings
92+
content = testutil.ReplaceWindowsLineEndings(content)
93+
require.Contains(t, content, `command:
9594
- flask
9695
- --app
9796
- app
9897
- run
9998
env:
10099
- name: JOB_ID
101-
value: "%d"`, job.JobId))
102-
103-
// Redeploy bundle with changed config env for app and confirm it's updated in app.yaml
104-
deployBundleWithArgs(t, ctx, root, `--var="env_var_name=ANOTHER_JOB_ID"`, "--force-lock", "--auto-approve")
105-
reader, err = wt.W.Workspace.Download(ctx, pathToAppYml)
106-
require.NoError(t, err)
107-
108-
data, err = io.ReadAll(reader)
109-
require.NoError(t, err)
110-
111-
content = string(data)
112-
require.Contains(t, content, fmt.Sprintf(`command:
113-
- flask
114-
- --app
115-
- app
116-
- run
117-
env:
118-
- name: ANOTHER_JOB_ID
119-
value: "%d"`, job.JobId))
100+
valueFrom: "app-job"`)
120101

121102
if testing.Short() {
122103
t.Log("Skip the app run in short mode")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
command:
2+
- flask
3+
- --app
4+
- app
5+
- run
6+
env:
7+
- name: JOB_ID
8+
valueFrom: "app-job"

integration/bundle/bundles/apps/template/databricks.yml.tmpl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@ resources:
1414
name: "{{.app_id}}"
1515
description: "App which manages job created by this bundle"
1616
source_code_path: ./app
17-
config:
18-
command:
19-
- flask
20-
- --app
21-
- app
22-
- run
23-
env:
24-
- name: ${var.env_var_name}
25-
value: ${resources.jobs.foo.id}
26-
2717
resources:
2818
- name: "app-job"
2919
description: "A job for app to be able to work with"

integration/bundle/testdata/apps/bundle_deploy.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,3 @@ Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/$UNIQUE_PRJ/files.
22
Deploying resources...
33
Updating deployment state...
44
Deployment complete!
5-
Warning: App config section detected
6-
7-
remove 'config' from app resource 'test_app' section and use app.yml file in the root of this app instead
8-
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
Warning: App config section detected
2-
3-
remove 'config' from app resource 'test_app' section and use app.yml file in the root of this app instead
4-
51
Name: basic
62
Target: default
73
Workspace:
84
User: [USERNAME]
95
Path: /Workspace/Users/[USERNAME]/.bundle/$UNIQUE_PRJ
106

11-
Found 1 warning
7+
Validation OK!

0 commit comments

Comments
 (0)