From 150677f1f592fbb6ce23db54d66cf57f1531bf37 Mon Sep 17 00:00:00 2001 From: Brian Bland Date: Thu, 6 Nov 2014 10:35:15 -0800 Subject: [PATCH] Expects storage driver executables to be of the form registry-storage-name Moves main packages to sub-packages of the individual storage drivers --- .../registry-storagedriver-filesystem/main.go | 0 .../registry-storagedriver-inmemory/main.go | 0 .../registry-storagedriver-s3/main.go | 0 storagedriver/README.md | 4 ++-- storagedriver/ipc/client.go | 18 ++++++++---------- 5 files changed, 10 insertions(+), 12 deletions(-) rename main/storagedriver/filesystem/filesystem.go => cmd/registry-storagedriver-filesystem/main.go (100%) rename main/storagedriver/inmemory/inmemory.go => cmd/registry-storagedriver-inmemory/main.go (100%) rename main/storagedriver/s3/s3.go => cmd/registry-storagedriver-s3/main.go (100%) diff --git a/main/storagedriver/filesystem/filesystem.go b/cmd/registry-storagedriver-filesystem/main.go similarity index 100% rename from main/storagedriver/filesystem/filesystem.go rename to cmd/registry-storagedriver-filesystem/main.go diff --git a/main/storagedriver/inmemory/inmemory.go b/cmd/registry-storagedriver-inmemory/main.go similarity index 100% rename from main/storagedriver/inmemory/inmemory.go rename to cmd/registry-storagedriver-inmemory/main.go diff --git a/main/storagedriver/s3/s3.go b/cmd/registry-storagedriver-s3/main.go similarity index 100% rename from main/storagedriver/s3/s3.go rename to cmd/registry-storagedriver-s3/main.go diff --git a/storagedriver/README.md b/storagedriver/README.md index f2795834d..09ee7bf06 100644 --- a/storagedriver/README.md +++ b/storagedriver/README.md @@ -26,7 +26,7 @@ Driver Selection and Configuration The preferred method of selecting a storage driver is using the `StorageDriverFactory` interface in the `storagedriver/factory` package. These factories provide a common interface for constructing storage drivers with a parameters map. The factory model is based off of the [Register](http://golang.org/pkg/database/sql/#Register) and [Open](http://golang.org/pkg/database/sql/#Open) methods in the builtin [database/sql](http://golang.org/pkg/database/sql) package. -Storage driver factories may be registered by name using the `factory.Register` method, and then later invoked by calling `factory.Create` with a driver name and parameters map. If no driver is registered with the given name, this factory will attempt to find an executable storage driver with the same name and return an IPC storage driver wrapper managing the driver subprocess. If no such storage driver can be found, `factory.Create` will return an `InvalidStorageDriverError`. +Storage driver factories may be registered by name using the `factory.Register` method, and then later invoked by calling `factory.Create` with a driver name and parameters map. If no driver is registered with the given name, this factory will attempt to find an executable storage driver with the executable name "registry-storage-\" and return an IPC storage driver wrapper managing the driver subprocess. If no such storage driver can be found, `factory.Create` will return an `InvalidStorageDriverError`. Driver Contribution =================== @@ -38,7 +38,7 @@ To create a valid storage driver, one must implement the `storagedriver.StorageD Storage drivers should call `factory.Register` with their driver name in an `init` method, allowing callers of `factory.New` to construct instances of this driver without requiring modification of imports throughout the codebase. ### Out-of-process drivers -As many users will run the registry as a pre-constructed docker container, storage drivers should also be distributable as IPC server executables. Drivers written in go should model the main method provided in `main/storagedriver/filesystem/filesystem.go`. Parameters to IPC drivers will be provided as a JSON-serialized map in the first argument to the process. These parameters should be validated and then a blocking call to `ipc.StorageDriverServer` should be made with a new storage driver. +As many users will run the registry as a pre-constructed docker container, storage drivers should also be distributable as IPC server executables. Drivers written in go should model the main method provided in `storagedriver/filesystem/registry-storage-filesystem/filesystem.go`. Parameters to IPC drivers will be provided as a JSON-serialized map in the first argument to the process. These parameters should be validated and then a blocking call to `ipc.StorageDriverServer` should be made with a new storage driver. ## Testing Storage driver test suites are provided in `storagedriver/testsuites/testsuites.go` and may be used for any storage driver written in go. Two methods are provided for registering test suites, `RegisterInProcessSuite` and `RegisterIPCSuite`, which run the same set of tests for the driver imported or managed over IPC respectively. diff --git a/storagedriver/ipc/client.go b/storagedriver/ipc/client.go index fd5f15c32..929eda611 100644 --- a/storagedriver/ipc/client.go +++ b/storagedriver/ipc/client.go @@ -8,13 +8,16 @@ import ( "net" "os" "os/exec" - "path" "syscall" "github.com/docker/libchan" "github.com/docker/libchan/spdy" ) +// StorageDriverExecutablePrefix is the prefix which the IPC storage driver loader expects driver +// executables to begin with. For example, the s3 driver should be named "registry-storage-s3". +const StorageDriverExecutablePrefix = "registry-storagedriver-" + // StorageDriverClient is a storagedriver.StorageDriver implementation using a managed child process // communicating over IPC using libchan with a unix domain socket type StorageDriverClient struct { @@ -38,15 +41,10 @@ func NewDriverClient(name string, parameters map[string]string) (*StorageDriverC return nil, err } - driverPath := os.ExpandEnv(path.Join("$GOPATH", "bin", name)) - if _, err := os.Stat(driverPath); os.IsNotExist(err) { - driverPath = path.Join(path.Dir(os.Args[0]), name) - } - if _, err := os.Stat(driverPath); os.IsNotExist(err) { - driverPath, err = exec.LookPath(name) - if err != nil { - return nil, err - } + driverExecName := StorageDriverExecutablePrefix + name + driverPath, err := exec.LookPath(driverExecName) + if err != nil { + return nil, err } command := exec.Command(driverPath, string(paramsBytes))