/
deploy.go
executable file
·84 lines (67 loc) · 1.78 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
package command
import (
"fmt"
"strings"
"github.com/hashicorp/otto/helper/flag"
)
// DeployCommand is the command that deploys the app once it is built.
type DeployCommand struct {
Meta
}
func (c *DeployCommand) Run(args []string) int {
fs := c.FlagSet("deploy", FlagSetNone)
fs.Usage = func() { c.Ui.Error(c.Help()) }
args, execArgs, posArgs := flag.FilterArgs(fs, args)
if err := fs.Parse(args); err != nil {
return 1
}
// Get the remaining args to determine if we have an action.
var action string
if len(posArgs) > 0 {
action = posArgs[0]
execArgs = append(execArgs, posArgs[1:]...)
}
// Load the appfile
app, err := c.Appfile()
if err != nil {
c.Ui.Error(err.Error())
return 1
}
// Get a core
core, err := c.Core(app)
if err != nil {
c.Ui.Error(fmt.Sprintf(
"Error loading core: %s", err))
return 1
}
// Destroy action gets an extra double-check
if action == "destroy" {
msg := "Otto will delete all resources associated with the deploy."
if !c.confirmDestroy(msg, execArgs) {
return 1
}
}
// Deploy the artifact
if err := core.Deploy(action, execArgs); err != nil {
// Display errors without prefix, we expect them to be formatted in a way
// that's suitable for UI.
c.Ui.Error(err.Error())
return 1
}
return 0
}
func (c *DeployCommand) Synopsis() string {
return "Deploy the application"
}
func (c *DeployCommand) Help() string {
helpText := `
Usage: otto deploy [options]
Deploy the application to the current environment.
This command may modify real infrastructure, including adding
and removing resources.
The "build" command should be called prior to this to create the
build artifact. Deploy can be called multiple times with the same
artifact to redeploy an application.
`
return strings.TrimSpace(helpText)
}