@Nonnull private DockerClient openDockerClient() throws MojoExecutionException { final RegistryAuthSupplier authSupplier = createRegistryAuthSupplier(); try { return DefaultDockerClient.fromEnv() .readTimeoutMillis(readTimeoutMillis) .connectTimeoutMillis(connectTimeoutMillis) .registryAuthSupplier(authSupplier) .useProxy(useProxy) .build(); } catch (DockerCertificateException e) { throw new MojoExecutionException("Could not load Docker certificates", e); } }
LocalDockerRunner(ScheduledExecutorService executorService, StateManager stateManager) { LOG.info("creating a client"); try { client = DefaultDockerClient.fromEnv().build(); } catch (DockerCertificateException e) { throw new RuntimeException(e); } executorService.scheduleAtFixedRate(this::checkStatuses, 1, CHECK_INTERVAL, TimeUnit.SECONDS); this.stateManager = Objects.requireNonNull(stateManager); }
protected DockerClient createDockerClient() { try { return DefaultDockerClient.fromEnv().build(); } catch (DockerCertificateException e) { throw new IllegalStateException("Could not create docker client from environement", e); } }
public static DockerClient initDockerClient() { DockerClient docker; try { docker = DefaultDockerClient.fromEnv().build(); } catch (DockerCertificateException e) { throw new RuntimeException("Error while initializing docker client."); } return docker; }
public Docker() throws DockerCertificateException { this.client = DefaultDockerClient.fromEnv().build(); }
private DockerInstance(String imageName, String[] commands, String containerName, HostConfig hostConfig, String[] env, ImageStrategy imageStrategy, String[] usedContainerPorts) { this.imageName = imageName; this.commands = commands; this.containerName = containerName; this.hostConfig = hostConfig; this.env = env; this.usedContainerPorts = usedContainerPorts; try { dockerClient = DefaultDockerClient.fromEnv().build(); } catch (DockerCertificateException e) { throw new RuntimeException(e); } this.imageStrategy = imageStrategy; }
public DockerTaskRunner() throws Exception { this.docker = DefaultDockerClient.fromEnv().build(); this.client = new Docker(this.docker); // Check swarm status // try { // this.swarm = this.docker.inspectSwarm(); // if (this.swarm != null && this.swarm.id() != null) { // this.isSwarm = true; // } // } catch (Exception e) { // // OK, It will show that this node isn't a docker swarm node or manager // } }
private void connectToDocker() { try { LOG.debug("Connecting to Docker"); dockerClient = DefaultDockerClient.fromEnv().build(); dockerClient.ping(); LOG.debug("Connection to Docker established"); } catch (DockerException | DockerCertificateException | InterruptedException e) { throw new EnvironmentBuilderException("Unable to connect to Docker", e); } }
protected static DockerClient createDockerClient(DockerClientConfig config) { final RegistryAuth registryAuth = getRegistryAuth(config); try { if (registryAuth != null) { return DefaultDockerClient.fromEnv().registryAuth(registryAuth).build(); } else { return DefaultDockerClient.fromEnv().build(); } } catch (DockerCertificateException e) { throw new RuntimeException(e); } }
private DockerClient connectToDocker() { try { LOG.debug("Connecting to Docker"); DockerClient docker = DefaultDockerClient.fromEnv().build(); docker.ping(); LOG.debug("Connection to Docker established"); return docker; } catch (DockerException | DockerCertificateException | InterruptedException e) { throw new EnvironmentBuilderException("Unable to connect to Docker", e); } }
private static DefaultDockerClient givenDockerClient() throws DockerCertificateException { return DefaultDockerClient.fromEnv().build(); }
public static DockerClient buildClient(URI dockerHost, Path certificatesPath) { try { if (dockerHost == null) { logger.info("Configuring docker host from environment"); return DefaultDockerClient.fromEnv().build(); } else { logger.info("Configuring docker host from configuration"); DefaultDockerClient.Builder builder = DefaultDockerClient.builder().uri(dockerHost); if (certificatesPath != null) { builder.dockerCertificates(new DockerCertificates(certificatesPath)); } return builder.build(); } } catch (DockerCertificateException e) { logger.error("Could not read certificates", e); throw new IllegalArgumentException("Could not read certificates: " + e.getMessage()); } }
protected DockerClient createDockerClient() throws DockerClientException { try { return DefaultDockerClient.fromEnv() // .connectTimeoutMillis(5000) // .readTimeoutMillis(20000) // .build(); } catch (final IllegalStateException | IllegalArgumentException | DockerCertificateException e) { throw new DockerClientException("Unable to create docker client", e); } }
DockerRule(DockerRuleBuilder builder) { this.builder = builder; this.imageNameWithTag = imageNameWithTag(builder.imageName()); try { dockerClient = DefaultDockerClient.fromEnv().build(); log.debug("server.info: {}", dockerClient.info()); log.debug("server.version: {}", dockerClient.version()); if (builder.imageAlwaysPull() || ! imageAvaliable(dockerClient, imageNameWithTag)) { dockerClient.pull(imageNameWithTag); } } catch (ImageNotFoundException e) { throw new ImagePullException(String.format("Image '%s' not found", imageNameWithTag), e); } catch (DockerCertificateException | DockerException | InterruptedException e) { throw new IllegalStateException(e); } }
@Before public void setUp() throws Exception { docker = DefaultDockerClient.fromEnv().build(); }
public DockerService(Config config, InternalPreferences preferences) { this.config = config; this.preferences = preferences; dockerDefaultSocket = getConfig().getDockerDefaultSocket(); dockerWaitTimeoutSec = getConfig().getDockerWaitTimeoutSec(); dockerPollTimeMs = getConfig().getDockerPollTimeMs(); String dockerServerUrl = getConfig().getDockerServerUrl(); Builder dockerClientBuilder = null; if (dockerServerUrl.isEmpty()) { try { dockerClientBuilder = DefaultDockerClient.fromEnv(); } catch (DockerCertificateException e) { throw new SeleniumJupiterException(e); } } else { log.debug("Using Docker server URL {}", dockerServerUrl); dockerClientBuilder = DefaultDockerClient.builder() .uri(dockerServerUrl); } dockerClient = dockerClientBuilder.build(); }
@Override public Statement apply(Statement statement, Description description) { try { DefaultDockerClient client = DefaultDockerClient.fromEnv() .connectTimeoutMillis(5000L) .readTimeoutMillis(20000L) .registryAuthSupplier(new FixedRegistryAuthSupplier()) .build(); client.ping(); client.pull(IMAGE); client.close(); } catch (Throwable t) { Assume.assumeNoException(t); } return wrappedRule.apply(statement, description); }
@Override public DefaultDockerClient.Builder configure(TestContext testContext, VirtualResource virtualResource, PropertiesReader configReader) { try { DefaultDockerClient.Builder builder = DefaultDockerClient.fromEnv(); PropertiesReader reader = configReader; if (reader.isEmpty()) { reader = testContext.getPropertiesReader(DEFAULT_CONFIG_KEY); } if (!reader.isEmpty()) { RegistryAuth registryAuth = RegistryAuth.builder() .serverAddress(reader.getProperty("uri")) .email(reader.getProperty("email")) .username(reader.getProperty("username")) .password(reader.getProperty("password")) .build(); RegistryAuthSupplier dockerHubAuthSupplier = new DockerHubRegistryAuthSupplier(registryAuth); //TODO: explore making these configuration configurable via .testify.yml file builder.registryAuthSupplier(dockerHubAuthSupplier) .connectTimeoutMillis(10000) .connectionPoolSize(16); } return builder; } catch (DockerCertificateException e) { throw ExceptionUtil.INSTANCE.propagate(e); } }