forked from docker-archive/deploykit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
94 lines (75 loc) · 2.1 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
package main
import (
"encoding/json"
"fmt"
"os"
log "github.com/Sirupsen/logrus"
"github.com/docker/infrakit/plugin/util"
instance_plugin "github.com/docker/infrakit/spi/http/instance"
"github.com/spf13/cobra"
)
var (
// PluginName is the name of the plugin in the Docker Hub / registry
PluginName = "FileInstance"
// PluginType is the type / interface it supports
PluginType = "infrakit.InstancePlugin/1.0"
// Version is the build release identifier.
Version = "Unspecified"
// Revision is the build source control revision.
Revision = "Unspecified"
)
func main() {
logLevel := len(log.AllLevels) - 2
listen := "unix:///run/infrakit/plugins/instance-file.sock"
dir := os.TempDir()
cmd := &cobra.Command{
Use: os.Args[0],
Short: "File instance plugin",
RunE: func(c *cobra.Command, args []string) error {
if logLevel > len(log.AllLevels)-1 {
logLevel = len(log.AllLevels) - 1
} else if logLevel < 0 {
logLevel = 0
}
log.SetLevel(log.AllLevels[logLevel])
if c.Use == "version" {
return nil
}
log.Infoln("Starting plugin")
log.Infoln("Listening on:", listen)
_, stopped, err := util.StartServer(listen, instance_plugin.PluginServer(
NewFileInstancePlugin(dir)))
if err != nil {
log.Error(err)
}
<-stopped // block until done
log.Infoln("Server stopped")
return nil
},
}
cmd.AddCommand(&cobra.Command{
Use: "version",
Short: "print build version information",
RunE: func(cmd *cobra.Command, args []string) error {
buff, err := json.MarshalIndent(map[string]interface{}{
"name": PluginName,
"type": PluginType,
"version": Version,
"revision": Revision,
}, " ", " ")
if err != nil {
return err
}
fmt.Println(string(buff))
return nil
},
})
cmd.Flags().StringVar(&listen, "listen", listen, "listen address (unix or tcp) for the control endpoint")
cmd.Flags().IntVar(&logLevel, "log", logLevel, "Logging level. 0 is least verbose. Max is 5")
cmd.Flags().StringVar(&dir, "dir", dir, "Dir for storing the files")
err := cmd.Execute()
if err != nil {
log.Error(err)
os.Exit(1)
}
}