Search in sources :

Example 1 with ApacheDockerHttpClient

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();
}
Also used : Builder(com.github.dockerjava.httpclient5.ApacheDockerHttpClient.Builder) DockerBuilder(io.github.bonigarcia.wdm.docker.DockerContainer.DockerBuilder) DockerClientBuilder(com.github.dockerjava.core.DockerClientBuilder) ApacheDockerHttpClient(com.github.dockerjava.httpclient5.ApacheDockerHttpClient) DefaultDockerClientConfig(com.github.dockerjava.core.DefaultDockerClientConfig) DockerClientConfig(com.github.dockerjava.core.DockerClientConfig) DefaultDockerClientConfig(com.github.dockerjava.core.DefaultDockerClientConfig)

Example 2 with ApacheDockerHttpClient

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();
}
Also used : Path(java.nio.file.Path) DockerClientBuilder(com.github.dockerjava.core.DockerClientBuilder) Builder(com.github.dockerjava.httpclient5.ApacheDockerHttpClient.Builder) ApacheDockerHttpClient(com.github.dockerjava.httpclient5.ApacheDockerHttpClient) DefaultDockerClientConfig(com.github.dockerjava.core.DefaultDockerClientConfig) DockerClientConfig(com.github.dockerjava.core.DockerClientConfig) DefaultDockerClientConfig(com.github.dockerjava.core.DefaultDockerClientConfig)

Example 3 with ApacheDockerHttpClient

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);
}
Also used : ApacheDockerHttpClient(com.github.dockerjava.httpclient5.ApacheDockerHttpClient) DockerClientConfig(com.github.dockerjava.core.DockerClientConfig) DefaultDockerClientConfig(com.github.dockerjava.core.DefaultDockerClientConfig)

Aggregations

DefaultDockerClientConfig (com.github.dockerjava.core.DefaultDockerClientConfig)3 DockerClientConfig (com.github.dockerjava.core.DockerClientConfig)3 ApacheDockerHttpClient (com.github.dockerjava.httpclient5.ApacheDockerHttpClient)3 DockerClientBuilder (com.github.dockerjava.core.DockerClientBuilder)2 Builder (com.github.dockerjava.httpclient5.ApacheDockerHttpClient.Builder)2 DockerBuilder (io.github.bonigarcia.wdm.docker.DockerContainer.DockerBuilder)1 Path (java.nio.file.Path)1