Skip to content

Commit b96f7be

Browse files
committed
wip
1 parent 507ebee commit b96f7be

File tree

8 files changed

+53
-69
lines changed

8 files changed

+53
-69
lines changed

acceptance/bundle/migrate/default-python/out.state_after_migration.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"job_cluster_key": "job_cluster",
5050
"libraries": [
5151
{
52-
"whl": ".databricks/bundle/dev/patched_wheels/python_artifact_my_default_python/my_default_python-0.0.1+[UNIX_TIME_NANOS][0]-py3-none-any.whl"
52+
"whl": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][0]-py3-none-any.whl"
5353
}
5454
],
5555
"notebook_task": {
@@ -66,7 +66,7 @@
6666
"job_cluster_key": "job_cluster",
6767
"libraries": [
6868
{
69-
"whl": ".databricks/bundle/dev/patched_wheels/python_artifact_my_default_python/my_default_python-0.0.1+[UNIX_TIME_NANOS][0]-py3-none-any.whl"
69+
"whl": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][0]-py3-none-any.whl"
7070
}
7171
],
7272
"python_wheel_task": {

acceptance/bundle/migrate/default-python/output.txt

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ To undo the migration, remove [TEST_TMP_DIR]/my_default_python/.databricks/bundl
3838
>>> jq .. | .libraries? | select(.) ../out.state_after_migration.json
3939
[
4040
{
41-
"whl": ".databricks/bundle/dev/patched_wheels/python_artifact_my_default_python/my_default_python-0.0.1+[UNIX_TIME_NANOS][1]-py3-none-any.whl"
41+
"whl": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][1]-py3-none-any.whl"
4242
}
4343
]
4444
[
4545
{
46-
"whl": ".databricks/bundle/dev/patched_wheels/python_artifact_my_default_python/my_default_python-0.0.1+[UNIX_TIME_NANOS][1]-py3-none-any.whl"
46+
"whl": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS][1]-py3-none-any.whl"
4747
}
4848
]
4949
[
@@ -74,22 +74,6 @@ Deployment complete!
7474
>>> print_state.py
7575

7676
>>> diff.py ../out.state_after_migration.json ../out.state_after_deploy.json
77-
--- ../out.state_after_migration.json
78-
+++ ../out.state_after_deploy.json
79-
@@ -50,5 +50,5 @@
80-
"libraries": [
81-
{
82-
- "whl": ".databricks/bundle/dev/patched_wheels/python_artifact_my_default_python/my_default_python-0.0.1+[UNIX_TIME_NANOS]-py3-none-any.whl"
83-
+ "whl": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS]-py3-none-any.whl"
84-
}
85-
],
86-
@@ -67,5 +67,5 @@
87-
"libraries": [
88-
{
89-
- "whl": ".databricks/bundle/dev/patched_wheels/python_artifact_my_default_python/my_default_python-0.0.1+[UNIX_TIME_NANOS]-py3-none-any.whl"
90-
+ "whl": "/Workspace/Users/[USERNAME]/.bundle/my_default_python/dev/artifacts/.internal/my_default_python-0.0.1+[UNIX_TIME_NANOS]-py3-none-any.whl"
91-
}
92-
],
9377

9478
=== Extra plan: should have no drift
9579
>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle plan

bundle/phases/build.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ import (
99
"github.com/databricks/cli/bundle/config/mutator"
1010
"github.com/databricks/cli/bundle/libraries"
1111
"github.com/databricks/cli/bundle/scripts"
12+
"github.com/databricks/cli/bundle/trampoline"
1213
"github.com/databricks/cli/libs/log"
14+
"github.com/databricks/cli/libs/logdiag"
1315
)
1416

17+
type LibLocationMap map[string][]libraries.LocationToUpdate
18+
1519
// The build phase builds artifacts.
16-
func Build(ctx context.Context, b *bundle.Bundle) {
20+
func Build(ctx context.Context, b *bundle.Bundle) LibLocationMap {
1721
log.Info(ctx, "Phase: build")
1822

1923
bundle.ApplySeqContext(ctx, b,
@@ -36,4 +40,17 @@ func Build(ctx context.Context, b *bundle.Bundle) {
3640
// SwitchToPatchedWheels must be run after ExpandGlobReferences and after build phase because it Artifact.Source and Artifact.Patched populated
3741
libraries.SwitchToPatchedWheels(),
3842
)
43+
44+
libs, diags := libraries.ReplaceWithRemotePath(ctx, b)
45+
for _, diag := range diags {
46+
logdiag.LogDiag(ctx, diag)
47+
}
48+
49+
bundle.ApplyContext(ctx, b,
50+
// TransformWheelTask must be run after ReplaceWithRemotePath so we can use correct remote path in the
51+
// transformed notebook
52+
trampoline.TransformWheelTask(),
53+
)
54+
55+
return libs
3956
}

bundle/phases/deploy.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func uploadLibraries(ctx context.Context, b *bundle.Bundle, libs map[string][]li
136136
}
137137

138138
// The deploy phase deploys artifacts and resources.
139-
func Deploy(ctx context.Context, b *bundle.Bundle, outputHandler sync.OutputHandler, engine engine.EngineType) {
139+
func Deploy(ctx context.Context, b *bundle.Bundle, outputHandler sync.OutputHandler, engine engine.EngineType, libs map[string][]libraries.LocationToUpdate) {
140140
log.Info(ctx, "Phase: deploy")
141141

142142
// Core mutators that CRUD resources and modify deployment state. These
@@ -156,11 +156,6 @@ func Deploy(ctx context.Context, b *bundle.Bundle, outputHandler sync.OutputHand
156156
bundle.ApplyContext(ctx, b, lock.Release(lock.GoalDeploy))
157157
}()
158158

159-
libs := DeployPrepare(ctx, b, false, engine)
160-
if logdiag.HasError(ctx) {
161-
return
162-
}
163-
164159
uploadLibraries(ctx, b, libs)
165160
if logdiag.HasError(ctx) {
166161
return

bundle/phases/plan.go

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,19 @@ import (
1111
"github.com/databricks/cli/bundle/deploy"
1212
"github.com/databricks/cli/bundle/deploy/terraform"
1313
"github.com/databricks/cli/bundle/deployplan"
14-
"github.com/databricks/cli/bundle/libraries"
1514
"github.com/databricks/cli/bundle/statemgmt"
16-
"github.com/databricks/cli/bundle/trampoline"
1715
"github.com/databricks/cli/libs/dyn"
18-
"github.com/databricks/cli/libs/logdiag"
1916
)
2017

21-
// DeployPrepare is common set of mutators between "bundle plan" and "bundle deploy".
22-
// This function does not make any mutations in the workspace remotely, only in-memory bundle config mutations
23-
func DeployPrepare(ctx context.Context, b *bundle.Bundle, isPlan bool, engine engine.EngineType) map[string][]libraries.LocationToUpdate {
18+
// PreDeployChecks is common set of mutators between "bundle plan" and "bundle deploy".
19+
// Note, it is not run in "bundle migrate" so it must not modify the config
20+
func PreDeployChecks(ctx context.Context, b *bundle.Bundle, isPlan bool, engine engine.EngineType) {
2421
bundle.ApplySeqContext(ctx, b,
2522
terraform.CheckDashboardsModifiedRemotely(isPlan, engine),
2623
deploy.StatePull(),
2724
mutator.ValidateGitDetails(),
2825
statemgmt.CheckRunningResource(engine),
2926
)
30-
31-
libs, diags := libraries.ReplaceWithRemotePath(ctx, b)
32-
for _, diag := range diags {
33-
logdiag.LogDiag(ctx, diag)
34-
}
35-
36-
bundle.ApplySeqContext(ctx, b,
37-
// TransformWheelTask must be run after ReplaceWithRemotePath so we can use correct remote path in the
38-
// transformed notebook
39-
trampoline.TransformWheelTask(),
40-
)
41-
42-
return libs
4327
}
4428

4529
// checkForPreventDestroy checks if the resource has lifecycle.prevent_destroy set, but the plan calls for this resource to be recreated or destroyed.

cmd/bundle/deploy.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ See https://docs.databricks.com/en/dev-tools/bundles/index.html for more informa
5959
b.Config.Bundle.Deployment.FailOnActiveRuns = failOnActiveRuns
6060
}
6161
},
62-
Verbose: verbose,
63-
AlwaysPull: true,
64-
FastValidate: true,
65-
Build: true,
66-
Deploy: true,
62+
Verbose: verbose,
63+
AlwaysPull: true,
64+
FastValidate: true,
65+
Build: true,
66+
PreDeployChecks: true,
67+
Deploy: true,
6768
})
6869

6970
return err

cmd/bundle/plan.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ It is useful for previewing changes before running 'bundle deploy'.`,
3535

3636
cmd.RunE = func(cmd *cobra.Command, args []string) error {
3737
opts := utils.ProcessOptions{
38-
AlwaysPull: true,
39-
FastValidate: true,
40-
Build: true,
41-
DeployPrepare: true,
38+
AlwaysPull: true,
39+
FastValidate: true,
40+
Build: true,
41+
PreDeployChecks: true,
4242
}
4343

4444
// Only add InitFunc if we need to set force or cluster ID

cmd/bundle/utils/process.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ type ProcessOptions struct {
5959
SkipEngineEnvVar bool
6060

6161
// If true, call corresponding phase:
62-
FastValidate bool
63-
Validate bool
64-
Build bool
65-
DeployPrepare bool
66-
Deploy bool
62+
FastValidate bool
63+
Validate bool
64+
Build bool
65+
PreDeployChecks bool
66+
Deploy bool
6767

6868
// Indicate whether the bundle operation originates from the pipelines CLI
6969
IsPipelinesCLI bool
@@ -152,7 +152,7 @@ func ProcessBundleRet(cmd *cobra.Command, opts ProcessOptions) (*bundle.Bundle,
152152

153153
var stateDesc *statemgmt.StateDesc
154154

155-
shouldReadState := opts.ReadState || opts.AlwaysPull || opts.InitIDs || opts.ErrorOnEmptyState || opts.DeployPrepare || opts.Deploy
155+
shouldReadState := opts.ReadState || opts.AlwaysPull || opts.InitIDs || opts.ErrorOnEmptyState || opts.PreDeployChecks || opts.Deploy
156156

157157
if shouldReadState {
158158
// PullResourcesState depends on stateFiler which needs b.Config.Workspace.StatePath which is set in phases.Initialize
@@ -206,9 +206,11 @@ func ProcessBundleRet(cmd *cobra.Command, opts ProcessOptions) (*bundle.Bundle,
206206
}
207207
}
208208

209-
if opts.Build {
209+
var libs phases.LibLocationMap
210+
211+
if opts.Build || opts.Deploy {
210212
t2 := time.Now()
211-
phases.Build(ctx, b)
213+
libs = phases.Build(ctx, b)
212214
b.Metrics.ExecutionTimes = append(b.Metrics.ExecutionTimes, protos.IntMapEntry{
213215
Key: "phases.Build",
214216
Value: time.Since(t2).Milliseconds(),
@@ -219,12 +221,13 @@ func ProcessBundleRet(cmd *cobra.Command, opts ProcessOptions) (*bundle.Bundle,
219221
}
220222
}
221223

222-
if opts.DeployPrepare {
223-
if opts.Deploy {
224-
panic("Deploy already calls DeployPrepare internally")
225-
}
224+
if opts.PreDeployChecks {
226225
downgradeWarningToError := !opts.Deploy
227-
_ = phases.DeployPrepare(ctx, b, downgradeWarningToError, stateDesc.Engine)
226+
phases.PreDeployChecks(ctx, b, downgradeWarningToError, stateDesc.Engine)
227+
228+
if logdiag.HasError(ctx) {
229+
return b, stateDesc, root.ErrAlreadyPrinted
230+
}
228231
}
229232

230233
if opts.Deploy {
@@ -236,7 +239,7 @@ func ProcessBundleRet(cmd *cobra.Command, opts ProcessOptions) (*bundle.Bundle,
236239
}
237240

238241
t3 := time.Now()
239-
phases.Deploy(ctx, b, outputHandler, stateDesc.Engine)
242+
phases.Deploy(ctx, b, outputHandler, stateDesc.Engine, libs)
240243
b.Metrics.ExecutionTimes = append(b.Metrics.ExecutionTimes, protos.IntMapEntry{
241244
Key: "phases.Deploy",
242245
Value: time.Since(t3).Milliseconds(),

0 commit comments

Comments
 (0)