Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reinstate retries for image pulls #1712

Merged
merged 5 commits into from Aug 22, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 20 additions & 13 deletions core/src/main/java/org/testcontainers/images/RemoteDockerImage.java
Expand Up @@ -29,6 +29,7 @@ public class RemoteDockerImage extends LazyFuture<String> {
*/
@Deprecated
public static final Set<DockerImageName> AVAILABLE_IMAGE_NAME_CACHE = new HashSet<>();
private static final int PULL_ATTEMPTS = 3;

private DockerImageName imageName;

Expand Down Expand Up @@ -73,23 +74,29 @@ protected final String resolve() {
return imageName.toString();
}

// The image is not available locally - pull it
logger.info("Pulling docker image: {}. Please be patient; this may take some time but only needs to be done once.", imageName);

// The image is not available locally - pull it
try {
final PullImageResultCallback callback = new TimeLimitedLoggedPullImageResultCallback(logger);
dockerClient
.pullImageCmd(imageName.getUnversionedPart())
.withTag(imageName.getVersionPart())
.exec(callback);
callback.awaitCompletion();
AVAILABLE_IMAGE_NAME_CACHE.add(imageName);
} catch (Exception e) {
logger.error("Failed to pull image: {}. Please check output of `docker pull {}`", imageName, imageName);
throw new ContainerFetchException("Failed to pull image: " + imageName, e);
Exception lastFailure = null;
for (int i = 1; i <= PULL_ATTEMPTS; i++) {
try {
final PullImageResultCallback callback = new TimeLimitedLoggedPullImageResultCallback(logger);
dockerClient
.pullImageCmd(imageName.getUnversionedPart())
.withTag(imageName.getVersionPart())
.exec(callback);
callback.awaitCompletion();
AVAILABLE_IMAGE_NAME_CACHE.add(imageName);

return imageName.toString();
} catch (Exception e) {
logger.debug("Retrying pull for image: {}", imageName);
lastFailure = e;
}
}
logger.error("Failed to pull image: {}. Please check output of `docker pull {}`", imageName, imageName, lastFailure);

return imageName.toString();
throw new ContainerFetchException("Failed to pull image: " + imageName, lastFailure);
} catch (DockerClientException e) {
throw new ContainerFetchException("Failed to get Docker client for " + imageName, e);
}
Expand Down