github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/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  	"os"
    10  
    11  	log "github.com/hashicorp/go-hclog"
    12  	plugin "github.com/hashicorp/go-plugin"
    13  	"github.com/hashicorp/nomad/drivers/docker"
    14  	"github.com/hashicorp/nomad/drivers/docker/docklog"
    15  	"github.com/hashicorp/nomad/plugins"
    16  	"github.com/hashicorp/nomad/plugins/base"
    17  )
    18  
    19  func main() {
    20  
    21  	if len(os.Args) > 1 {
    22  		// Detect if we are being launched as a docker logging plugin
    23  		switch os.Args[1] {
    24  		case docklog.PluginName:
    25  			logger := log.New(&log.LoggerOptions{
    26  				Level:      log.Trace,
    27  				JSONFormat: true,
    28  				Name:       docklog.PluginName,
    29  			})
    30  
    31  			plugin.Serve(&plugin.ServeConfig{
    32  				HandshakeConfig: base.Handshake,
    33  				Plugins: map[string]plugin.Plugin{
    34  					docklog.PluginName: docklog.NewPlugin(docklog.NewDockerLogger(logger)),
    35  				},
    36  				GRPCServer: plugin.DefaultGRPCServer,
    37  				Logger:     logger,
    38  			})
    39  
    40  			return
    41  		}
    42  	}
    43  
    44  	// Serve the plugin
    45  	plugins.Serve(factory)
    46  }
    47  
    48  // factory returns a new instance of the docker driver plugin
    49  func factory(log log.Logger) interface{} {
    50  	return docker.NewDockerDriver(log)
    51  }