forked from openfaas/faas-cli
/
up.go
78 lines (63 loc) · 2.01 KB
/
up.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
// Copyright (c) OpenFaaS Author(s) 2018. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package commands
import (
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
var (
skipPush bool
)
func init() {
upFlagset := pflag.NewFlagSet("up", pflag.ExitOnError)
upFlagset.BoolVar(&skipPush, "skip-push", false, "Skip pushing function to remote registry")
upCmd.Flags().AddFlagSet(upFlagset)
build, _, _ := faasCmd.Find([]string{"build"})
upCmd.Flags().AddFlagSet(build.Flags())
push, _, _ := faasCmd.Find([]string{"push"})
upCmd.Flags().AddFlagSet(push.Flags())
deploy, _, _ := faasCmd.Find([]string{"deploy"})
upCmd.Flags().AddFlagSet(deploy.Flags())
faasCmd.AddCommand(upCmd)
}
// upCmd is a wrapper to the build, push and deploy commands
var upCmd = &cobra.Command{
Use: `up -f [YAML_FILE] [--skip-push] [flags from build, push, deploy]`,
Short: "Builds, pushes and deploys OpenFaaS function containers",
Long: `Build, Push, and Deploy OpenFaaS function containers either via the
supplied YAML config using the "--yaml" flag (which may contain multiple function
definitions), or directly via flags.
The push step may be skipped by setting the --skip-push flag.
Note: All flags from the build, push and deploy flags are valid and can be combined,
see the --help text for those commands for details.`,
Example: ` faas-cli up -f myfn.yaml
faas-cli up --filter "*gif*" --secret dockerhuborg`,
PreRunE: preRunUp,
RunE: upHandler,
}
func preRunUp(cmd *cobra.Command, args []string) error {
if err := preRunBuild(cmd, args); err != nil {
return err
}
if err := preRunDeploy(cmd, args); err != nil {
return err
}
return nil
}
func upHandler(cmd *cobra.Command, args []string) error {
if err := runBuild(cmd, args); err != nil {
return err
}
fmt.Println()
if !skipPush {
if err := runPush(cmd, args); err != nil {
return err
}
fmt.Println()
}
if err := runDeploy(cmd, args); err != nil {
return err
}
return nil
}