From f798fdc6623276ca94e1788cf1d67223fabaae90 Mon Sep 17 00:00:00 2001 From: Kenshin Okinaka Date: Fri, 2 Oct 2026 02:15:16 +0900 Subject: [PATCH] test(ecs): give the image-pull test's registry a port the Docker daemon can reach (#4824) The registry was published on an ephemeral host port. Docker Desktop allocates such a port on the host side only, so the daemon, which runs inside the VM, could not reach localhost: and the push ended with "dial tcp [::1]:: i/o timeout". push() dropped that error, and the test failed later on an unrelated 404 from the manifest HEAD. The registry now binds a free loopback port the test chooses, and push() fails with the daemon's error when a push does not succeed. --- .../EcsImagePullDockerIntegrationTest.java | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/test/java/io/github/hectorvent/floci/services/ecs/EcsImagePullDockerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ecs/EcsImagePullDockerIntegrationTest.java index cbc2253f40..de354a1e8b 100644 --- a/src/test/java/io/github/hectorvent/floci/services/ecs/EcsImagePullDockerIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/ecs/EcsImagePullDockerIntegrationTest.java @@ -25,6 +25,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.IOException; +import java.net.InetAddress; +import java.net.ServerSocket; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; @@ -34,9 +36,12 @@ import java.util.List; import java.util.Map; import java.util.UUID; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * The scenario from a CI rebuild: a service's image tag is moved in its registry while the Docker @@ -170,19 +175,18 @@ class EcsImagePullDockerIntegrationTest { } } - private String startRegistry() throws InterruptedException { + private String startRegistry() throws InterruptedException, IOException { pull(TestImages.REGISTRY); ExposedPort registryPort = ExposedPort.tcp(5000); + int hostPort = freeLoopbackPort(); registryContainerId = dockerClient.createContainerCmd(TestImages.REGISTRY) .withExposedPorts(registryPort) .withHostConfig(HostConfig.newHostConfig().withPortBindings(new PortBinding( - Ports.Binding.bindIp("127.0.0.1"), registryPort))) + Ports.Binding.bindIpAndPort("127.0.0.1", hostPort), registryPort))) .exec() .getId(); dockerClient.startContainerCmd(registryContainerId).exec(); - Ports.Binding binding = dockerClient.inspectContainerCmd(registryContainerId).exec() - .getNetworkSettings().getPorts().getBindings().get(registryPort)[0]; - String registry = "localhost:" + binding.getHostPortSpec(); + String registry = "localhost:" + hostPort; HttpClient http = HttpClient.newHttpClient(); for (int attempt = 0; attempt < 50; attempt++) { try { @@ -217,9 +221,29 @@ class EcsImagePullDockerIntegrationTest { } private void push(String repository) throws InterruptedException { - dockerClient.pushImageCmd(repository).withTag("latest") - .exec(new ResultCallback.Adapter()) + AtomicReference pushError = new AtomicReference<>(); + boolean finished = dockerClient.pushImageCmd(repository).withTag("latest") + .exec(new ResultCallback.Adapter() { + @Override + public void onNext(PushResponseItem item) { + if (item.isErrorIndicated()) { + pushError.set(String.valueOf(item.getErrorDetail())); + } + } + }) .awaitCompletion(2, TimeUnit.MINUTES); + assertTrue(finished, "the push to " + repository + " must finish"); + assertNull(pushError.get(), "the push to " + repository + " must succeed"); + } + + /** + * A port named in the binding, not one the daemon picks: Docker Desktop allocates an unnamed + * port on the host side only, where the daemon that pushes and pulls cannot reach it. + */ + private static int freeLoopbackPort() throws IOException { + try (ServerSocket socket = new ServerSocket(0, 1, InetAddress.getByName("127.0.0.1"))) { + return socket.getLocalPort(); + } } private boolean isDockerAvailable() {