forked from nanobox-io/nanobox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.go
78 lines (67 loc) · 2.33 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
package commands
import (
"fmt"
"github.com/spf13/cobra"
"github.com/nanobox-io/nanobox/commands/registry"
"github.com/nanobox-io/nanobox/commands/steps"
"github.com/nanobox-io/nanobox/helpers"
"github.com/nanobox-io/nanobox/models"
"github.com/nanobox-io/nanobox/processors"
"github.com/nanobox-io/nanobox/processors/app"
"github.com/nanobox-io/nanobox/util/config"
"github.com/nanobox-io/nanobox/util/display"
// added because we need its steps
_ "github.com/nanobox-io/nanobox/commands/sim"
)
var (
// DeployCmd ...
DeployCmd = &cobra.Command{
Use: "deploy [dry-run|remote-alias]",
Short: "Deploy your application to a live remote or a dry-run environment.",
Long: ``,
PreRun: func(ccmd *cobra.Command, args []string) {
registry.Set("skip-compile", deployCmdFlags.skipCompile)
steps.Run("configure", "start", "build-runtime", "compile-app")(ccmd, args)
},
Run: deployFn,
}
// deployCmdFlags ...
deployCmdFlags = struct {
skipCompile bool
message string
force bool
}{}
)
//
func init() {
DeployCmd.Flags().BoolVarP(&deployCmdFlags.skipCompile, "skip-compile", "", false, "skip compiling the app")
DeployCmd.Flags().BoolVarP(&deployCmdFlags.force, "force", "", false, "force the deploy even if you have used this build on a previous deploy")
DeployCmd.Flags().StringVarP(&deployCmdFlags.message, "message", "m", "", "Allows you to append a message to the deploy. These messages appear in your app's deploy history in your dashboard.")
}
// deployFn ...
func deployFn(ccmd *cobra.Command, args []string) {
envModel, _ := models.FindEnvByID(config.EnvID())
args, location, name := helpers.Endpoint(envModel, args, 1)
switch location {
case "local":
switch name {
case "dev":
fmt.Println("deploying is not necessary in this context, 'nanobox run' instead")
return
case "sim":
steps.Run("sim start")(ccmd, args)
appModel, _ := models.FindAppBySlug(envModel.ID, "sim")
display.CommandErr(app.Deploy(envModel, appModel))
steps.Run("sim stop")(ccmd, args)
}
case "production":
steps.Run("login")(ccmd, args)
deployConfig := processors.DeployConfig{
App: name,
Message: deployCmdFlags.message,
Force: deployCmdFlags.force,
}
// set the meta arguments to be used in the processor and run the processor
display.CommandErr(processors.Deploy(envModel, deployConfig))
}
}