From 8b1d592143d088dd2202031fc3c579d1096eee81 Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Fri, 6 May 2022 10:21:15 +0200 Subject: Init Docker API Signed-off-by: Georg Pfuetzenreuter --- .../java/net/libertacasa/pubsh/web/Docker.java | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/main/java/net/libertacasa/pubsh/web/Docker.java (limited to 'src/main/java/net/libertacasa/pubsh/web') diff --git a/src/main/java/net/libertacasa/pubsh/web/Docker.java b/src/main/java/net/libertacasa/pubsh/web/Docker.java new file mode 100644 index 0000000..0c407f0 --- /dev/null +++ b/src/main/java/net/libertacasa/pubsh/web/Docker.java @@ -0,0 +1,51 @@ +package net.libertacasa.pubsh.web; + +import java.time.Duration; +import java.util.List; +import java.util.stream.Collectors; +import com.github.dockerjava.api.DockerClient; +import com.github.dockerjava.api.model.Image; +import com.github.dockerjava.core.DefaultDockerClientConfig; +import com.github.dockerjava.core.DockerClientConfig; +import com.github.dockerjava.core.DockerClientImpl; +import com.github.dockerjava.httpclient5.ApacheDockerHttpClient; +import com.github.dockerjava.transport.DockerHttpClient; + +public class Docker { + + static DockerClientConfig DockerConfig = DefaultDockerClientConfig.createDefaultConfigBuilder() + .withDockerHost("tcp://sweetsuse:2375") + .withDockerTlsVerify(false) + .build(); + + static DockerHttpClient httpClient = new ApacheDockerHttpClient.Builder() + .dockerHost(DockerConfig.getDockerHost()) + .sslConfig(DockerConfig.getSSLConfig()) + .maxConnections(100) + .connectionTimeout(Duration.ofSeconds(30)) + .responseTimeout(Duration.ofSeconds(45)) + .build(); + + static DockerClient dockerClient = DockerClientImpl.getInstance(DockerConfig, httpClient); + + public static List getImageChecksums() { + List imageQuery; + List imageList; + imageQuery = dockerClient.listImagesCmd().exec(); + imageList = imageQuery.stream().map(Image::getId).collect(Collectors.toList()); + return imageList; + } + + public static List getImages() { + List imageQuery; + imageQuery = dockerClient.listImagesCmd().exec(); + return imageQuery; + } + + public static List getContainers() { + List containerQuery; + containerQuery = dockerClient.listContainersCmd().withShowAll(true).exec(); + return containerQuery; + } + +} -- cgit v1.2.3