-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
112 lines (96 loc) · 2.75 KB
/
main.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
// Slurp is an intermediary to the stored build/blob, used specifically
// to speed up publishing nanobox builds.
//
// Usage
//
// To start slurp as a server, simply run:
//
// slurp
//
// For more specific usage information, refer to the help doc (slurp -h):
// Usage:
// slurp [flags]
//
// Flags:
// -a, --api-address="https://127.0.0.1:1566": Listen uri for the API (scheme defaults to https)
// -t, --api-token="secret": Token for API Access
// -b, --build-dir="/var/db/slurp/build/": Build staging directory
// -c, --config-file="": Configuration file to load
// -i, --insecure[=true]: Disable tls certificate verification when connecting to storage
// -l, --log-level="info": Log level to output [fatal|error|info|debug|trace]
// -s, --ssh-addr="127.0.0.1:1567": Address ssh server will listen on (ip:port combo)
// -k, --ssh-host="/var/db/slurp/slurp_rsa": SSH host (private) key file
// -S, --store-addr="hoarders://127.0.0.1:7410": Storage host address
// -T, --store-token="": Storage auth token
// -v, --version[=false]: Print version info and exit
//
package main
import (
"fmt"
"github.com/jcelliott/lumber"
"github.com/spf13/cobra"
"github.com/nanobox-io/slurp/api"
"github.com/nanobox-io/slurp/backend"
"github.com/nanobox-io/slurp/config"
"github.com/nanobox-io/slurp/ssh"
)
var (
// slurp provides the slurp cli/server functionality
slurp = &cobra.Command{
Use: "slurp",
Short: "slurp - build intermediary",
Long: ``,
SilenceErrors: true,
SilenceUsage: true,
PersistentPreRunE: readConfig,
PreRunE: preFlight,
RunE: startSlurp,
}
// to be populated by linker
version string
commit string
)
// add cli options to slurp
func init() {
config.AddFlags(slurp)
}
func readConfig(ccmd *cobra.Command, args []string) error {
if err := config.LoadConfigFile(); err != nil {
config.Log.Fatal("Failed to read config - %v", err)
return fmt.Errorf("")
}
return nil
}
func preFlight(ccmd *cobra.Command, args []string) error {
if config.Version {
fmt.Printf("slurp %s (%s)\n", version, commit)
return fmt.Errorf("")
}
return nil
}
// start slurp
func startSlurp(ccmd *cobra.Command, args []string) error {
config.Log = lumber.NewConsoleLogger(lumber.LvlInt(config.LogLevel))
// initialize backend
err := backend.Initialize()
if err != nil {
config.Log.Fatal("Backend init failed - %v", err)
return fmt.Errorf("")
}
// start ssh server
err = ssh.Start()
if err != nil {
config.Log.Fatal("SSH server start failed - %v", err)
return fmt.Errorf("")
}
// start api
err = api.StartApi()
if err != nil {
config.Log.Fatal("Api start failed - %v", err)
return fmt.Errorf("")
}
return nil
}
func main() {
slurp.Execute()
}