-
Notifications
You must be signed in to change notification settings - Fork 783
/
controller_buildnumbers.go
63 lines (54 loc) · 1.85 KB
/
controller_buildnumbers.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
package cmd
import (
"github.com/jenkins-x/jx/pkg/buildnum"
"github.com/jenkins-x/jx/pkg/jx/cmd/templates"
"github.com/spf13/cobra"
)
const (
command = "buildnumbers"
optionPort = "port"
optionBind = "bind"
)
// ControllerBuildNumbersOptions holds the options for the build number service.
type ControllerBuildNumbersOptions struct {
*CommonOptions
BindAddress string
Port int
}
var (
serveBuildNumbersLong = templates.LongDesc(`Runs the build number controller that serves sequential build
numbers over an HTTP interface.`)
serveBuildNumbersExample = templates.Examples("jx " + command)
)
// NewCmdControllerBuildNumbers builds a new command to serving build numbers over an HTTP interface.
func NewCmdControllerBuildNumbers(commonOpts *CommonOptions) *cobra.Command {
options := ControllerBuildNumbersOptions{
CommonOptions: commonOpts,
}
cmd := &cobra.Command{
Use: command,
Short: "Runs the service to generate build numbers.",
Long: serveBuildNumbersLong,
Example: serveBuildNumbersExample,
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := options.Run()
CheckErr(err)
},
}
cmd.Flags().IntVarP(&options.Port, optionPort, "", 8080, "The TCP port to listen on.")
cmd.Flags().StringVarP(&options.BindAddress, optionBind, "", "",
"The interface address to bind to (by default, will listen on all interfaces/addresses).")
return cmd
}
// Run will execute this command, starting the HTTP build number generation service with the specified options.
func (o *ControllerBuildNumbersOptions) Run() error {
jxClient, ns, err := o.JXClientAndDevNamespace()
if err != nil {
return err
}
buildNumGen := buildnum.NewCRDBuildNumGen(jxClient, ns)
httpBuildNumServer := buildnum.NewHTTPBuildNumberServer(o.BindAddress, o.Port, buildNumGen)
return httpBuildNumServer.Start()
}