diff options
author | Georg Pfuetzenreuter | 2022-05-06 10:21:15 +0200 |
---|---|---|
committer | Georg Pfuetzenreuter | 2022-05-06 10:21:15 +0200 |
commit | 8b1d592143d088dd2202031fc3c579d1096eee81 (patch) | |
tree | 764ea3cedf6d7b26167c6db91fc9ea5b69f68748 /src/main | |
parent | 27c6fd588820c0c9fb56ba7487c64d90118f9fa9 (diff) | |
download | pubsh-web-8b1d592143d088dd2202031fc3c579d1096eee81.tar.gz pubsh-web-8b1d592143d088dd2202031fc3c579d1096eee81.tar.bz2 pubsh-web-8b1d592143d088dd2202031fc3c579d1096eee81.zip |
Init Docker API
Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/net/libertacasa/pubsh/web/Docker.java | 51 |
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; + } + +} |