mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
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:<port> and the push ended with "dial tcp [::1]:<port>: 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.
This commit is contained in:
1 parent
a22e65f993
commit
f798fdc662
1 file changed
+31
-7
+31
-7
@@ -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<PushResponseItem>())
|
||||
AtomicReference<String> pushError = new AtomicReference<>();
|
||||
boolean finished = dockerClient.pushImageCmd(repository).withTag("latest")
|
||||
.exec(new ResultCallback.Adapter<PushResponseItem>() {
|
||||
@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() {
|
||||
|
||||
Reference in new issue
Block a user