Skip to content

Commit

Permalink
Temporary workaround when image pulled but docker-java fails. (Kostya…
Browse files Browse the repository at this point in the history
…Sha#207)

* Temporary workaround when image pulled but docker-java fails.

* And swarm also

* Checkstyle
  • Loading branch information
KostyaSha authored Oct 22, 2017
1 parent 700bad4 commit f53ef6e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.github.kostyasha.yad.credentials.DockerRegistryAuthCredentials;
import com.github.kostyasha.yad_docker_java.com.github.dockerjava.api.DockerClient;
import com.github.kostyasha.yad_docker_java.com.github.dockerjava.api.command.PullImageCmd;
import com.github.kostyasha.yad_docker_java.com.github.dockerjava.api.exception.DockerClientException;
import com.github.kostyasha.yad_docker_java.com.github.dockerjava.api.exception.NotFoundException;
import com.github.kostyasha.yad_docker_java.com.github.dockerjava.api.model.Image;
import com.github.kostyasha.yad_docker_java.com.github.dockerjava.core.NameParser;
import com.github.kostyasha.yad_docker_java.org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -127,9 +129,23 @@ public void exec(@Nonnull final DockerClient client, @Nonnull final String image
}
}

pullImageCmd
.exec(new DockerPullImageListenerLogger(listener))
.awaitSuccess();
try {
pullImageCmd
.exec(new DockerPullImageListenerLogger(listener))
.awaitSuccess();
} catch (DockerClientException exception) {
String exMsg = exception.getMessage();
if (exMsg.contains("Could not pull image: Digest:") ||
exMsg.contains(": downloaded")) {
try {
client.inspectImageCmd(imageName).exec();
} catch (NotFoundException notFoundEx) {
throw exception;
}
} else {
throw exception;
}
}

long pullTime = System.currentTimeMillis() - startTime;
LOG.info("Finished pulling image '{}', took {} ms", imageName, pullTime);
Expand All @@ -155,11 +171,11 @@ protected boolean shouldPullImage(DockerClient client, String imageName) {
List<Image> images = client.listImagesCmd().exec();

boolean hasImage = images.stream().anyMatch(image ->
nonNull(image.getRepoTags()) &&
Arrays.stream(image.getRepoTags())
.anyMatch(repoTag ->
repoTag.contains(fullImageName) || repoTag.contains("docker.io/" + fullImageName)
)
nonNull(image.getRepoTags()) &&
Arrays.stream(image.getRepoTags())
.anyMatch(repoTag ->
repoTag.contains(fullImageName) || repoTag.contains("docker.io/" + fullImageName)
)
);

return hasImage ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{"docker.io/kostyasha/yet-another-docker-plugin:wget-master",
"kostyasha/yet-another-docker-plugin:wget-master", PULL_LATEST, false},
{"kostyasha/yet-another-docker-plugin:wget-master",
"kostyasha/yet-another-docker-plugin:wget-master", PULL_LATEST, false},
{"", "repo/name", PULL_LATEST, true},
{"repo/name:latest", "repo/name", PULL_LATEST, true},
{"", "repo/name:latest", PULL_LATEST, true},
Expand All @@ -48,6 +50,7 @@ public static Collection<Object[]> data() {
{"", "repo/name:1.0", PULL_ALWAYS, true},
{"repo/name:1.0", "repo/name:1.0", PULL_ALWAYS, true},


{"", "repo/name", PULL_NEVER, false},
{"repo/name:latest", "repo/name", PULL_NEVER, false},
{"", "repo/name:latest", PULL_NEVER, false},
Expand Down

0 comments on commit f53ef6e

Please sign in to comment.