Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Dockerized Testing Toolkit
DTT Backend
Commits
1a6c6d0a
Verified
Commit
1a6c6d0a
authored
Jan 09, 2021
by
Lukas Wiest
🚂
Browse files
refactor(util/docker): add try-catch wrappers around image pull
parent
26b5c569
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/de/hftstuttgart/utils/DockerUtil.java
View file @
1a6c6d0a
...
...
@@ -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
()));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment