diff --git a/.travis.yml b/.travis.yml index 09584ef..538229d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ sudo: required language: go go: + - 1.7.x - 1.8.x - tip diff --git a/cmd/containerd/main.go b/cmd/containerd/main.go index a072199..d5c0721 100644 --- a/cmd/containerd/main.go +++ b/cmd/containerd/main.go @@ -20,6 +20,7 @@ import ( api "github.com/docker/containerd/api/services/execution" "github.com/docker/containerd/content" "github.com/docker/containerd/log" + "github.com/docker/containerd/plugin" "github.com/docker/containerd/utils" metrics "github.com/docker/go-metrics" "github.com/pkg/errors" @@ -85,7 +86,7 @@ func main() { log.G(global).Info("starting containerd boot...") // load all plugins into containerd - if err := containerd.Load(filepath.Join(conf.Root, "plugins")); err != nil { + if err := plugin.Load(filepath.Join(conf.Root, "plugins")); err != nil { return err } // start debug and metrics APIs @@ -222,12 +223,12 @@ func resolveContentStore() (*content.Store, error) { func loadRuntimes() (map[string]containerd.Runtime, error) { o := make(map[string]containerd.Runtime) - for name, rr := range containerd.Registrations() { - if rr.Type != containerd.RuntimePlugin { + for name, rr := range plugin.Registrations() { + if rr.Type != plugin.RuntimePlugin { continue } log.G(global).Infof("loading runtime plugin %q...", name) - ic := &containerd.InitContext{ + ic := &plugin.InitContext{ Root: conf.Root, State: conf.State, Context: log.WithModule(global, fmt.Sprintf("runtime-%s", name)), @@ -252,14 +253,14 @@ func newGRPCServer() *grpc.Server { return s } -func loadServices(runtimes map[string]containerd.Runtime, store *content.Store) ([]containerd.Service, error) { - var o []containerd.Service - for name, sr := range containerd.Registrations() { - if sr.Type != containerd.GRPCPlugin { +func loadServices(runtimes map[string]containerd.Runtime, store *content.Store) ([]plugin.Service, error) { + var o []plugin.Service + for name, sr := range plugin.Registrations() { + if sr.Type != plugin.GRPCPlugin { continue } log.G(global).Infof("loading grpc service plugin %q...", name) - ic := &containerd.InitContext{ + ic := &plugin.InitContext{ Root: conf.Root, State: conf.State, Context: log.WithModule(global, fmt.Sprintf("service-%s", name)), @@ -276,7 +277,7 @@ func loadServices(runtimes map[string]containerd.Runtime, store *content.Store) if err != nil { return nil, err } - o = append(o, vs.(containerd.Service)) + o = append(o, vs.(plugin.Service)) } return o, nil } diff --git a/linux/runtime.go b/linux/runtime.go index e48bb94..d063db2 100644 --- a/linux/runtime.go +++ b/linux/runtime.go @@ -14,6 +14,7 @@ import ( "github.com/docker/containerd/api/types/container" "github.com/docker/containerd/api/types/mount" "github.com/docker/containerd/log" + "github.com/docker/containerd/plugin" "golang.org/x/net/context" ) @@ -24,13 +25,13 @@ const ( ) func init() { - containerd.Register(runtimeName, &containerd.Registration{ - Type: containerd.RuntimePlugin, + plugin.Register(runtimeName, &plugin.Registration{ + Type: plugin.RuntimePlugin, Init: New, }) } -func New(ic *containerd.InitContext) (interface{}, error) { +func New(ic *plugin.InitContext) (interface{}, error) { path := filepath.Join(ic.State, runtimeName) if err := os.MkdirAll(path, 0700); err != nil { return nil, err diff --git a/plugin.go b/plugin/plugin.go similarity index 59% rename from plugin.go rename to plugin/plugin.go index 6ae63ef..bbef1bf 100644 --- a/plugin.go +++ b/plugin/plugin.go @@ -1,12 +1,10 @@ -package containerd +package plugin import ( "fmt" - "path/filepath" - "plugin" - "runtime" "sync" + "github.com/docker/containerd" "github.com/docker/containerd/content" "golang.org/x/net/context" @@ -29,7 +27,7 @@ type Registration struct { type InitContext struct { Root string State string - Runtimes map[string]Runtime + Runtimes map[string]containerd.Runtime Store *content.Store Config interface{} Context context.Context @@ -73,39 +71,3 @@ func Register(name string, r *Registration) error { func Registrations() map[string]*Registration { return register.r } - -// loadPlugins loads all plugins for the OS and Arch -// that containerd is built for inside the provided path -func loadPlugins(path string) error { - abs, err := filepath.Abs(path) - if err != nil { - return err - } - pattern := filepath.Join(abs, fmt.Sprintf( - "*-%s-%s.%s", - runtime.GOOS, - runtime.GOARCH, - getLibExt(), - )) - libs, err := filepath.Glob(pattern) - if err != nil { - return err - } - for _, lib := range libs { - if _, err := plugin.Open(lib); err != nil { - return err - } - } - return nil -} - -// getLibExt returns a platform specific lib extension for -// the platform that containerd is running on -func getLibExt() string { - switch runtime.GOOS { - case "windows": - return "dll" - default: - return "so" - } -} diff --git a/plugin/plugin_go18.go b/plugin/plugin_go18.go new file mode 100644 index 0000000..13ddb32 --- /dev/null +++ b/plugin/plugin_go18.go @@ -0,0 +1,46 @@ +// +build go1.8,!windows + +package plugin + +import ( + "fmt" + "path/filepath" + "plugin" + "runtime" +) + +// loadPlugins loads all plugins for the OS and Arch +// that containerd is built for inside the provided path +func loadPlugins(path string) error { + abs, err := filepath.Abs(path) + if err != nil { + return err + } + pattern := filepath.Join(abs, fmt.Sprintf( + "*-%s-%s.%s", + runtime.GOOS, + runtime.GOARCH, + getLibExt(), + )) + libs, err := filepath.Glob(pattern) + if err != nil { + return err + } + for _, lib := range libs { + if _, err := plugin.Open(lib); err != nil { + return err + } + } + return nil +} + +// getLibExt returns a platform specific lib extension for +// the platform that containerd is running on +func getLibExt() string { + switch runtime.GOOS { + case "windows": + return "dll" + default: + return "so" + } +} diff --git a/plugin/plugin_other.go b/plugin/plugin_other.go new file mode 100644 index 0000000..5057d88 --- /dev/null +++ b/plugin/plugin_other.go @@ -0,0 +1,8 @@ +// +build !go1.8 windows + +package plugin + +func loadPlugins(path string) error { + // plugins not supported until 1.8 + return nil +} diff --git a/services/content/service.go b/services/content/service.go index bc623f4..6286fca 100644 --- a/services/content/service.go +++ b/services/content/service.go @@ -5,10 +5,10 @@ import ( "sync" "github.com/Sirupsen/logrus" - "github.com/docker/containerd" api "github.com/docker/containerd/api/services/content" "github.com/docker/containerd/content" "github.com/docker/containerd/log" + "github.com/docker/containerd/plugin" "github.com/golang/protobuf/ptypes/empty" digest "github.com/opencontainers/go-digest" "github.com/pkg/errors" @@ -30,13 +30,13 @@ var bufPool = sync.Pool{ var _ api.ContentServer = &Service{} func init() { - containerd.Register("content-grpc", &containerd.Registration{ - Type: containerd.GRPCPlugin, + plugin.Register("content-grpc", &plugin.Registration{ + Type: plugin.GRPCPlugin, Init: NewService, }) } -func NewService(ic *containerd.InitContext) (interface{}, error) { +func NewService(ic *plugin.InitContext) (interface{}, error) { return &Service{ store: ic.Store, }, nil diff --git a/services/execution/service.go b/services/execution/service.go index 91285d2..4e9761d 100644 --- a/services/execution/service.go +++ b/services/execution/service.go @@ -7,6 +7,7 @@ import ( api "github.com/docker/containerd/api/services/execution" "github.com/docker/containerd/api/types/container" "github.com/docker/containerd/log" + "github.com/docker/containerd/plugin" google_protobuf "github.com/golang/protobuf/ptypes/empty" "golang.org/x/net/context" "google.golang.org/grpc" @@ -18,13 +19,13 @@ var ( ) func init() { - containerd.Register("runtime-grpc", &containerd.Registration{ - Type: containerd.GRPCPlugin, + plugin.Register("runtime-grpc", &plugin.Registration{ + Type: plugin.GRPCPlugin, Init: New, }) } -func New(ic *containerd.InitContext) (interface{}, error) { +func New(ic *plugin.InitContext) (interface{}, error) { c, err := newCollector(ic.Context, ic.Runtimes) if err != nil { return nil, err