summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/net/libertacasa/pubsh/web/Docker.java51
1 files changed, 51 insertions, 0 deletions
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<String> getImageChecksums() {
+ List<Image> imageQuery;
+ List<String> imageList;
+ imageQuery = dockerClient.listImagesCmd().exec();
+ imageList = imageQuery.stream().map(Image::getId).collect(Collectors.toList());
+ return imageList;
+ }
+
+ public static List<Image> getImages() {
+ List<Image> imageQuery;
+ imageQuery = dockerClient.listImagesCmd().exec();
+ return imageQuery;
+ }
+
+ public static List<com.github.dockerjava.api.model.Container> getContainers() {
+ List<com.github.dockerjava.api.model.Container> containerQuery;
+ containerQuery = dockerClient.listContainersCmd().withShowAll(true).exec();
+ return containerQuery;
+ }
+
+}