github.com/ilhicas/nomad@v0.11.8/drivers/docker/cmd/main.go (about) 1 // This package provides a mechanism to build the Docker driver plugin as an 2 // external binary. The binary has two entry points; the docker driver and the 3 // docker plugin's logging child binary. An example of using this is `go build 4 // -o </nomad/plugin/dir/docker`. When Nomad agent is then launched, the 5 // external docker plugin will be used. 6 package main 7 8 import ( 9 "context" 10 "os" 11 12 log "github.com/hashicorp/go-hclog" 13 plugin "github.com/hashicorp/go-plugin" 14 "github.com/hashicorp/nomad/drivers/docker" 15 "github.com/hashicorp/nomad/drivers/docker/docklog" 16 "github.com/hashicorp/nomad/plugins" 17 "github.com/hashicorp/nomad/plugins/base" 18 ) 19 20 func main() { 21 22 if len(os.Args) > 1 { 23 // Detect if we are being launched as a docker logging plugin 24 switch os.Args[1] { 25 case docklog.PluginName: 26 logger := log.New(&log.LoggerOptions{ 27 Level: log.Trace, 28 JSONFormat: true, 29 Name: docklog.PluginName, 30 }) 31 32 plugin.Serve(&plugin.ServeConfig{ 33 HandshakeConfig: base.Handshake, 34 Plugins: map[string]plugin.Plugin{ 35 docklog.PluginName: docklog.NewPlugin(docklog.NewDockerLogger(logger)), 36 }, 37 GRPCServer: plugin.DefaultGRPCServer, 38 Logger: logger, 39 }) 40 41 return 42 } 43 } 44 45 // Serve the plugin 46 plugins.ServeCtx(factory) 47 } 48 49 // factory returns a new instance of the docker driver plugin 50 func factory(ctx context.Context, log log.Logger) interface{} { 51 return docker.NewDockerDriver(ctx, log) 52 }