Skip to content

Commit 2973b59

Browse files
authored
Extract deployPrepare() (#3328)
## Changes No-op refactor to extract a set of mutators that are needed for "bundle plan". ## Why Going to use deployPrepare() in "bundle plan": #3329 It needs the same bundle config as bundle deploy in order to properly calculate plan.
1 parent 5c7d8ad commit 2973b59

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

bundle/phases/deploy.go

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,39 @@ func deployCore(ctx context.Context, b *bundle.Bundle) {
155155
}
156156
}
157157

158+
// deployPrepare is common set of mutators between "bundle plan" and "bundle deploy".
159+
// Ideally it should not modify the remote, only in-memory bundle config.
160+
// TODO: currently it does affect remote, via artifacts.CleanUp() and libraries.Upload().
161+
// We should refactor deployment so that it consists of two stages:
162+
// 1. Preparation: only local config is changed. This will be used by both "bundle deploy" and "bundle plan"
163+
// 2. Deployment: this does all the uploads. Only used by "deploy", not "plan".
164+
func deployPrepare(ctx context.Context, b *bundle.Bundle) {
165+
bundle.ApplySeqContext(ctx, b,
166+
statemgmt.StatePull(),
167+
terraform.CheckDashboardsModifiedRemotely(),
168+
deploy.StatePull(),
169+
mutator.ValidateGitDetails(),
170+
terraform.CheckRunningResource(),
171+
172+
// artifacts.CleanUp() is there because I'm not sure if it's safe to move to later stage.
173+
artifacts.CleanUp(),
174+
175+
// libraries.CheckForSameNameLibraries() needs to be run after we expand glob references so we
176+
// know what are the actual library paths.
177+
// libraries.ExpandGlobReferences() has to be run after the libraries are built and thus this
178+
// mutator is part of the deploy step rather than validate.
179+
libraries.ExpandGlobReferences(),
180+
libraries.CheckForSameNameLibraries(),
181+
// SwitchToPatchedWheels must be run after ExpandGlobReferences and after build phase because it Artifact.Source and Artifact.Patched populated
182+
libraries.SwitchToPatchedWheels(),
183+
184+
// libraries.Upload() not just uploads but also replaces local paths with remote paths.
185+
// TransformWheelTask depends on it and planning also depends on it.
186+
libraries.Upload(),
187+
trampoline.TransformWheelTask(),
188+
)
189+
}
190+
158191
// The deploy phase deploys artifacts and resources.
159192
func Deploy(ctx context.Context, b *bundle.Bundle, outputHandler sync.OutputHandler) {
160193
log.Info(ctx, "Phase: deploy")
@@ -176,23 +209,12 @@ func Deploy(ctx context.Context, b *bundle.Bundle, outputHandler sync.OutputHand
176209
bundle.ApplyContext(ctx, b, lock.Release(lock.GoalDeploy))
177210
}()
178211

212+
deployPrepare(ctx, b)
213+
if logdiag.HasError(ctx) {
214+
return
215+
}
216+
179217
bundle.ApplySeqContext(ctx, b,
180-
statemgmt.StatePull(),
181-
terraform.CheckDashboardsModifiedRemotely(),
182-
deploy.StatePull(),
183-
mutator.ValidateGitDetails(),
184-
terraform.CheckRunningResource(),
185-
artifacts.CleanUp(),
186-
// libraries.CheckForSameNameLibraries() needs to be run after we expand glob references so we
187-
// know what are the actual library paths.
188-
// libraries.ExpandGlobReferences() has to be run after the libraries are built and thus this
189-
// mutator is part of the deploy step rather than validate.
190-
libraries.ExpandGlobReferences(),
191-
libraries.CheckForSameNameLibraries(),
192-
// SwitchToPatchedWheels must be run after ExpandGlobReferences and after build phase because it Artifact.Source and Artifact.Patched populated
193-
libraries.SwitchToPatchedWheels(),
194-
libraries.Upload(),
195-
trampoline.TransformWheelTask(),
196218
files.Upload(outputHandler),
197219
deploy.StateUpdate(),
198220
deploy.StatePush(),

0 commit comments

Comments
 (0)