From 7d7b256ae80601457f6715860bab0f34e3fc0d3a Mon Sep 17 00:00:00 2001 From: Ivan Krutov Date: Sun, 21 Jul 2019 15:09:32 +0300 Subject: [PATCH 1/3] Using binaries only when requested explicitly (fixes #224, fixes #226) --- cmd/selenoid.go | 3 +++ selenoid/lifecycle.go | 33 +++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/cmd/selenoid.go b/cmd/selenoid.go index 447d824..ee10cec 100644 --- a/cmd/selenoid.go +++ b/cmd/selenoid.go @@ -15,6 +15,7 @@ var ( arch string version string browsers string + useDrivers bool browsersJSONUrl string configDir string uiConfigDir string @@ -132,6 +133,7 @@ func initFlags() { } { c.Flags().StringVarP(&browsers, "browsers", "b", "", "semicolon separated list of browser names to process") c.Flags().StringVarP(&browserEnv, "browser-env", "w", "", "override container or driver environment variables (e.g. \"KEY1=value1 KEY2=value2\")") + c.Flags().BoolVarP(&useDrivers, "use-drivers", "d", false, "use drivers mode instead of Docker") c.Flags().StringVarP(&browsersJSONUrl, "browsers-json", "j", selenoid.DefaultBrowsersJsonURL, "browsers JSON data URL (in most cases never need to be set manually)") c.Flags().BoolVarP(&skipDownload, "no-download", "n", false, "only output config file without downloading images or drivers") c.Flags().IntVarP(&lastVersions, "last-versions", "l", 2, "process only last N versions (Docker only)") @@ -167,6 +169,7 @@ func createLifecycle(configDir string, port uint16) (*selenoid.Lifecycle, error) Quiet: quiet, Force: force, ConfigDir: configDir, + UseDrivers: useDrivers, Browsers: browsers, BrowserEnv: browserEnv, Download: !skipDownload, diff --git a/selenoid/lifecycle.go b/selenoid/lifecycle.go index 3c4748b..28b73e3 100644 --- a/selenoid/lifecycle.go +++ b/selenoid/lifecycle.go @@ -2,6 +2,7 @@ package selenoid import ( "context" + "errors" "fmt" "github.com/docker/docker/client" "github.com/fatih/color" @@ -29,6 +30,7 @@ type LifecycleConfig struct { UserNS string // Drivers specific + UseDrivers bool BrowsersJsonUrl string GithubBaseUrl string OS string @@ -53,20 +55,8 @@ func NewLifecycle(config *LifecycleConfig) (*Lifecycle, error) { Forceable: Forceable{Force: config.Force}, Config: config, } - if isDockerAvailable() { - lc.Titlef("Using %v", color.BlueString("Docker")) - dockerCfg, err := NewDockerConfigurator(config) - if err != nil { - return nil, err - } - lc.argsAware = dockerCfg - lc.statusAware = dockerCfg - lc.downloadable = dockerCfg - lc.configurable = dockerCfg - lc.runnable = dockerCfg - lc.closer = dockerCfg - } else { - lc.Titlef("Docker is not supported - using binaries...") + if config.UseDrivers { + lc.Titlef("Using driver binaries...") driversCfg := NewDriversConfigurator(config) lc.argsAware = driversCfg lc.statusAware = driversCfg @@ -74,7 +64,22 @@ func NewLifecycle(config *LifecycleConfig) (*Lifecycle, error) { lc.configurable = driversCfg lc.runnable = driversCfg lc.closer = driversCfg + return &lc, nil + } + if !isDockerAvailable() { + return nil, errors.New("can not access Docker: make sure you have Docker installed and current user has access permissions") + } + lc.Titlef("Using %v", color.BlueString("Docker")) + dockerCfg, err := NewDockerConfigurator(config) + if err != nil { + return nil, fmt.Errorf("failed to initialize Docker support: %v", err) } + lc.argsAware = dockerCfg + lc.statusAware = dockerCfg + lc.downloadable = dockerCfg + lc.configurable = dockerCfg + lc.runnable = dockerCfg + lc.closer = dockerCfg return &lc, nil } From 53ec735559c850fc885e83b03345c55af2682cdf Mon Sep 17 00:00:00 2001 From: Ivan Krutov Date: Sun, 21 Jul 2019 15:09:51 +0300 Subject: [PATCH 2/3] Bump Chromedriver version --- browsers.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/browsers.json b/browsers.json index d0f5dda..29b49db 100644 --- a/browsers.json +++ b/browsers.json @@ -4,23 +4,23 @@ "files": { "linux": { "amd64": { - "url": "http://chromedriver.storage.googleapis.com/74.0.3729.6/chromedriver_linux64.zip", + "url": "http://chromedriver.storage.googleapis.com/75.0.3770.140/chromedriver_linux64.zip", "filename": "chromedriver" } }, "darwin": { "amd64": { - "url": "http://chromedriver.storage.googleapis.com/74.0.3729.6/chromedriver_mac64.zip", + "url": "http://chromedriver.storage.googleapis.com/75.0.3770.140/chromedriver_mac64.zip", "filename": "chromedriver" } }, "windows": { "386": { - "url": "http://chromedriver.storage.googleapis.com/74.0.3729.6/chromedriver_win32.zip", + "url": "http://chromedriver.storage.googleapis.com/75.0.3770.140/chromedriver_win32.zip", "filename": "chromedriver.exe" }, "amd64": { - "url": "http://chromedriver.storage.googleapis.com/74.0.3729.6/chromedriver_win32.zip", + "url": "http://chromedriver.storage.googleapis.com/75.0.3770.140/chromedriver_win32.zip", "filename": "chromedriver.exe" } } From 13db5bd162666957ec4878e0e2c33e3354a5a01e Mon Sep 17 00:00:00 2001 From: Ivan Krutov Date: Sun, 21 Jul 2019 15:42:09 +0300 Subject: [PATCH 3/3] Added ability to set shmSize value (fixes #222) --- cmd/selenoid.go | 3 +++ go.mod | 1 + selenoid/docker.go | 6 ++++++ selenoid/docker_test.go | 23 +++++++++++++---------- selenoid/lifecycle.go | 1 + 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/cmd/selenoid.go b/cmd/selenoid.go index ee10cec..c43db33 100644 --- a/cmd/selenoid.go +++ b/cmd/selenoid.go @@ -11,6 +11,7 @@ import ( var ( lastVersions int tmpfs int + shmSize int operatingSystem string arch string version string @@ -137,6 +138,7 @@ func initFlags() { c.Flags().StringVarP(&browsersJSONUrl, "browsers-json", "j", selenoid.DefaultBrowsersJsonURL, "browsers JSON data URL (in most cases never need to be set manually)") c.Flags().BoolVarP(&skipDownload, "no-download", "n", false, "only output config file without downloading images or drivers") c.Flags().IntVarP(&lastVersions, "last-versions", "l", 2, "process only last N versions (Docker only)") + c.Flags().IntVarP(&shmSize, "shm-size", "z", 0, "add shmSize sized in megabytes (Docker only)") c.Flags().IntVarP(&tmpfs, "tmpfs", "t", 0, "add tmpfs volume sized in megabytes (Docker only)") c.Flags().BoolVarP(&vnc, "vnc", "s", false, "download containers with VNC support (Docker only)") } @@ -180,6 +182,7 @@ func createLifecycle(configDir string, port uint16) (*selenoid.Lifecycle, error) LastVersions: lastVersions, RegistryUrl: registry, + ShmSize: shmSize, Tmpfs: tmpfs, VNC: vnc, UserNS: userNS, diff --git a/go.mod b/go.mod index 16e1cb3..7baf6ae 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/docker/docker-credential-helpers v0.6.0 // indirect github.com/docker/go-connections v0.4.0 github.com/docker/go-metrics v0.0.0-20180209012529-399ea8c73916 // indirect + github.com/docker/go-units v0.4.0 github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect github.com/fatih/color v1.5.0 github.com/google/go-github v0.0.0-20170519031903-ebfec748347a diff --git a/selenoid/docker.go b/selenoid/docker.go index e676a8d..cba1bc1 100644 --- a/selenoid/docker.go +++ b/selenoid/docker.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/docker/go-units" "io/ioutil" "log" "sort" @@ -77,6 +78,7 @@ type DockerConfigurator struct { LastVersions int Pull bool RegistryUrl string + ShmSize int Tmpfs int VNC bool docker *client.Client @@ -100,6 +102,7 @@ func NewDockerConfigurator(config *LifecycleConfig) (*DockerConfigurator, error) LogsAware: LogsAware{DisableLogs: config.DisableLogs}, RegistryUrl: config.RegistryUrl, LastVersions: config.LastVersions, + ShmSize: config.ShmSize, Tmpfs: config.Tmpfs, VNC: config.VNC, } @@ -474,6 +477,9 @@ func (c *DockerConfigurator) createVersions(browserName string, image string, ta tmpfs["/tmp"] = fmt.Sprintf("size=%dm", c.Tmpfs) browser.Tmpfs = tmpfs } + if c.ShmSize > 0 { + browser.ShmSize, _ = units.RAMInBytes(fmt.Sprintf("%dm", c.ShmSize)) + } browserEnv := strings.Fields(c.BrowserEnv) if len(browserEnv) > 0 { browser.Env = browserEnv diff --git a/selenoid/docker_test.go b/selenoid/docker_test.go index 218db59..31de905 100644 --- a/selenoid/docker_test.go +++ b/selenoid/docker_test.go @@ -261,6 +261,7 @@ func testConfigure(t *testing.T, download bool) { Quiet: false, LastVersions: 2, Tmpfs: 512, + ShmSize: 256, Browsers: "firefox:>45.0;opera", Args: "-limit 42", VNC: true, @@ -288,11 +289,12 @@ func testConfigure(t *testing.T, download bool) { correctFFBrowsers := make(map[string]*config.Browser) correctFFBrowsers["46.0"] = &config.Browser{ - Image: "selenoid/vnc_firefox:46.0", - Port: "4444", - Path: "/wd/hub", - Tmpfs: tmpfsMap, - Env: []string{testEnv}, + Image: "selenoid/vnc_firefox:46.0", + Port: "4444", + Path: "/wd/hub", + Tmpfs: tmpfsMap, + ShmSize: 268435456, + Env: []string{testEnv}, } AssertThat(t, firefoxVersions, EqualTo{config.Versions{ Default: "46.0", @@ -306,11 +308,12 @@ func testConfigure(t *testing.T, download bool) { correctOperaBrowsers := make(map[string]*config.Browser) correctOperaBrowsers["44.0"] = &config.Browser{ - Image: "selenoid/vnc_opera:44.0", - Port: "4444", - Path: "/", - Tmpfs: tmpfsMap, - Env: []string{testEnv}, + Image: "selenoid/vnc_opera:44.0", + Port: "4444", + Path: "/", + Tmpfs: tmpfsMap, + ShmSize: 268435456, + Env: []string{testEnv}, } AssertThat(t, operaVersions, EqualTo{config.Versions{ Default: "44.0", diff --git a/selenoid/lifecycle.go b/selenoid/lifecycle.go index 28b73e3..b0fa0df 100644 --- a/selenoid/lifecycle.go +++ b/selenoid/lifecycle.go @@ -25,6 +25,7 @@ type LifecycleConfig struct { // Docker specific LastVersions int RegistryUrl string + ShmSize int Tmpfs int VNC bool UserNS string