From 3b58a891b73af2736a9f71525c898637e168a6fc Mon Sep 17 00:00:00 2001 From: Ivan Krutov Date: Tue, 30 Oct 2018 07:31:02 +0300 Subject: [PATCH 1/2] Added flag to turn off logging (fixes #197) --- cmd/selenoid.go | 21 ++++++++++++--------- selenoid/base.go | 4 ++++ selenoid/docker.go | 4 +++- selenoid/drivers.go | 4 +++- selenoid/lifecycle.go | 21 +++++++++++---------- 5 files changed, 33 insertions(+), 21 deletions(-) diff --git a/cmd/selenoid.go b/cmd/selenoid.go index f72ff81..4ba0715 100644 --- a/cmd/selenoid.go +++ b/cmd/selenoid.go @@ -27,6 +27,7 @@ var ( port uint16 uiPort uint16 userNS string + disableLogs bool ) func init() { @@ -157,20 +158,22 @@ func initFlags() { c.Flags().StringVarP(&args, "args", "g", "", "additional service arguments (e.g. \"-limit 5\")") c.Flags().StringVarP(&env, "env", "e", "", "override service environment variables (e.g. \"KEY1=value1 KEY2=value2\")") c.Flags().StringVarP(&userNS, "userns", "", "", "override user namespace, similarly to \"docker run --userns host ...\" (Docker only)") + c.Flags().BoolVarP(&disableLogs, "disable-logs", "", false, "start with log saving feature disabled") } } func createLifecycle(configDir string, port uint16) (*selenoid.Lifecycle, error) { config := selenoid.LifecycleConfig{ - Quiet: quiet, - Force: force, - ConfigDir: configDir, - Browsers: browsers, - BrowserEnv: browserEnv, - Download: !skipDownload, - Args: args, - Env: env, - Port: int(port), + Quiet: quiet, + Force: force, + ConfigDir: configDir, + Browsers: browsers, + BrowserEnv: browserEnv, + Download: !skipDownload, + Args: args, + Env: env, + Port: int(port), + DisableLogs: disableLogs, LastVersions: lastVersions, RegistryUrl: registry, diff --git a/selenoid/base.go b/selenoid/base.go index fc65fe4..1b374ab 100644 --- a/selenoid/base.go +++ b/selenoid/base.go @@ -122,6 +122,10 @@ type UserNSAware struct { UserNS string } +type LogsAware struct { + DisableLogs bool +} + const ( SelenoidDefaultPort = 4444 SelenoidUIDefaultPort = 8080 diff --git a/selenoid/docker.go b/selenoid/docker.go index 15f48e4..c7bf9e7 100644 --- a/selenoid/docker.go +++ b/selenoid/docker.go @@ -73,6 +73,7 @@ type DockerConfigurator struct { BrowserEnvAware PortAware UserNSAware + LogsAware LastVersions int Pull bool RegistryUrl string @@ -96,6 +97,7 @@ func NewDockerConfigurator(config *LifecycleConfig) (*DockerConfigurator, error) BrowserEnvAware: BrowserEnvAware{BrowserEnv: config.BrowserEnv}, PortAware: PortAware{Port: config.Port}, UserNSAware: UserNSAware{UserNS: config.UserNS}, + LogsAware: LogsAware{DisableLogs: config.DisableLogs}, RegistryUrl: config.RegistryUrl, LastVersions: config.LastVersions, Tmpfs: config.Tmpfs, @@ -666,7 +668,7 @@ func (c *DockerConfigurator) Start() error { cmd = append(cmd, "-video-output-dir", "/opt/selenoid/video/", "-video-recorder-image", videoRecorderImage) } - if !contains(cmd, "-log-output-dir") && isLogSavingSupported(c.Logger, c.Version) { + if !c.DisableLogs && !contains(cmd, "-log-output-dir") && isLogSavingSupported(c.Logger, c.Version) { cmd = append(cmd, "-log-output-dir", "/opt/selenoid/logs/") } diff --git a/selenoid/drivers.go b/selenoid/drivers.go index 011a346..0fa82a4 100644 --- a/selenoid/drivers.go +++ b/selenoid/drivers.go @@ -66,6 +66,7 @@ type DriversConfigurator struct { BrowserEnvAware PortAware RequestedBrowsersAware + LogsAware Browsers string BrowsersJsonUrl string @@ -85,6 +86,7 @@ func NewDriversConfigurator(config *LifecycleConfig) *DriversConfigurator { PortAware: PortAware{Port: config.Port}, DownloadAware: DownloadAware{DownloadNeeded: config.Download}, RequestedBrowsersAware: RequestedBrowsersAware{Browsers: config.Browsers}, + LogsAware: LogsAware{DisableLogs: config.DisableLogs}, BrowsersJsonUrl: config.BrowsersJsonUrl, Browsers: config.Browsers, GithubBaseUrl: config.GithubBaseUrl, @@ -584,7 +586,7 @@ func (d *DriversConfigurator) Start() error { if !contains(args, "-disable-docker") { args = append(args, "-disable-docker") } - if !contains(args, "-log-output-dir") && isLogSavingSupported(d.Logger, d.Version) { + if !d.DisableLogs && !contains(args, "-log-output-dir") && isLogSavingSupported(d.Logger, d.Version) { logsConfigDir := getVolumeConfigDir(filepath.Join(d.ConfigDir, logsDirName), append(selenoidConfigDirElem, logsDirName)) args = append(args, "-log-output-dir", logsConfigDir) } diff --git a/selenoid/lifecycle.go b/selenoid/lifecycle.go index 249c804..b147e74 100644 --- a/selenoid/lifecycle.go +++ b/selenoid/lifecycle.go @@ -9,16 +9,17 @@ import ( ) type LifecycleConfig struct { - Quiet bool - Force bool - ConfigDir string - Browsers string - BrowserEnv string - Download bool - Args string - Env string - Version string - Port int + Quiet bool + Force bool + ConfigDir string + Browsers string + BrowserEnv string + Download bool + Args string + Env string + Version string + Port int + DisableLogs bool // Docker specific LastVersions int From 0bf53e026a85bf421f8d617fdd4d0aa5e504e534 Mon Sep 17 00:00:00 2001 From: Ivan Krutov Date: Mon, 29 Oct 2018 20:37:24 +0300 Subject: [PATCH 2/2] Mounting volumes with :Z flag to avoid permission issues on CentOS (fixes #196) --- selenoid/docker.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/selenoid/docker.go b/selenoid/docker.go index c7bf9e7..eb130a7 100644 --- a/selenoid/docker.go +++ b/selenoid/docker.go @@ -644,16 +644,16 @@ func (c *DockerConfigurator) Start() error { videoConfigDir := getVolumeConfigDir(filepath.Join(c.ConfigDir, videoDirName), append(selenoidConfigDirElem, videoDirName)) logsConfigDir := getVolumeConfigDir(filepath.Join(c.ConfigDir, logsDirName), append(selenoidConfigDirElem, logsDirName)) volumes := []string{ - fmt.Sprintf("%s:/etc/selenoid:ro", volumeConfigDir), - fmt.Sprintf("%s:/opt/selenoid/video", videoConfigDir), - fmt.Sprintf("%s:/opt/selenoid/logs", logsConfigDir), + fmt.Sprintf("%s:/etc/selenoid:ro,Z", volumeConfigDir), + fmt.Sprintf("%s:/opt/selenoid/video:Z", videoConfigDir), + fmt.Sprintf("%s:/opt/selenoid/logs:Z", logsConfigDir), } const dockerSocket = "/var/run/docker.sock" if c.isDockerForWindows() { //With two slashes. See https://stackoverflow.com/questions/36765138/bind-to-docker-socket-on-windows volumes = append(volumes, fmt.Sprintf("/%s:%s", dockerSocket, dockerSocket)) } else if fileExists(dockerSocket) { - volumes = append(volumes, fmt.Sprintf("%s:%s", dockerSocket, dockerSocket)) + volumes = append(volumes, fmt.Sprintf("%s:%s:Z", dockerSocket, dockerSocket)) } cmd := []string{}