-
Notifications
You must be signed in to change notification settings - Fork 2k
/
main.go
51 lines (43 loc) · 1.37 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
// This package provides a mechanism to build the Docker driver plugin as an
// external binary. The binary has two entry points; the docker driver and the
// docker plugin's logging child binary. An example of using this is `go build
// -o </nomad/plugin/dir/docker`. When Nomad agent is then launched, the
// external docker plugin will be used.
package main
import (
"os"
log "github.com/hashicorp/go-hclog"
plugin "github.com/hashicorp/go-plugin"
"github.com/hashicorp/nomad/drivers/docker"
"github.com/hashicorp/nomad/drivers/docker/docklog"
"github.com/hashicorp/nomad/plugins"
"github.com/hashicorp/nomad/plugins/base"
)
func main() {
if len(os.Args) > 1 {
// Detect if we are being launched as a docker logging plugin
switch os.Args[1] {
case docklog.PluginName:
logger := log.New(&log.LoggerOptions{
Level: log.Trace,
JSONFormat: true,
Name: docklog.PluginName,
})
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: base.Handshake,
Plugins: map[string]plugin.Plugin{
docklog.PluginName: docklog.NewPlugin(docklog.NewDockerLogger(logger)),
},
GRPCServer: plugin.DefaultGRPCServer,
Logger: logger,
})
return
}
}
// Serve the plugin
plugins.Serve(factory)
}
// factory returns a new instance of the docker driver plugin
func factory(log log.Logger) interface{} {
return docker.NewDockerDriver(log)
}