Verified Commit 1a6c6d0a authored by Lukas Wiest's avatar Lukas Wiest 🚂
Browse files

refactor(util/docker): add try-catch wrappers around image pull

parent 26b5c569
...@@ -2,6 +2,7 @@ package de.hftstuttgart.utils; ...@@ -2,6 +2,7 @@ package de.hftstuttgart.utils;
import com.github.dockerjava.api.DockerClient; import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.command.CreateContainerResponse; import com.github.dockerjava.api.command.CreateContainerResponse;
import com.github.dockerjava.api.exception.DockerException;
import com.github.dockerjava.api.model.Bind; import com.github.dockerjava.api.model.Bind;
import com.github.dockerjava.api.model.HostConfig; import com.github.dockerjava.api.model.HostConfig;
import com.github.dockerjava.core.DefaultDockerClientConfig; import com.github.dockerjava.core.DefaultDockerClientConfig;
...@@ -40,18 +41,33 @@ public class DockerUtil { ...@@ -40,18 +41,33 @@ public class DockerUtil {
public int runContainer(String image, Bind... binds) throws InterruptedException, IOException public int runContainer(String image, Bind... binds) throws InterruptedException, IOException
{ {
LOG.debug(String.format("pull image: %s", image)); LOG.debug(String.format("pull image: %s", image));
dockerClient.pullImageCmd(image) try {
.start() dockerClient.pullImageCmd(image)
.awaitCompletion() .start()
.close(); .awaitCompletion()
.close();
} catch (DockerException e) {
LOG.error(String.format(
"pulling docker image %s failed with %s, trying with local image",
image,
e.getMessage()));
}
LOG.debug("creating container"); LOG.debug("creating container");
CreateContainerResponse containerResponse = dockerClient.createContainerCmd("testcontainer") CreateContainerResponse containerResponse;
.withImage(image) try {
.withHostConfig( containerResponse = dockerClient.createContainerCmd("testcontainer")
HostConfig.newHostConfig() .withImage(image)
.withBinds(binds)) .withHostConfig(
.exec(); HostConfig.newHostConfig()
.withBinds(binds))
.exec();
} catch (DockerException e) {
LOG.error(String.format(
"Creating Docker Testrunner container failed with %s", e.getMessage()));
throw e;
}
LOG.debug(String.format("container created: %s", containerResponse.getId())); LOG.debug(String.format("container created: %s", containerResponse.getId()));
LOG.debug(String.format("starting container %s", containerResponse.getId())); LOG.debug(String.format("starting container %s", containerResponse.getId()));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment