openvidu-test-e2e: get container IP using DockerClient

pull/780/head
pabloFuente 2023-02-21 14:53:35 +01:00
parent f7f2708b1f
commit 1111c62bfe
2 changed files with 12 additions and 8 deletions

View File

@ -22,7 +22,7 @@ public class MediaNodeDockerUtils {
dockerClient.removeContainerCmd(containerId).withForce(true).exec(); dockerClient.removeContainerCmd(containerId).withForce(true).exec();
} }
public static String getMediaNodeIp(String containerId) { public static String getContainerIp(String containerId) {
DockerClient dockerClient = getDockerClient(); DockerClient dockerClient = getDockerClient();
return dockerClient.inspectContainerCmd(containerId).exec().getNetworkSettings().getNetworks().get("bridge") return dockerClient.inspectContainerCmd(containerId).exec().getNetworkSettings().getNetworks().get("bridge")
.getIpAddress(); .getIpAddress();

View File

@ -864,8 +864,9 @@ public class OpenViduTestE2e {
* https://github.com/tiangolo/nginx-rtmp-docker * https://github.com/tiangolo/nginx-rtmp-docker
* *
* @return The IP address of the Docker container * @return The IP address of the Docker container
* @throws InterruptedException
*/ */
protected static String startRtmpServer() throws IOException, TimeoutException { protected static String startRtmpServer() throws IOException, TimeoutException, InterruptedException {
File file = writeRtmpServerConfigInFile(); File file = writeRtmpServerConfigInFile();
String dockerRunCommand = "docker run -d --name broadcast-nginx -p 1935:1935 -v " + file.getAbsolutePath() String dockerRunCommand = "docker run -d --name broadcast-nginx -p 1935:1935 -v " + file.getAbsolutePath()
+ ":/etc/nginx/nginx.conf tiangolo/nginx-rtmp"; + ":/etc/nginx/nginx.conf tiangolo/nginx-rtmp";
@ -879,16 +880,19 @@ public class OpenViduTestE2e {
} }
protected static String waitForContainerIpAddress(String containerNameOrId, int secondsTimeout) protected static String waitForContainerIpAddress(String containerNameOrId, int secondsTimeout)
throws TimeoutException, UnknownHostException { throws TimeoutException, UnknownHostException, InterruptedException {
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
long maxTime = currentTime + (secondsTimeout * 1000); long maxTime = currentTime + (secondsTimeout * 1000);
InetAddressValidator validator = InetAddressValidator.getInstance();
while (System.currentTimeMillis() < maxTime) { while (System.currentTimeMillis() < maxTime) {
String ip = commandLine.executeCommand( try {
"docker container inspect -f '{{ .NetworkSettings.IPAddress }}' " + containerNameOrId, 3); String ip = MediaNodeDockerUtils.getContainerIp(containerNameOrId);
InetAddressValidator validator = InetAddressValidator.getInstance(); if (validator.isValid(ip)) {
if (validator.isValid(ip)) { return ip;
return ip; }
} catch (Exception e) {
} }
Thread.sleep(50);
} }
throw new TimeoutException(); throw new TimeoutException();
} }