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;
}
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");
}
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();
}
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;
}
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;
}
Aggregations