use of com.github.dockerjava.httpclient5.ApacheDockerHttpClient in project webdrivermanager by bonigarcia.
the class DockerService method getDockerClient.
private DockerClient getDockerClient(String dockerHost) {
DefaultDockerClientConfig.Builder dockerClientConfigBuilder = DefaultDockerClientConfig.createDefaultConfigBuilder();
if (!isNullOrEmpty(dockerHost)) {
dockerClientConfigBuilder.withDockerHost(dockerHost);
}
DockerClientConfig dockerClientConfig = dockerClientConfigBuilder.build();
dockerHostUri = dockerClientConfig.getDockerHost();
ApacheDockerHttpClient dockerHttpClient = new Builder().dockerHost(dockerHostUri).build();
return DockerClientBuilder.getInstance(dockerClientConfig).withDockerHttpClient(dockerHttpClient).build();
}
use of com.github.dockerjava.httpclient5.ApacheDockerHttpClient in project kestra by kestra-io.
the class DockerScriptRunner method getDockerClient.
private DockerClient getDockerClient(AbstractBash abstractBash, RunContext runContext, Path workingDirectory) throws IllegalVariableEvaluationException, IOException {
DefaultDockerClientConfig.Builder dockerClientConfigBuilder = DefaultDockerClientConfig.createDefaultConfigBuilder();
if (abstractBash.getDockerOptions() != null) {
if (abstractBash.getDockerOptions().getDockerHost() != null) {
dockerClientConfigBuilder.withDockerHost(runContext.render(abstractBash.getDockerOptions().getDockerHost()));
}
if (abstractBash.getDockerOptions().getDockerConfig() != null) {
Path docker = Files.createTempDirectory(workingDirectory, "docker");
Path file = Files.createFile(docker.resolve("config.json"));
Files.write(file, runContext.render(abstractBash.getDockerOptions().getDockerConfig()).getBytes());
dockerClientConfigBuilder.withDockerConfig(docker.toFile().getAbsolutePath());
}
}
DockerClientConfig dockerClientConfig = dockerClientConfigBuilder.build();
ApacheDockerHttpClient dockerHttpClient = new Builder().dockerHost(dockerClientConfig.getDockerHost()).build();
return DockerClientBuilder.getInstance(dockerClientConfig).withDockerHttpClient(dockerHttpClient).build();
}
use of com.github.dockerjava.httpclient5.ApacheDockerHttpClient in project Jpom by dromara.
the class DockerUtil method build.
// /**
// * 构建 docker client 对象
// *
// * @param parameter 参数
// * @param maxConnections 连接数
// * @return DockerClient
// */
// public static DockerCmdExecFactory buildJersey(Map<String, Object> parameter, int maxConnections) {
// JerseyDockerCmdExecFactory jerseyDockerCmdExecFactory = new JerseyDockerCmdExecFactory();
// int timeout = Convert.toInt(parameter.get("timeout"), 0);
// if (timeout > 0) {
// jerseyDockerCmdExecFactory.withConnectTimeout((int) TimeUnit.SECONDS.toMillis(timeout));
// jerseyDockerCmdExecFactory.withReadTimeout((int) TimeUnit.SECONDS.toMillis(timeout));
// jerseyDockerCmdExecFactory.withConnectionRequestTimeout((int) TimeUnit.SECONDS.toMillis(timeout));
// }
//
// String host = (String) parameter.get("dockerHost");
// String apiVersion = (String) parameter.get("apiVersion");
// String dockerCertPath = (String) parameter.get("dockerCertPath");
// //
//
//
// JerseyDockerHttpClient.Builder builder =new JerseyDockerHttpClient.Builder();
//
//
// DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
// .withDockerTlsVerify(StrUtil.isNotEmpty(dockerCertPath))
// .withApiVersion(apiVersion)
// .withDockerCertPath(dockerCertPath)
// .withDockerHost(host).build();
//
// builder.dockerHost(config.getDockerHost());
// builder.sslConfig(config.getSSLConfig());
// JerseyDockerHttpClient dockerHttpClient = builder.build();
// // dockerHttpClient.execute()
//
//
// //
// jerseyDockerCmdExecFactory.withMaxTotalConnections(maxConnections);
// jerseyDockerCmdExecFactory.init(config);
// return jerseyDockerCmdExecFactory.getDockerCmdExecFactory();
//
// //
// // ApacheDockerHttpClient.Builder builder = new ApacheDockerHttpClient.Builder()
// // .dockerHost(config.getDockerHost())
// // .sslConfig(config.getSSLConfig())
// // .maxConnections(maxConnections);
// // //
// // int timeout = Convert.toInt(parameter.get("timeout"), 0);
// // if (timeout > 0) {
// // builder.connectionTimeout(Duration.ofSeconds(timeout));
// // builder.responseTimeout(Duration.ofSeconds(timeout));
// // }
// // ApacheDockerHttpClient httpClient = builder.build();
// // return DockerClientImpl.getInstance(config, httpClient);
// }
/**
* 构建 docker client 对象
*
* @param parameter 参数
* @param maxConnections 连接数
* @return DockerClient
*/
public static DockerClient build(Map<String, Object> parameter, int maxConnections) {
String host = (String) parameter.get("dockerHost");
String apiVersion = (String) parameter.get("apiVersion");
String dockerCertPath = (String) parameter.get("dockerCertPath");
//
DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder().withDockerTlsVerify(StrUtil.isNotEmpty(dockerCertPath)).withApiVersion(apiVersion).withDockerCertPath(dockerCertPath).withDockerHost(host).build();
//
ApacheDockerHttpClient.Builder builder = new ApacheDockerHttpClient.Builder().dockerHost(config.getDockerHost()).sslConfig(config.getSSLConfig()).maxConnections(maxConnections);
//
int timeout = Convert.toInt(parameter.get("timeout"), 0);
if (timeout > 0) {
builder.connectionTimeout(Duration.ofSeconds(timeout));
builder.responseTimeout(Duration.ofSeconds(timeout));
}
ApacheDockerHttpClient httpClient = builder.build();
return DockerClientImpl.getInstance(config, httpClient);
}
Aggregations