2019-01-07 22:47:49 +00:00
|
|
|
// 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.
|
2018-12-19 23:26:37 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-12-20 00:32:42 +00:00
|
|
|
"os"
|
|
|
|
|
2018-12-19 23:26:37 +00:00
|
|
|
log "github.com/hashicorp/go-hclog"
|
2018-12-20 00:32:42 +00:00
|
|
|
plugin "github.com/hashicorp/go-plugin"
|
2018-12-19 23:26:37 +00:00
|
|
|
"github.com/hashicorp/nomad/drivers/docker"
|
2018-12-20 00:32:42 +00:00
|
|
|
"github.com/hashicorp/nomad/drivers/docker/docklog"
|
2018-12-19 23:26:37 +00:00
|
|
|
"github.com/hashicorp/nomad/plugins"
|
2018-12-20 00:32:42 +00:00
|
|
|
"github.com/hashicorp/nomad/plugins/base"
|
2018-12-19 23:26:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2018-12-20 00:32:42 +00:00
|
|
|
|
|
|
|
if len(os.Args) > 1 {
|
|
|
|
// Detect if we are being launched as a docker logging plugin
|
|
|
|
switch os.Args[1] {
|
|
|
|
case docklog.PluginName:
|
2019-01-09 23:06:58 +00:00
|
|
|
logger := log.New(&log.LoggerOptions{
|
|
|
|
Level: log.Trace,
|
|
|
|
JSONFormat: true,
|
|
|
|
Name: docklog.PluginName,
|
|
|
|
})
|
|
|
|
|
2018-12-20 00:32:42 +00:00
|
|
|
plugin.Serve(&plugin.ServeConfig{
|
|
|
|
HandshakeConfig: base.Handshake,
|
|
|
|
Plugins: map[string]plugin.Plugin{
|
2019-01-09 23:06:58 +00:00
|
|
|
docklog.PluginName: docklog.NewPlugin(docklog.NewDockerLogger(logger)),
|
2018-12-20 00:32:42 +00:00
|
|
|
},
|
|
|
|
GRPCServer: plugin.DefaultGRPCServer,
|
2019-01-09 23:06:58 +00:00
|
|
|
Logger: logger,
|
2018-12-20 00:32:42 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-19 23:26:37 +00:00
|
|
|
// Serve the plugin
|
|
|
|
plugins.Serve(factory)
|
|
|
|
}
|
|
|
|
|
2019-01-07 22:47:49 +00:00
|
|
|
// factory returns a new instance of the docker driver plugin
|
2018-12-19 23:26:37 +00:00
|
|
|
func factory(log log.Logger) interface{} {
|
|
|
|
return docker.NewDockerDriver(log)
|
|
|
|
}
|