-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuilds.go
More file actions
153 lines (122 loc) · 3.94 KB
/
builds.go
File metadata and controls
153 lines (122 loc) · 3.94 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package parser
import (
docopt "github.com/docopt/docopt-go"
"github.com/drycc/workflow-cli/cmd"
)
// Builds routes build commands to their specific function.
func Builds(argv []string, cmdr cmd.Commander) error {
usage := `
Valid commands for builds:
builds:info print information about a specific build
builds:create imports an image and deploys as a new release
builds:fetch fetch the Procfile and dryccfile to the local
Use 'drycc help [command]' to learn more.
`
switch argv[0] {
case "builds:info":
return buildsInfo(argv, cmdr)
case "builds:create":
return buildsCreate(argv, cmdr)
case "builds:fetch":
return buildsFetch(argv, cmdr)
default:
if printHelp(argv, usage) {
return nil
}
if argv[0] == "builds" {
argv[0] = "builds:info"
return buildsInfo(argv, cmdr)
}
PrintUsage(cmdr)
return nil
}
}
func buildsInfo(argv []string, cmdr cmd.Commander) error {
usage := `
Print information about a specific build.
Usage: drycc builds:info [options]
Options:
-a --app=<app>
the uniquely identifiable name for the application.
-v --version=<version>
the version for which the build info needs to be displayed.
`
args, err := docopt.ParseArgs(usage, argv, "")
if err != nil {
return err
}
var version int
if safeGetString(args, "--version") != "" {
if version, err = versionFromString(safeGetString(args, "--version")); err != nil {
return err
}
}
return cmdr.BuildsInfo(safeGetString(args, "--app"), version)
}
func buildsCreate(argv []string, cmdr cmd.Commander) error {
usage := `
Creates a new build of an application. Imports an <image> and deploys it to Drycc
as a new release. If a Procfile or drycc.yaml is present in the current directory,
it will be used as the default for this application.
Usage: drycc builds:create <image> [options]
Arguments:
<image>
A default fully-qualified container image, either from Drycc Registry (e.g. registry.drycc.cc/drycc/example-go:latest)
or from an in-house registry (e.g. myregistry.example.com:5000/example-go:latest).
This image must include the tag.
Options:
-a --app=<app>
the uniquely identifiable name for the application.
-s --stack=<stack>
the stack name for the application, defaults to container.
-p --procfile=<procfile>
a YAML file used to supply a Procfile to the application.
-d --dryccpath=<dryccpath>
drycc config path to the application, default is '.drycc'.
--confirm=yes
to proceed, type "yes".
`
args, err := docopt.ParseArgs(usage, argv, "")
if err != nil {
return err
}
app := safeGetString(args, "--app")
image := safeGetString(args, "<image>")
confirm := safeGetString(args, "--confirm")
stack := safeGetValue(args, "--stack", "container")
procfile := safeGetValue(args, "--procfile", "Procfile")
dryccpath := safeGetValue(args, "--dryccpath", ".drycc")
return cmdr.BuildsCreate(app, image, stack, procfile, dryccpath, confirm)
}
func buildsFetch(argv []string, cmdr cmd.Commander) error {
usage := `
Print information about a specific build.
Usage: drycc builds:fetch [options]
Options:
-a --app=<app>
the uniquely identifiable name for the application.
-v --version=<version>
the version for which the build info needs to be fetched.
-p --procfile=<procfile>
a YAML file used to supply a Procfile to the application.
-d --dryccpath=<dryccpath>
drycc config path to the application, default is '.drycc'.
--confirm=yes
to proceed, type "yes".
`
args, err := docopt.ParseArgs(usage, argv, "")
if err != nil {
return err
}
app := safeGetString(args, "--app")
var version int
if safeGetString(args, "--version") != "" {
if version, err = versionFromString(safeGetString(args, "--version")); err != nil {
return err
}
}
procfile := safeGetValue(args, "--procfile", "Procfile")
dryccpath := safeGetValue(args, "--dryccpath", ".drycc")
confirm := safeGetString(args, "--confirm")
return cmdr.BuildsFetch(app, version, procfile, dryccpath, confirm)
}