-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.go
57 lines (47 loc) · 1.68 KB
/
app.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
package v3
import (
"fmt"
"github.com/happytobi/cf-puppeteer/arguments"
"github.com/happytobi/cf-puppeteer/ui"
"github.com/pkg/errors"
)
func (resource *ResourcesData) CreateApp(parsedArguments *arguments.ParserArguments) (err error) {
args := []string{"v3-create-app", parsedArguments.AppName}
//check if user pushes a docker image
if len(parsedArguments.DockerImage) > 0 {
args = append(args, "--app-type", "docker")
}
err = resource.Executor.Execute(args)
if err != nil {
return errors.Wrap(err, "could not create app")
}
return nil
}
func (resource *ResourcesData) PushApp(parsedArguments *arguments.ParserArguments) (err error) {
args := []string{"v3-push", parsedArguments.AppName, "--no-start"}
if len(parsedArguments.AppPath) > 0 && len(parsedArguments.DockerImage) == 0 {
args = append(args, "-p", parsedArguments.AppPath)
}
if len(parsedArguments.DockerImage) > 0 {
args = append(args, "--docker-image", parsedArguments.DockerImage)
if len(parsedArguments.DockerUserName) > 0 {
args = append(args, "--docker-username", parsedArguments.DockerUserName)
}
}
if parsedArguments.NoRoute == true {
args = append(args, "--no-route")
}
err = resource.Executor.Execute(args)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("could not push application with passed args: %v", args))
}
for envKey, envVal := range parsedArguments.Envs {
ui.Say(fmt.Sprintf("set environment-variable %s", envKey))
args = []string{"v3-set-env", parsedArguments.AppName, envKey, envVal}
err = resource.Executor.Execute(args)
if err != nil {
ui.Failed("could not set environment variable with key: %s to application: %s", envKey, parsedArguments.AppName)
}
}
return nil
}