Skip to content

Commit b6be1b7

Browse files
committed
Merge pull request docker-archive-public#2954 from jeanlaurent/engine-url
Fix docker-archive-public#2029 - local drivers dont run with engine-install-url
2 parents ccdf3c2 + 8eb22b4 commit b6be1b7

File tree

9 files changed

+56
-7
lines changed

9 files changed

+56
-7
lines changed

commands/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var (
4545
cli.StringFlag{
4646
Name: "engine-install-url",
4747
Usage: "Custom URL to use for engine installation",
48-
Value: "https://get.docker.com",
48+
Value: drivers.DefaultEngineInstallURL,
4949
EnvVar: "MACHINE_DOCKER_INSTALL_URL",
5050
},
5151
cli.StringSliceFlag{

drivers/hyperv/hyperv.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"os"
77
"time"
88

9+
"errors"
10+
911
"github.com/docker/machine/libmachine/drivers"
1012
"github.com/docker/machine/libmachine/log"
1113
"github.com/docker/machine/libmachine/mcnflag"
@@ -78,6 +80,9 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
7880
}
7981

8082
func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
83+
if drivers.EngineInstallURLFlagSet(flags) {
84+
return errors.New("--engine-install-url cannot be used with the hyperv driver, use --hyperv-boot2docker-url instead")
85+
}
8186
d.Boot2DockerURL = flags.String("hyperv-boot2docker-url")
8287
d.VSwitch = flags.String("hyperv-virtual-switch")
8388
d.DiskSize = flags.Int("hyperv-disk-size")

drivers/virtualbox/virtualbox.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ func (d *Driver) GetURL() (string, error) {
190190
}
191191

192192
func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
193+
if drivers.EngineInstallURLFlagSet(flags) {
194+
return errors.New("--engine-install-url cannot be used with the virtualbox driver, use --virtualbox-boot2docker-url instead")
195+
}
193196
d.CPU = flags.Int("virtualbox-cpu-count")
194197
d.Memory = flags.Int("virtualbox-memory")
195198
d.DiskSize = flags.Int("virtualbox-disk-size")

drivers/vmwarefusion/fusion_darwin.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"text/template"
1919
"time"
2020

21+
"errors"
22+
2123
"github.com/docker/machine/libmachine/drivers"
2224
"github.com/docker/machine/libmachine/log"
2325
"github.com/docker/machine/libmachine/mcnflag"
@@ -144,6 +146,9 @@ func (d *Driver) DriverName() string {
144146
}
145147

146148
func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
149+
if drivers.EngineInstallURLFlagSet(flags) {
150+
return errors.New("--engine-install-url cannot be used with the vmwarefusion driver, use --vmwarefusion-boot2docker-url instead")
151+
}
147152
d.Memory = flags.Int("vmwarefusion-memory-size")
148153
d.CPU = flags.Int("vmwarefusion-cpu-count")
149154
d.DiskSize = flags.Int("vmwarefusion-disk-size")

drivers/vmwarevsphere/vsphere.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"github.com/docker/machine/libmachine/ssh"
2222
"github.com/docker/machine/libmachine/state"
2323

24+
"errors"
25+
2426
"github.com/vmware/govmomi"
2527
"github.com/vmware/govmomi/find"
2628
"github.com/vmware/govmomi/guest"
@@ -177,6 +179,9 @@ func (d *Driver) DriverName() string {
177179
}
178180

179181
func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
182+
if drivers.EngineInstallURLFlagSet(flags) {
183+
return errors.New("--engine-install-url cannot be used with the vmwarevsphere driver, use --vmwarevsphere-boot2docker-url instead")
184+
}
180185
d.SSHUser = "docker"
181186
d.SSHPort = 22
182187
d.CPU = flags.Int("vmwarevsphere-cpu-count")

libmachine/drivers/base.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import (
66
)
77

88
const (
9-
DefaultSSHUser = "root"
10-
DefaultSSHPort = 22
9+
DefaultSSHUser = "root"
10+
DefaultSSHPort = 22
11+
DefaultEngineInstallURL = "https://get.docker.com"
1112
)
1213

1314
// BaseDriver - Embed this struct into drivers to provide the common set
@@ -83,3 +84,8 @@ func (d *BaseDriver) SetSwarmConfigFromFlags(flags DriverOptions) {
8384
d.SwarmHost = flags.String("swarm-host")
8485
d.SwarmDiscovery = flags.String("swarm-discovery")
8586
}
87+
88+
func EngineInstallURLFlagSet(flags DriverOptions) bool {
89+
engineInstallURLFlag := flags.String("engine-install-url")
90+
return engineInstallURLFlag != DefaultEngineInstallURL && engineInstallURLFlag != ""
91+
}

libmachine/drivers/base_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"testing"
66

7+
"github.com/docker/machine/libmachine/mcnflag"
78
"github.com/stretchr/testify/assert"
89
)
910

@@ -26,3 +27,24 @@ func TestIP(t *testing.T) {
2627
assert.Equal(t, c.expectedErr, err)
2728
}
2829
}
30+
31+
func TestEngineInstallUrlFlagEmpty(t *testing.T) {
32+
assert.False(t, EngineInstallURLFlagSet(&CheckDriverOptions{}))
33+
}
34+
35+
func createDriverOptionWithEngineInstall(url string) *CheckDriverOptions {
36+
return &CheckDriverOptions{
37+
FlagsValues: map[string]interface{}{"engine-install-url": url},
38+
CreateFlags: []mcnflag.Flag{mcnflag.StringFlag{Name: "engine-install-url", Value: ""}},
39+
}
40+
}
41+
42+
func TestEngineInstallUrlFlagDefault(t *testing.T) {
43+
options := createDriverOptionWithEngineInstall(DefaultEngineInstallURL)
44+
assert.False(t, EngineInstallURLFlagSet(options))
45+
}
46+
47+
func TestEngineInstallUrlFlagSet(t *testing.T) {
48+
options := createDriverOptionWithEngineInstall("https://test.docker.com")
49+
assert.True(t, EngineInstallURLFlagSet(options))
50+
}

libmachine/libmachine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (api *Client) NewHost(driverName string, rawDriver []byte) (*host.Host, err
7575
ServerKeyPath: filepath.Join(api.GetMachinesDir(), "server-key.pem"),
7676
},
7777
EngineOptions: &engine.Options{
78-
InstallURL: "https://get.docker.com",
78+
InstallURL: drivers.DefaultEngineInstallURL,
7979
StorageDriver: "aufs",
8080
TLSVerify: true,
8181
},

test/integration/virtualbox/bad-create-iso.bats renamed to test/integration/virtualbox/guards.bats

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ only_if_env DRIVER virtualbox
66

77
use_disposable_machine
88

9-
export BAD_URL="http://dev.null:9111/bad.iso"
10-
119
@test "$DRIVER: Should not allow machine creation with bad ISO" {
12-
run machine create -d virtualbox --virtualbox-boot2docker-url $BAD_URL $NAME
10+
run machine create -d virtualbox --virtualbox-boot2docker-url http://dev.null:9111/bad.iso $NAME
1311
[[ ${status} -eq 1 ]]
1412
}
13+
14+
@test "$DRIVER: Should not allow machine creation with engine-install-url" {
15+
run machine create --engine-install-url https://test.docker.com -d virtualbox $NAME
16+
[[ ${output} == *"--engine-install-url cannot be used"* ]]
17+
}

0 commit comments

Comments
 (0)