Skip to content

Commit

Permalink
[grid] Dynamic Grid is able to disable video container spawn up
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 committed Jan 11, 2025
1 parent 7425162 commit e309cde
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public DockerAssetsPath(String hostPath, String containerPath) {
this.containerPath = containerPath;
}

public String getHostPath() {
return this.hostPath;
}

public String getHostPath(SessionId id) {
return this.hostPath + File.separator + id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ public Map<Capabilities, Collection<SessionFactory>> getDockerSessionFactories(

loadImages(docker, kinds.keySet().toArray(new String[0]));
Image videoImage = getVideoImage(docker);
loadImages(docker, videoImage.getName());
if (videoImage != null) {
loadImages(docker, videoImage.getName());
}

// Hard coding the config section value "node" to avoid an extra dependency
int maxContainerCount =
Expand Down Expand Up @@ -224,6 +226,9 @@ protected List<Device> getDevicesMapping() {

private Image getVideoImage(Docker docker) {
String videoImage = config.get(DOCKER_SECTION, "video-image").orElse(DEFAULT_VIDEO_IMAGE);
if (videoImage.equalsIgnoreCase("false")) {
return null;
}
return docker.getImage(videoImage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,15 @@ private Capabilities addForwardCdpEndpoint(

private Container createBrowserContainer(int port, Capabilities sessionCapabilities) {
Map<String, String> browserContainerEnvVars = getBrowserContainerEnvVars(sessionCapabilities);
// Enable env var to trigger video recording if session capabilities request and external video
// container is disabled
if (videoImage == null && recordVideoForSession(sessionCapabilities)) {
browserContainerEnvVars.put("SE_RECORD_VIDEO", "true");
browserContainerEnvVars.put("SE_VIDEO_FILE_NAME", "auto");
if (runningInDocker) {
browserContainerEnvVars.put("SE_VIDEO_RECORD_STANDALONE", "true");
}
}
long browserContainerShmMemorySize = 2147483648L; // 2GB
ContainerConfig containerConfig =
image(browserImage)
Expand All @@ -295,6 +304,10 @@ private Container createBrowserContainer(int port, Capabilities sessionCapabilit
.network(networkName)
.devices(devices)
.applyHostConfig(hostConfig, hostConfigKeys);
Optional<DockerAssetsPath> path = ofNullable(this.assetsPath);
if (path.isPresent() && videoImage == null && recordVideoForSession(sessionCapabilities)) {
containerConfig.bind(Collections.singletonMap(this.assetsPath.getHostPath(), "/videos"));
}
if (!runningInDocker) {
containerConfig = containerConfig.map(Port.tcp(4444), Port.tcp(port));
}
Expand Down Expand Up @@ -335,7 +348,7 @@ private void setCapsToEnvVars(

private Container startVideoContainer(
Capabilities sessionCapabilities, String browserContainerIp, String hostPath) {
if (!recordVideoForSession(sessionCapabilities)) {
if (videoImage == null || !recordVideoForSession(sessionCapabilities)) {
return null;
}
int videoPort = 9000;
Expand Down

0 comments on commit e309cde

Please sign in to comment.