Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private TimeLimitedLoggedPullImageResultCallback pullImage(PullImageCmd pullImag
throws InterruptedException {
try {
return pullImageCmd.exec(new TimeLimitedLoggedPullImageResultCallback(logger)).awaitCompletion();
} catch (DockerClientException | NotFoundException e) {
} catch (DockerClientException | NotFoundException | InternalServerErrorException e) {
// Try to fallback to x86
return pullImageCmd
.withPlatform("linux/amd64")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package org.testcontainers.images;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.command.PullImageCmd;
import com.github.dockerjava.api.exception.InternalServerErrorException;
import org.testcontainers.utility.ImageNameSubstitutor;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.testcontainers.utility.Base58;
Expand Down Expand Up @@ -76,4 +84,30 @@ protected String resolve() {
imageNameFuture.get();
assertThat(remoteDockerImage.toString()).contains("imageName=" + imageName);
}
@Test
void fallsBackToAmd64WhenPullFailsWithInternalServerError() throws Exception {
DockerImageName imageName = DockerImageName.parse("test/image:latest");
DockerClient dockerClient = mock(DockerClient.class);
PullImageCmd pullImageCmd = mock(PullImageCmd.class);

when(dockerClient.pullImageCmd("test/image")).thenReturn(pullImageCmd);
when(pullImageCmd.withTag("latest")).thenReturn(pullImageCmd);
when(pullImageCmd.withPlatform("linux/amd64")).thenReturn(pullImageCmd);

when(pullImageCmd.exec(any(TimeLimitedLoggedPullImageResultCallback.class)))
.thenThrow(new InternalServerErrorException("no image found in manifest list for architecture \"arm64\""))
.thenReturn(mock(TimeLimitedLoggedPullImageResultCallback.class));

RemoteDockerImage remoteDockerImage = new RemoteDockerImage(
CompletableFuture.completedFuture(imageName),
__ -> true,
ImageNameSubstitutor.noop(),
dockerClient
);

remoteDockerImage.resolve();

verify(pullImageCmd).withPlatform("linux/amd64");
}

}