Search in sources :

Example 1 with DockerCertificateException

use of com.spotify.docker.client.DockerCertificateException in project kie-wb-common by kiegroup.

the class DockerAccessInterfaceImpl method buildClient.

private DockerClient buildClient(final ProviderId providerId) throws DockerException, InterruptedException {
    DefaultDockerClient dockerClient;
    if (providerId.getId().equals("local")) {
        try {
            if (System.getProperty("os.name").toLowerCase().contains("mac")) {
                dockerClient = DefaultDockerClient.builder().uri(DefaultDockerClient.DEFAULT_UNIX_ENDPOINT).build();
                // This test the docker client connection to see if the client was built properly
                Info info = dockerClient.info();
                LOG.info("Connected to Docker Client Info: " + info);
                return dockerClient;
            }
            try {
                dockerClient = DefaultDockerClient.fromEnv().build();
                Info info = dockerClient.info();
                LOG.info("Connected to Docker Client Info: " + info);
                return dockerClient;
            } catch (DockerCertificateException ex) {
                throw new RuntimeException(ex);
            }
        } catch (DockerException | InterruptedException ex) {
            try {
                dockerClient = DefaultDockerClient.fromEnv().build();
                Info info = dockerClient.info();
                LOG.info("Connected to Docker Client Info: " + info);
                return dockerClient;
            } catch (DockerCertificateException e) {
                throw new RuntimeException(e);
            }
        }
    }
    throw new RuntimeException("Couldn't create Docker Client, for providerId = " + providerId.getId());
}
Also used : DockerException(com.spotify.docker.client.DockerException) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) DockerCertificateException(com.spotify.docker.client.DockerCertificateException) Info(com.spotify.docker.client.messages.Info)

Example 2 with DockerCertificateException

use of com.spotify.docker.client.DockerCertificateException in project docker-api-spring-boot by jliu666.

the class DockerClientAutoConfiguration method dockerClient.

@Bean
@ConditionalOnMissingBean(DockerClient.class)
public DockerClient dockerClient() {
    DefaultDockerClient.Builder builder = null;
    try {
        builder = DefaultDockerClient.fromEnv();
    } catch (DockerCertificateException e) {
        e.printStackTrace();
    }
    if (builder == null) {
        builder = DefaultDockerClient.builder();
    }
    if (!StringUtils.isEmpty(dockerClientProperties.getApiVersion())) {
        builder.apiVersion(dockerClientProperties.getApiVersion());
    }
    if (!StringUtils.isEmpty(dockerClientProperties.getDockerHost())) {
        builder.uri(dockerClientProperties.getDockerHost());
    }
    if (dockerClientProperties.getDockerTlsVerify() != null) {
        String scheme = builder.uri().getScheme();
        if (dockerClientProperties.getDockerTlsVerify() && "http".equals(scheme.toLowerCase())) {
            builder.uri(builder.uri().toString().replaceFirst("http", "https"));
        }
        if (!dockerClientProperties.getDockerTlsVerify() && "https".equals(scheme.toLowerCase())) {
            builder.uri(builder.uri().toString().replaceFirst("https", "http"));
        }
    }
    DockerCertificates certificates = getCertificates();
    if (null != certificates) {
        builder.dockerCertificates();
    } else {
        builder.dockerCertificates(certificates);
    }
    builder.authConfig(getAuthConfig());
    return builder.build();
}
Also used : DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) DockerCertificateException(com.spotify.docker.client.DockerCertificateException) DockerCertificates(com.spotify.docker.client.DockerCertificates) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

DefaultDockerClient (com.spotify.docker.client.DefaultDockerClient)2 DockerCertificateException (com.spotify.docker.client.DockerCertificateException)2 DockerCertificates (com.spotify.docker.client.DockerCertificates)1 DockerException (com.spotify.docker.client.DockerException)1 Info (com.spotify.docker.client.messages.Info)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1