Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #230 from vania-pooh/master
Browse files Browse the repository at this point in the history
Ability to set custom shmSize
  • Loading branch information
vania-pooh authored Jul 21, 2019
2 parents 55cf9f4 + 13db5bd commit cd5d622
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 28 deletions.
8 changes: 4 additions & 4 deletions browsers.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand Down
6 changes: 6 additions & 0 deletions cmd/selenoid.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import (
var (
lastVersions int
tmpfs int
shmSize int
operatingSystem string
arch string
version string
browsers string
useDrivers bool
browsersJSONUrl string
configDir string
uiConfigDir string
Expand Down Expand Up @@ -132,9 +134,11 @@ 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)")
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)")
}
Expand Down Expand Up @@ -167,6 +171,7 @@ func createLifecycle(configDir string, port uint16) (*selenoid.Lifecycle, error)
Quiet: quiet,
Force: force,
ConfigDir: configDir,
UseDrivers: useDrivers,
Browsers: browsers,
BrowserEnv: browserEnv,
Download: !skipDownload,
Expand All @@ -177,6 +182,7 @@ func createLifecycle(configDir string, port uint16) (*selenoid.Lifecycle, error)

LastVersions: lastVersions,
RegistryUrl: registry,
ShmSize: shmSize,
Tmpfs: tmpfs,
VNC: vnc,
UserNS: userNS,
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions selenoid/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/docker/go-units"
"io/ioutil"
"log"
"sort"
Expand Down Expand Up @@ -77,6 +78,7 @@ type DockerConfigurator struct {
LastVersions int
Pull bool
RegistryUrl string
ShmSize int
Tmpfs int
VNC bool
docker *client.Client
Expand All @@ -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,
}
Expand Down Expand Up @@ -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
Expand Down
23 changes: 13 additions & 10 deletions selenoid/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
34 changes: 20 additions & 14 deletions selenoid/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package selenoid

import (
"context"
"errors"
"fmt"
"github.com/docker/docker/client"
"github.com/fatih/color"
Expand All @@ -24,11 +25,13 @@ type LifecycleConfig struct {
// Docker specific
LastVersions int
RegistryUrl string
ShmSize int
Tmpfs int
VNC bool
UserNS string

// Drivers specific
UseDrivers bool
BrowsersJsonUrl string
GithubBaseUrl string
OS string
Expand All @@ -53,28 +56,31 @@ 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
lc.downloadable = driversCfg
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
}

Expand Down

0 comments on commit cd5d622

Please sign in to comment.