forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.go
85 lines (68 loc) · 1.92 KB
/
deploy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package cmd
import (
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshdir "github.com/cloudfoundry/bosh-cli/director"
boshtpl "github.com/cloudfoundry/bosh-cli/director/template"
boshui "github.com/cloudfoundry/bosh-cli/ui"
)
type DeployCmd struct {
ui boshui.UI
deployment boshdir.Deployment
releaseUploader ReleaseUploader
}
type ReleaseUploader interface {
UploadReleases([]byte) ([]byte, error)
}
func NewDeployCmd(
ui boshui.UI,
deployment boshdir.Deployment,
releaseUploader ReleaseUploader,
) DeployCmd {
return DeployCmd{ui, deployment, releaseUploader}
}
func (c DeployCmd) Run(opts DeployOpts) error {
tpl := boshtpl.NewTemplate(opts.Args.Manifest.Bytes)
bytes, err := tpl.Evaluate(opts.VarFlags.AsVariables(), opts.OpsFlags.AsOp(), boshtpl.EvaluateOpts{})
if err != nil {
return bosherr.WrapErrorf(err, "Evaluating manifest")
}
err = c.checkDeploymentName(bytes)
if err != nil {
return err
}
bytes, err = c.releaseUploader.UploadReleases(bytes)
if err != nil {
return err
}
deploymentDiff, err := c.deployment.Diff(bytes, opts.NoRedact)
if err != nil {
return err
}
diff := NewDiff(deploymentDiff.Diff)
diff.Print(c.ui)
err = c.ui.AskForConfirmation()
if err != nil {
return err
}
updateOpts := boshdir.UpdateOpts{
Recreate: opts.Recreate,
Fix: opts.Fix,
SkipDrain: opts.SkipDrain,
DryRun: opts.DryRun,
Canaries: opts.Canaries,
MaxInFlight: opts.MaxInFlight,
Diff: deploymentDiff,
}
return c.deployment.Update(bytes, updateOpts)
}
func (c DeployCmd) checkDeploymentName(bytes []byte) error {
manifest, err := boshdir.NewManifestFromBytes(bytes)
if err != nil {
return bosherr.WrapErrorf(err, "Parsing manifest")
}
if manifest.Name != c.deployment.Name() {
errMsg := "Expected manifest to specify deployment name '%s' but was '%s'"
return bosherr.Errorf(errMsg, c.deployment.Name(), manifest.Name)
}
return nil
}