Skip to content

Commit

Permalink
[grid][java]: dynamic grid re-fetch browser images if they were prune…
Browse files Browse the repository at this point in the history
…d during runtime

Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
  • Loading branch information
VietND96 committed Apr 14, 2024
1 parent 6d7e7da commit f632ae3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions java/src/org/openqa/selenium/docker/ContainerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public ContainerConfig(
this.hostConfig = hostConfig;
}

public Image getImage() {
return this.image;
}

public static ContainerConfig image(Image image) {
return new ContainerConfig(
image,
Expand Down
19 changes: 19 additions & 0 deletions java/src/org/openqa/selenium/docker/v1_41/CreateContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.openqa.selenium.docker.ContainerId;
import org.openqa.selenium.docker.DockerException;
import org.openqa.selenium.docker.DockerProtocol;
import org.openqa.selenium.docker.internal.Reference;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.json.JsonException;
Expand All @@ -52,6 +53,24 @@ public CreateContainer(DockerProtocol protocol, HttpHandler client) {
}

public Container apply(ContainerConfig info) {
try {
return createContainer(info);
} catch (DockerException e) {
if (e.getMessage().contains("No such image")) {
return pullImageAndCreateContainer(info);
} else {
throw e;
}
}
}

private Container pullImageAndCreateContainer(ContainerConfig info) {
PullImage pullImage = new PullImage(client);
pullImage.apply(Reference.parse(info.getImage().getName()));
return createContainer(info);
}

public Container createContainer(ContainerConfig info) {
HttpResponse res =
DockerMessages.throwIfNecessary(
client.execute(
Expand Down

0 comments on commit f632ae3

Please sign in to comment.