-
Notifications
You must be signed in to change notification settings - Fork 200
/
bundle.go
488 lines (422 loc) · 18 KB
/
bundle.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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
package main
import (
"strings"
"github.com/spf13/cobra"
"github.com/deislabs/porter/pkg/porter"
)
func buildBundlesCommand(p *porter.Porter) *cobra.Command {
cmd := &cobra.Command{
Use: "bundles",
Aliases: []string{"bundle"},
Short: "Bundle commands",
Long: "Commands for working with bundles. These all have shortcuts so that you can call these commands without the bundle resource prefix. For example, porter bundle install is available as porter install as well.",
}
cmd.Annotations = map[string]string{
"group": "resource",
}
cmd.AddCommand(buildBundleCreateCommand(p))
cmd.AddCommand(buildBundleBuildCommand(p))
cmd.AddCommand(buildBundleListCommand(p))
cmd.AddCommand(buildBundleInstallCommand(p))
cmd.AddCommand(buildBundleUpgradeCommand(p))
cmd.AddCommand(buildBundleInvokeCommand(p))
cmd.AddCommand(buildBundleUninstallCommand(p))
cmd.AddCommand(buildBundleShowCommand(p))
cmd.AddCommand(buildBundleOutputCommand(p))
return cmd
}
func buildBundleAliasCommands(p *porter.Porter) []*cobra.Command {
return []*cobra.Command{
buildCreateCommand(p),
buildBuildCommand(p),
buildInstallCommand(p),
buildUpgradeCommand(p),
buildUninstallCommand(p),
buildInvokeCommand(p),
buildPublishCommand(p),
buildShowCommand(p),
}
}
func buildBundleCreateCommand(p *porter.Porter) *cobra.Command {
return &cobra.Command{
Use: "create",
Short: "Create a bundle",
Long: "Create a bundle. This generates a porter bundle in the current directory.",
RunE: func(cmd *cobra.Command, args []string) error {
return p.Create()
},
}
}
func buildCreateCommand(p *porter.Porter) *cobra.Command {
cmd := buildBundleCreateCommand(p)
cmd.Example = strings.Replace(cmd.Example, "porter bundle create", "porter create", -1)
cmd.Annotations = map[string]string{
"group": "alias",
}
return cmd
}
func buildBundleBuildCommand(p *porter.Porter) *cobra.Command {
opts := porter.BuildOptions{}
cmd := &cobra.Command{
Use: "build",
Short: "Build a bundle",
Long: "Builds the bundle in the current directory by generating a Dockerfile and a CNAB bundle.json, and then building the invocation image.",
RunE: func(cmd *cobra.Command, args []string) error {
return p.Build(opts)
},
}
cmd.Flags().BoolVarP(&opts.Verbose, "verbose", "v", false, "Enable verbose logging")
return cmd
}
func buildBuildCommand(p *porter.Porter) *cobra.Command {
cmd := buildBundleBuildCommand(p)
cmd.Example = strings.Replace(cmd.Example, "porter bundle build", "porter build", -1)
cmd.Annotations = map[string]string{
"group": "alias",
}
return cmd
}
func buildBundleListCommand(p *porter.Porter) *cobra.Command {
opts := porter.ListOptions{}
cmd := &cobra.Command{
Use: "list",
Short: "list installed bundles",
Long: `List all bundles installed by Porter.
A listing of bundles currently installed by Porter will be provided, along with metadata such as creation time, last action, last status, etc.
Optional output formats include json and yaml.`,
Example: ` porter bundle list
porter bundle list -o json`,
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.ParseFormat()
},
RunE: func(cmd *cobra.Command, args []string) error {
return p.ListBundles(opts)
},
}
f := cmd.Flags()
f.StringVarP(&opts.RawFormat, "output", "o", "table",
"Specify an output format. Allowed values: table, json, yaml")
return cmd
}
func buildBundleInstallCommand(p *porter.Porter) *cobra.Command {
opts := porter.InstallOptions{}
cmd := &cobra.Command{
Use: "install [CLAIM]",
Short: "Install a bundle",
Long: `Install a bundle.
The first argument is the name of the claim to create for the installation. The claim name defaults to the name of the bundle.
Porter uses the Docker driver as the default runtime for executing a bundle's invocation image, but an alternate driver may be supplied via '--driver/-d'.
For instance, the 'debug' driver may be specified, which simply logs the info given to it and then exits.`,
Example: ` porter bundle install
porter bundle install --insecure
porter bundle install MyAppInDev --file myapp/bundle.json
porter bundle install --param-file base-values.txt --param-file dev-values.txt --param test-mode=true --param header-color=blue
porter bundle install --cred azure --cred kubernetes
porter bundle install --driver debug
porter bundle install MyAppFromTag --tag deislabs/porter-kube-bundle:v1.0
`,
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.Validate(args, p.Context)
},
RunE: func(cmd *cobra.Command, args []string) error {
return p.InstallBundle(opts)
},
}
f := cmd.Flags()
f.BoolVar(&opts.Insecure, "insecure", true,
"Allow working with untrusted bundles")
f.StringVarP(&opts.File, "file", "f", "",
"Path to the porter manifest file. Defaults to the bundle in the current directory.")
f.StringVar(&opts.CNABFile, "cnab-file", "",
"Path to the CNAB bundle.json file.")
f.StringSliceVar(&opts.ParamFiles, "param-file", nil,
"Path to a parameters definition file for the bundle, each line in the form of NAME=VALUE. May be specified multiple times.")
f.StringSliceVar(&opts.Params, "param", nil,
"Define an individual parameter in the form NAME=VALUE. Overrides parameters set with the same name using --param-file. May be specified multiple times.")
f.StringSliceVarP(&opts.CredentialIdentifiers, "cred", "c", nil,
"Credential to use when installing the bundle. May be either a named set of credentials or a filepath, and specified multiple times.")
f.StringVarP(&opts.Driver, "driver", "d", porter.DefaultDriver,
"Specify a driver to use. Allowed values: docker, debug")
f.StringVarP(&opts.Tag, "tag", "t", "",
"Use a bundle in an OCI registry specified by the given tag")
f.BoolVar(&opts.InsecureRegistry, "insecure-registry", false,
"Don't require TLS for the registry")
return cmd
}
func buildInstallCommand(p *porter.Porter) *cobra.Command {
cmd := buildBundleInstallCommand(p)
cmd.Example = strings.Replace(cmd.Example, "porter bundle install", "porter install", -1)
cmd.Annotations = map[string]string{
"group": "alias",
}
return cmd
}
func buildBundleUpgradeCommand(p *porter.Porter) *cobra.Command {
opts := porter.UpgradeOptions{}
cmd := &cobra.Command{
Use: "upgrade [CLAIM]",
Short: "Upgrade a bundle",
Long: `Upgrade a bundle.
The first argument is the name of the claim to upgrade. The claim name defaults to the name of the bundle.
Porter uses the Docker driver as the default runtime for executing a bundle's invocation image, but an alternate driver may be supplied via '--driver/-d'.
For instance, the 'debug' driver may be specified, which simply logs the info given to it and then exits.`,
Example: ` porter bundle upgrade
porter bundle upgrade --insecure
porter bundle upgrade MyAppInDev --file myapp/bundle.json
porter bundle upgrade --param-file base-values.txt --param-file dev-values.txt --param test-mode=true --param header-color=blue
porter bundle upgrade --cred azure --cred kubernetes
porter bundle upgrade --driver debug
porter bundle upgrade MyAppFromTag --tag deislabs/porter-kube-bundle:v1.0
`,
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.Validate(args, p.Context)
},
RunE: func(cmd *cobra.Command, args []string) error {
return p.UpgradeBundle(opts)
},
}
f := cmd.Flags()
f.BoolVar(&opts.Insecure, "insecure", true,
"Allow working with untrusted bundles")
f.StringVarP(&opts.File, "file", "f", "",
"Path to the porter manifest file. Defaults to the bundle in the current directory.")
f.StringVar(&opts.CNABFile, "cnab-file", "",
"Path to the CNAB bundle.json file.")
f.StringSliceVar(&opts.ParamFiles, "param-file", nil,
"Path to a parameters definition file for the bundle, each line in the form of NAME=VALUE. May be specified multiple times.")
f.StringSliceVar(&opts.Params, "param", nil,
"Define an individual parameter in the form NAME=VALUE. Overrides parameters set with the same name using --param-file. May be specified multiple times.")
f.StringSliceVarP(&opts.CredentialIdentifiers, "cred", "c", nil,
"Credential to use when installing the bundle. May be either a named set of credentials or a filepath, and specified multiple times.")
f.StringVarP(&opts.Driver, "driver", "d", porter.DefaultDriver,
"Specify a driver to use. Allowed values: docker, debug")
f.StringVarP(&opts.Tag, "tag", "t", "",
"Use a bundle in an OCI registry specified by the given tag")
f.BoolVar(&opts.InsecureRegistry, "insecure-registry", false,
"Don't require TLS for the registry")
return cmd
}
func buildUpgradeCommand(p *porter.Porter) *cobra.Command {
cmd := buildBundleUpgradeCommand(p)
cmd.Example = strings.Replace(cmd.Example, "porter bundle upgrade", "porter upgrade", -1)
cmd.Annotations = map[string]string{
"group": "alias",
}
return cmd
}
func buildBundleInvokeCommand(p *porter.Porter) *cobra.Command {
opts := porter.InvokeOptions{}
cmd := &cobra.Command{
Use: "invoke [CLAIM] --action ACTION",
Short: "Invoke a custom action on a bundle",
Long: `Invoke a custom action on a bundle.
The first argument is the name of the claim upon which to invoke the action. The claim name defaults to the name of the bundle.
Porter uses the Docker driver as the default runtime for executing a bundle's invocation image, but an alternate driver may be supplied via '--driver/-d'.
For instance, the 'debug' driver may be specified, which simply logs the info given to it and then exits.`,
Example: ` porter bundle invoke --action ACTION
porter bundle invoke --action ACTION MyAppInDev --file myapp/bundle.json
porter bundle invoke --action ACTION --param-file base-values.txt --param-file dev-values.txt --param test-mode=true --param header-color=blue
porter bundle invoke --action ACTION --cred azure --cred kubernetes
porter bundle invoke --action ACTION --driver debug
porter bundle invoke --action ACTION MyAppFromTag --tag deislabs/porter-kube-bundle:v1.0
`,
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.Validate(args, p.Context)
},
RunE: func(cmd *cobra.Command, args []string) error {
return p.InvokeBundle(opts)
},
}
f := cmd.Flags()
f.StringVar(&opts.Action, "action", "",
"Custom action name to invoke.")
f.StringVarP(&opts.File, "file", "f", "",
"Path to the porter manifest file. Defaults to the bundle in the current directory.")
f.StringVar(&opts.CNABFile, "cnab-file", "",
"Path to the CNAB bundle.json file.")
f.StringSliceVar(&opts.ParamFiles, "param-file", nil,
"Path to a parameters definition file for the bundle, each line in the form of NAME=VALUE. May be specified multiple times.")
f.StringSliceVar(&opts.Params, "param", nil,
"Define an individual parameter in the form NAME=VALUE. Overrides parameters set with the same name using --param-file. May be specified multiple times.")
f.StringSliceVarP(&opts.CredentialIdentifiers, "cred", "c", nil,
"Credential to use when installing the bundle. May be either a named set of credentials or a filepath, and specified multiple times.")
f.StringVarP(&opts.Driver, "driver", "d", porter.DefaultDriver,
"Specify a driver to use. Allowed values: docker, debug")
f.StringVarP(&opts.Tag, "tag", "t", "",
"Use a bundle in an OCI registry specified by the given tag")
f.BoolVar(&opts.InsecureRegistry, "insecure-registry", false,
"Don't require TLS for the registry")
return cmd
}
func buildInvokeCommand(p *porter.Porter) *cobra.Command {
cmd := buildBundleInvokeCommand(p)
cmd.Example = strings.Replace(cmd.Example, "porter bundle invoke", "porter invoke", -1)
cmd.Annotations = map[string]string{
"group": "alias",
}
return cmd
}
func buildBundleUninstallCommand(p *porter.Porter) *cobra.Command {
opts := porter.UninstallOptions{}
cmd := &cobra.Command{
Use: "uninstall [CLAIM]",
Short: "Uninstall a bundle",
Long: `Uninstall a bundle
The first argument is the name of the claim to uninstall. The claim name defaults to the name of the bundle.
Porter uses the Docker driver as the default runtime for executing a bundle's invocation image, but an alternate driver may be supplied via '--driver/-d'.
For instance, the 'debug' driver may be specified, which simply logs the info given to it and then exits.`,
Example: ` porter bundle uninstall
porter bundle uninstall --insecure
porter bundle uninstall MyAppInDev --file myapp/bundle.json
porter bundle uninstall --param-file base-values.txt --param-file dev-values.txt --param test-mode=true --param header-color=blue
porter bundle uninstall --cred azure --cred kubernetes
porter bundle uninstall --driver debug
porter bundle uninstall MyAppFromTag --tag deislabs/porter-kube-bundle:v1.0
`,
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.Validate(args, p.Context)
},
RunE: func(cmd *cobra.Command, args []string) error {
return p.UninstallBundle(opts)
},
}
f := cmd.Flags()
f.BoolVar(&opts.Insecure, "insecure", true,
"Allow working with untrusted bundles")
f.StringVarP(&opts.File, "file", "f", "",
"Path to the porter manifest file. Defaults to the bundle in the current directory. Optional unless a newer version of the bundle should be used to uninstall the bundle.")
f.StringVar(&opts.CNABFile, "cnab-file", "",
"Path to the CNAB bundle.json file.")
f.StringSliceVar(&opts.ParamFiles, "param-file", nil,
"Path to a parameters definition file for the bundle, each line in the form of NAME=VALUE. May be specified multiple times.")
f.StringSliceVar(&opts.Params, "param", nil,
"Define an individual parameter in the form NAME=VALUE. Overrides parameters set with the same name using --param-file. May be specified multiple times.")
f.StringSliceVarP(&opts.CredentialIdentifiers, "cred", "c", nil,
"Credential to use when uninstalling the bundle. May be either a named set of credentials or a filepath, and specified multiple times.")
f.StringVarP(&opts.Driver, "driver", "d", porter.DefaultDriver,
"Specify a driver to use. Allowed values: docker, debug")
f.StringVarP(&opts.Tag, "tag", "t", "",
"Use a bundle in an OCI registry specified by the given tag")
f.BoolVar(&opts.InsecureRegistry, "insecure-registry", false,
"Don't require TLS for the registry")
return cmd
}
func buildUninstallCommand(p *porter.Porter) *cobra.Command {
cmd := buildBundleUninstallCommand(p)
cmd.Example = strings.Replace(cmd.Example, "porter bundle uninstall", "porter uninstall", -1)
cmd.Annotations = map[string]string{
"group": "alias",
}
return cmd
}
func buildBundlePublishCommand(p *porter.Porter) *cobra.Command {
opts := porter.PublishOptions{}
cmd := cobra.Command{
Use: "publish",
Short: "Publish a bundle",
Long: "Publishes a bundle by pushing the invocation image and bundle to a registry.",
Example: ` porter bundle publish
porter bundle publish --file myapp/porter.yaml
porter bundle publish --insecure
`,
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.Validate(p.Context)
},
RunE: func(cmd *cobra.Command, args []string) error {
return p.Publish(opts)
},
}
f := cmd.Flags()
f.StringVarP(&opts.File, "file", "f", "", "Path to the Porter manifest. Defaults to `porter.yaml` in the current directory.")
f.BoolVar(&opts.InsecureRegistry, "insecure-registry", false, "Don't require TLS for the registry.")
return &cmd
}
func buildPublishCommand(p *porter.Porter) *cobra.Command {
cmd := buildBundlePublishCommand(p)
cmd.Example = strings.Replace(cmd.Example, "porter bundle publish", "porter publish", -1)
cmd.Annotations = map[string]string{
"group": "alias",
}
return cmd
}
func buildBundleShowCommand(p *porter.Porter) *cobra.Command {
opts := porter.ShowOptions{}
cmd := cobra.Command{
Use: "show [CLAIM]",
Short: "Show a bundle",
Long: "Displays info relating to a bundle claim, including status and a listing of outputs.",
Example: ` porter bundle show [CLAIM]
Optional output formats include json and yaml.
`,
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.Validate(args, p.Context)
},
RunE: func(cmd *cobra.Command, args []string) error {
return p.ShowBundle(opts)
},
}
f := cmd.Flags()
f.StringVarP(&opts.RawFormat, "output", "o", "table",
"Specify an output format. Allowed values: table, json, yaml")
return &cmd
}
func buildShowCommand(p *porter.Porter) *cobra.Command {
cmd := buildBundleShowCommand(p)
cmd.Example = strings.Replace(cmd.Example, "porter bundle show", "porter show", -1)
cmd.Annotations = map[string]string{
"group": "alias",
}
return cmd
}
func buildBundleOutputCommand(p *porter.Porter) *cobra.Command {
cmd := &cobra.Command{
Use: "output",
Aliases: []string{"outputs"},
Short: "Output commands",
Annotations: map[string]string{
"group": "resource",
},
}
cmd.AddCommand(buildBundleOutputShowCommand(p))
cmd.AddCommand(buildBundleOutputListCommand(p))
return cmd
}
func buildBundleOutputListCommand(p *porter.Porter) *cobra.Command {
opts := porter.OutputListOptions{}
cmd := cobra.Command{
Use: "list [CLAIM]",
Short: "List bundle outputs",
Long: "Displays a listing of bundle outputs.",
Example: ` porter bundle outputs list [CLAIM]
Optional output formats include json and yaml.
`,
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.Validate(args, p.Context)
},
RunE: func(cmd *cobra.Command, args []string) error {
return p.ListBundleOutputs(&opts)
},
}
f := cmd.Flags()
f.StringVarP(&opts.RawFormat, "output", "o", "table",
"Specify an output format. Allowed values: table, json, yaml")
return &cmd
}
func buildBundleOutputShowCommand(p *porter.Porter) *cobra.Command {
opts := porter.OutputShowOptions{}
cmd := cobra.Command{
Use: "show NAME [--claim|-c CLAIM]",
Short: "Show a bundle output",
Long: "Show a bundle output.",
Example: ` porter bundle output show NAME [--claim|-c CLAIM]`,
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.Validate(args, p.Context)
},
RunE: func(cmd *cobra.Command, args []string) error {
return p.ShowBundleOutput(&opts)
},
}
f := cmd.Flags()
f.StringVarP(&opts.Name, "claim", "c", "", "Specify a claim that the output belongs to.")
return &cmd
}