Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
Merge pull request #421 from zalando/issue-396
Browse files Browse the repository at this point in the history
Extending the PULL_SELENIUM_IMAGE to actually pull the image
  • Loading branch information
diemol authored Jan 28, 2018
2 parents 3958e86 + aff687e commit 744d3ad
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
8 changes: 4 additions & 4 deletions docker/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ events {
}
http {
client_max_body_size 300M;
proxy_connect_timeout 600s;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
send_timeout 600s;
proxy_connect_timeout 900s;
proxy_send_timeout 900s;
proxy_read_timeout 900s;
send_timeout 900s;

server {
listen 4444;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableMap;
import com.spotify.docker.client.AnsiProgressHandler;
import com.spotify.docker.client.DefaultDockerClient;
import com.spotify.docker.client.DockerClient;
import com.spotify.docker.client.LogStream;
Expand Down Expand Up @@ -66,6 +67,8 @@ public class DockerContainerClient implements ContainerClient {
private List<ContainerMount> mntFolders = new ArrayList<>();
private List<String> zaleniumHttpEnvVars = new ArrayList<>();
private Map<String, String> seleniumContainerLabels = new HashMap<>();
private boolean pullSeleniumImage = false;
private AtomicBoolean pullSeleniumImageChecked = new AtomicBoolean(false);
private AtomicBoolean mntFoldersAndHttpEnvVarsChecked = new AtomicBoolean(false);
private AtomicBoolean seleniumContainerLabelsChecked = new AtomicBoolean(false);

Expand Down Expand Up @@ -183,6 +186,7 @@ public ContainerCreationStatus createContainer(String zaleniumContainerName, Str
loadMountedFolders(zaleniumContainerName);
// In some environments the created containers need to be labeled so the platform can handle them. E.g. Rancher.
loadSeleniumContainerLabels();
loadPullSeleniumImageFlag();

List<String> binds = generateMountedFolderBinds();
binds.add("/dev/shm:/dev/shm");
Expand Down Expand Up @@ -240,6 +244,20 @@ public ContainerCreationStatus createContainer(String zaleniumContainerName, Str

final ContainerConfig containerConfig = builder.build();

try {
if (pullSeleniumImage) {
List<Image> images = dockerClient.listImages(DockerClient.ListImagesParam.byName(image));
if (images.size() == 0) {
// If the image has no tag, we add latest, otherwise we end up pulling all the images with that name.
String imageToPull = image.lastIndexOf(':') > 0 ? image : image.concat(":latest");
dockerClient.pull(imageToPull, new AnsiProgressHandler());
}
}
} catch (DockerException | InterruptedException e) {
logger.log(Level.WARNING, nodeId + " Error while checking (and pulling) if the image is present", e);
ga.trackException(e);
}

try {
final ContainerCreation container = dockerClient.createContainer(containerConfig, containerName);
dockerClient.startContainer(container.id());
Expand All @@ -249,7 +267,7 @@ public ContainerCreationStatus createContainer(String zaleniumContainerName, Str
ga.trackException(e);
return new ContainerCreationStatus(false);
}
}
}

@VisibleForTesting
protected static void setEnv(final Environment env) {
Expand Down Expand Up @@ -279,6 +297,12 @@ private void loadSeleniumContainerLabels() {
}
}

private void loadPullSeleniumImageFlag() {
if (!this.pullSeleniumImageChecked.getAndSet(true)) {
pullSeleniumImage = env.getBooleanEnvVariable("PULL_SELENIUM_IMAGE", false);
}
}

private void loadMountedFolders(String zaleniumContainerName) {
if (!this.mntFoldersAndHttpEnvVarsChecked.get()) {
String containerId = getContainerId(zaleniumContainerName);
Expand Down

0 comments on commit 744d3ad

Please sign in to comment.