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;
import com.github.dockerjava.api.DockerClient;
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.HostConfig;
import com.github.dockerjava.core.DefaultDockerClientConfig;
......@@ -40,18 +41,33 @@ public class DockerUtil {
public int runContainer(String image, Bind... binds) throws InterruptedException, IOException
{
LOG.debug(String.format("pull image: %s", image));
dockerClient.pullImageCmd(image)
.start()
.awaitCompletion()
.close();
try {
dockerClient.pullImageCmd(image)
.start()
.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");
CreateContainerResponse containerResponse = dockerClient.createContainerCmd("testcontainer")
.withImage(image)
.withHostConfig(
HostConfig.newHostConfig()
.withBinds(binds))
.exec();
CreateContainerResponse containerResponse;
try {
containerResponse = dockerClient.createContainerCmd("testcontainer")
.withImage(image)
.withHostConfig(
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("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