mirror of https://github.com/OpenVidu/openvidu.git
Remove sha256 method and add getImageId and getRunningContainers returns container ids if an image id is passed
parent
08647869d3
commit
496c1cff92
|
@ -27,19 +27,13 @@ import java.util.concurrent.TimeUnit;
|
||||||
import javax.ws.rs.ProcessingException;
|
import javax.ws.rs.ProcessingException;
|
||||||
|
|
||||||
import com.github.dockerjava.api.DockerClient;
|
import com.github.dockerjava.api.DockerClient;
|
||||||
import com.github.dockerjava.api.command.CreateContainerCmd;
|
import com.github.dockerjava.api.async.ResultCallback;
|
||||||
import com.github.dockerjava.api.command.CreateContainerResponse;
|
import com.github.dockerjava.api.command.*;
|
||||||
import com.github.dockerjava.api.command.ExecCreateCmdResponse;
|
|
||||||
import com.github.dockerjava.api.command.InspectContainerResponse;
|
|
||||||
import com.github.dockerjava.api.exception.ConflictException;
|
import com.github.dockerjava.api.exception.ConflictException;
|
||||||
import com.github.dockerjava.api.exception.DockerClientException;
|
import com.github.dockerjava.api.exception.DockerClientException;
|
||||||
import com.github.dockerjava.api.exception.InternalServerErrorException;
|
import com.github.dockerjava.api.exception.InternalServerErrorException;
|
||||||
import com.github.dockerjava.api.exception.NotFoundException;
|
import com.github.dockerjava.api.exception.NotFoundException;
|
||||||
import com.github.dockerjava.api.model.Bind;
|
import com.github.dockerjava.api.model.*;
|
||||||
import com.github.dockerjava.api.model.Container;
|
|
||||||
import com.github.dockerjava.api.model.Frame;
|
|
||||||
import com.github.dockerjava.api.model.HostConfig;
|
|
||||||
import com.github.dockerjava.api.model.Volume;
|
|
||||||
import com.github.dockerjava.core.DefaultDockerClientConfig;
|
import com.github.dockerjava.core.DefaultDockerClientConfig;
|
||||||
import com.github.dockerjava.core.DockerClientBuilder;
|
import com.github.dockerjava.core.DockerClientBuilder;
|
||||||
import com.github.dockerjava.core.DockerClientConfig;
|
import com.github.dockerjava.core.DockerClientConfig;
|
||||||
|
@ -215,15 +209,6 @@ public class DockerManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getImageSha256(String image) {
|
|
||||||
try {
|
|
||||||
return CommandExecutor.execCommand(5000, "/bin/sh", "-c", "docker inspect " + image + " -f \"{{ .Id }}\"");
|
|
||||||
} catch (IOException | InterruptedException e) {
|
|
||||||
log.error(e.getMessage());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getRunningContainers(String fullImageName) {
|
public List<String> getRunningContainers(String fullImageName) {
|
||||||
List<String> containerIds = new ArrayList<>();
|
List<String> containerIds = new ArrayList<>();
|
||||||
List<Container> existingContainers = this.dockerClient.listContainersCmd().exec();
|
List<Container> existingContainers = this.dockerClient.listContainersCmd().exec();
|
||||||
|
@ -231,10 +216,18 @@ public class DockerManager {
|
||||||
if (container.getImage().startsWith(fullImageName)) {
|
if (container.getImage().startsWith(fullImageName)) {
|
||||||
containerIds.add(container.getId());
|
containerIds.add(container.getId());
|
||||||
}
|
}
|
||||||
|
if (container.getImageId().startsWith(fullImageName)) {
|
||||||
|
containerIds.add(container.getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return containerIds;
|
return containerIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getImageId(String fullImageName) {
|
||||||
|
InspectImageResponse imageResponse = this.dockerClient.inspectImageCmd(fullImageName).exec();
|
||||||
|
return imageResponse.getId();
|
||||||
|
}
|
||||||
|
|
||||||
public Map<String, String> getLabels(String containerId) {
|
public Map<String, String> getLabels(String containerId) {
|
||||||
InspectContainerResponse containerInfo = dockerClient.inspectContainerCmd(containerId).exec();
|
InspectContainerResponse containerInfo = dockerClient.inspectContainerCmd(containerId).exec();
|
||||||
return containerInfo.getConfig().getLabels();
|
return containerInfo.getConfig().getLabels();
|
||||||
|
|
Loading…
Reference in New Issue