Merge pull request #2733 from dgageot/2688-run-docker-machine-from-path

Run docker-machine from the PATH for core drivers
This commit is contained in:
David Gageot 2016-01-04 16:28:33 +01:00
commit b7fa3327cf
2 changed files with 15 additions and 3 deletions

View File

@ -88,6 +88,8 @@ func main() {
return
}
localbinary.CurrentBinaryIsDockerMachine = true
setDebugOutputLevel()
cli.AppHelpTemplate = AppHelpTemplate
cli.CommandHelpTemplate = CommandHelpTemplate

View File

@ -16,6 +16,7 @@ var (
// Timeout where we will bail if we're not able to properly contact the
// plugin server.
defaultTimeout = 10 * time.Second
CurrentBinaryIsDockerMachine = false
CoreDrivers = [...]string{"amazonec2", "azure", "digitalocean",
"exoscale", "generic", "google", "hyperv", "none", "openstack",
"rackspace", "softlayer", "virtualbox", "vmwarefusion",
@ -90,10 +91,19 @@ func (e ErrPluginBinaryNotFound) Error() string {
return fmt.Sprintf("Driver %q not found. Do you have the plugin binary accessible in your PATH?", e.driverName)
}
// driverPath finds the path of a driver binary by its name.
// + If the driver is a core driver, there is no separate driver binary. We reuse current binary if it's `docker-machine`
// or we assume `docker-machine` is in the PATH.
// + If the driver is NOT a core driver, then the separate binary must be in the PATH and it's name must be
// `docker-machine-driver-driverName`
func driverPath(driverName string) string {
for _, coreDriver := range CoreDrivers {
if coreDriver == driverName {
return os.Args[0] // "docker-machine"
if CurrentBinaryIsDockerMachine {
return os.Args[0]
}
return "docker-machine"
}
}