Search in sources :

Example 1 with DockerHttpClient

use of com.github.dockerjava.transport.DockerHttpClient in project iexec-common by iExecBlockchainComputing.

the class DockerClientInstance method createClient.

/**
 * Docker client
 */
/**
 * Build a new docker client instance. If credentials are provided, an authentication
 * attempt is made to the specified registry.
 *
 * @param registryAddress
 * @param username
 * @param password
 * @return an authenticated docker client if credentials are provided
 * @throws IllegalArgumentException if registry address is blank
 * @throws DockerException if authentication fails
 */
private static DockerClient createClient(String registryAddress, String username, String password) throws DockerException, IllegalArgumentException {
    if (StringUtils.isBlank(registryAddress)) {
        throw new IllegalArgumentException("Registry address must not be blank");
    }
    boolean shouldAuthenticate = StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password);
    DefaultDockerClientConfig.Builder configBuilder = DefaultDockerClientConfig.createDefaultConfigBuilder().withDockerTlsVerify(false).withRegistryUrl(registryAddress);
    if (shouldAuthenticate) {
        configBuilder.withRegistryUsername(username).withRegistryPassword(password);
    }
    DefaultDockerClientConfig config = configBuilder.build();
    DockerHttpClient httpClient = new ApacheDockerHttpClient.Builder().dockerHost(config.getDockerHost()).sslConfig(config.getSSLConfig()).build();
    DockerClient dockerClient = DockerClientImpl.getInstance(config, httpClient);
    if (shouldAuthenticate) {
        dockerClient.authCmd().exec();
        log.info("Authenticated Docker client registry [registry:{}, username:{}]", registryAddress, username);
    }
    return dockerClient;
}
Also used : DockerClient(com.github.dockerjava.api.DockerClient) ApacheDockerHttpClient(com.github.dockerjava.httpclient5.ApacheDockerHttpClient) DefaultDockerClientConfig(com.github.dockerjava.core.DefaultDockerClientConfig) ApacheDockerHttpClient(com.github.dockerjava.httpclient5.ApacheDockerHttpClient) DockerHttpClient(com.github.dockerjava.transport.DockerHttpClient)

Example 2 with DockerHttpClient

use of com.github.dockerjava.transport.DockerHttpClient in project quorum-acceptance-tests by ConsenSys.

the class DockerInfrastructureService method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    DefaultDockerClientConfig.Builder configBuilder = DefaultDockerClientConfig.createDefaultConfigBuilder();
    if (StringUtils.isNotBlank(networkProperty().getDockerInfrastructure().getHost())) {
        configBuilder.withDockerHost(networkProperty().getDockerInfrastructure().getHost());
    }
    DefaultDockerClientConfig config = configBuilder.build();
    infraProperty = networkProperty().getDockerInfrastructure();
    DockerHttpClient httpClient = new ApacheDockerHttpClient.Builder().dockerHost(config.getDockerHost()).sslConfig(config.getSSLConfig()).build();
    dockerClient = DockerClientImpl.getInstance(config, httpClient);
    quorumDockerImageCatalog = ImmutableMap.<String, QuorumImageConfig>builder().put("develop", new QuorumImageConfig(Optional.ofNullable(infraProperty.getTargetQuorumImage()).orElse("quorumengineering/quorum:develop"), GethArgBuilder.newBuilder().allowInsecureUnlock(true))).put("latest", new QuorumImageConfig("quorumengineering/quorum:latest", GethArgBuilder.newBuilder().allowInsecureUnlock(true))).put("v2.5.0", new QuorumImageConfig("quorumengineering/quorum:2.5.0", GethArgBuilder.newBuilder())).put("21.1.0", new QuorumImageConfig("quorumengineering/quorum:21.1.0", GethArgBuilder.newBuilder().allowInsecureUnlock(true))).put("21.4.0", new QuorumImageConfig("quorumengineering/quorum:21.4.0", GethArgBuilder.newBuilder().allowInsecureUnlock(true))).put("21.10.0", new QuorumImageConfig("quorumengineering/quorum:21.10.0", GethArgBuilder.newBuilder().allowInsecureUnlock(true))).put("2.7.0", new QuorumImageConfig("quorumengineering/quorum:2.7.0", GethArgBuilder.newBuilder().allowInsecureUnlock(true))).build();
    tesseraDockerImageCatalog = ImmutableMap.of("develop", Optional.ofNullable(infraProperty.getTargetTesseraImage()).orElse("quorumengineering/tessera:develop"), "latest", "quorumengineering/tessera:latest", "0.10.5", "quorumengineering/tessera:0.10.5", "21.1.0", "quorumengineering/tessera:21.1.0", "21.10.0", "quorumengineering/tessera:21.10.0");
}
Also used : ApacheDockerHttpClient(com.github.dockerjava.httpclient5.ApacheDockerHttpClient) DefaultDockerClientConfig(com.github.dockerjava.core.DefaultDockerClientConfig) ApacheDockerHttpClient(com.github.dockerjava.httpclient5.ApacheDockerHttpClient) DockerHttpClient(com.github.dockerjava.transport.DockerHttpClient)

Example 3 with DockerHttpClient

use of com.github.dockerjava.transport.DockerHttpClient in project Jpom by dromara.

the class Test method beforeLocal.

// @Before
public void beforeLocal() {
    // 
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    Logger logger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
    logger.setLevel(Level.INFO);
    DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder().withDockerHost("tcp://127.0.0.1:2375").build();
    DockerHttpClient httpClient = new ApacheDockerHttpClient.Builder().dockerHost(config.getDockerHost()).sslConfig(config.getSSLConfig()).maxConnections(100).build();
    this.dockerClient = DockerClientImpl.getInstance(config, httpClient);
    dockerClient.pingCmd().exec();
}
Also used : InvocationBuilder(com.github.dockerjava.core.InvocationBuilder) Logger(ch.qos.logback.classic.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) DockerClientConfig(com.github.dockerjava.core.DockerClientConfig) DefaultDockerClientConfig(com.github.dockerjava.core.DefaultDockerClientConfig) ApacheDockerHttpClient(com.github.dockerjava.httpclient5.ApacheDockerHttpClient) DockerHttpClient(com.github.dockerjava.transport.DockerHttpClient)

Example 4 with DockerHttpClient

use of com.github.dockerjava.transport.DockerHttpClient in project Jpom by dromara.

the class TestSwarm method client.

private DockerClient client(String host) {
    DefaultDockerClientConfig.Builder builder = DefaultDockerClientConfig.createDefaultConfigBuilder().withDockerHost("tcp://" + host + ":2375");
    if (StrUtil.equals(host, nodeLt)) {
        builder.withDockerTlsVerify(true).withDockerCertPath("/Users/user/fsdownload/docker-ca");
    }
    DockerClientConfig config = builder.build();
    DockerHttpClient httpClient = new ApacheDockerHttpClient.Builder().dockerHost(config.getDockerHost()).sslConfig(config.getSSLConfig()).maxConnections(100).build();
    DockerClient dockerClient = DockerClientImpl.getInstance(config, httpClient);
    dockerClient.pingCmd().exec();
    return dockerClient;
}
Also used : DockerClient(com.github.dockerjava.api.DockerClient) DefaultDockerClientConfig(com.github.dockerjava.core.DefaultDockerClientConfig) DockerClientConfig(com.github.dockerjava.core.DockerClientConfig) DefaultDockerClientConfig(com.github.dockerjava.core.DefaultDockerClientConfig) ApacheDockerHttpClient(com.github.dockerjava.httpclient5.ApacheDockerHttpClient) DockerHttpClient(com.github.dockerjava.transport.DockerHttpClient)

Example 5 with DockerHttpClient

use of com.github.dockerjava.transport.DockerHttpClient in project Jpom by dromara.

the class DefaultDockerCheckPluginImpl method testLocal.

private String testLocal() {
    DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder().build();
    URI dockerHost = config.getDockerHost();
    String host = dockerHost.toString();
    DockerHttpClient httpClient = new ApacheDockerHttpClient.Builder().dockerHost(dockerHost).connectionTimeout(Duration.ofSeconds(3)).build();
    DockerClientImpl.getInstance(config, httpClient).pingCmd().exec();
    return host;
}
Also used : ApacheDockerHttpClient(com.github.dockerjava.httpclient5.ApacheDockerHttpClient) DockerClientConfig(com.github.dockerjava.core.DockerClientConfig) DefaultDockerClientConfig(com.github.dockerjava.core.DefaultDockerClientConfig) URI(java.net.URI) ApacheDockerHttpClient(com.github.dockerjava.httpclient5.ApacheDockerHttpClient) DockerHttpClient(com.github.dockerjava.transport.DockerHttpClient)

Aggregations

DefaultDockerClientConfig (com.github.dockerjava.core.DefaultDockerClientConfig)16 DockerHttpClient (com.github.dockerjava.transport.DockerHttpClient)16 ApacheDockerHttpClient (com.github.dockerjava.httpclient5.ApacheDockerHttpClient)15 DockerClientConfig (com.github.dockerjava.core.DockerClientConfig)13 DockerClient (com.github.dockerjava.api.DockerClient)6 Logger (ch.qos.logback.classic.Logger)4 LoggerContext (ch.qos.logback.classic.LoggerContext)4 InvocationBuilder (com.github.dockerjava.core.InvocationBuilder)2 IOException (java.io.IOException)2 Before (org.junit.Before)2 VersionCmd (com.github.dockerjava.api.command.VersionCmd)1 NotFoundException (com.github.dockerjava.api.exception.NotFoundException)1 Container (com.github.dockerjava.api.model.Container)1 Version (com.github.dockerjava.api.model.Version)1 DockerClientImpl (com.github.dockerjava.core.DockerClientImpl)1 ZerodepDockerHttpClient (com.github.dockerjava.zerodep.ZerodepDockerHttpClient)1 Consul (com.orbitz.consul.Consul)1 FrameworkInitialisation (dev.galasa.framework.FrameworkInitialisation)1 FrameworkException (dev.galasa.framework.spi.FrameworkException)1 IConfigurationPropertyStoreService (dev.galasa.framework.spi.IConfigurationPropertyStoreService)1