All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.testcontainers.dockerclient.EnvironmentAndSystemPropertyClientProviderStrategy Maven / Gradle / Ivy

There is a newer version: 1.20.1
Show newest version
package org.testcontainers.dockerclient;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.core.DockerClientConfig;

/**
 * Use environment variables and system properties (as supported by the underlying DockerClient DefaultConfigBuilder)
 * to try and locate a docker environment.
 */
public class EnvironmentAndSystemPropertyClientProviderStrategy extends DockerClientProviderStrategy {

    @Override
    public void test() throws InvalidConfigurationException {

        try {
            // Try using environment variables
            config = DockerClientConfig.createDefaultConfigBuilder().build();
            DockerClient client = getClientForConfig(config);

            ping(client, 1);
        } catch (Exception e) {
            throw new InvalidConfigurationException("ping failed");
        }

        LOGGER.info("Found docker client settings from environment");
        LOGGER.info("Docker host IP address is {}", DockerClientConfigUtils.getDockerHostIpAddress(config));
    }

    @Override
    public String getDescription() {
        return "Environment variables, system properties and defaults. Resolved: \n" + stringRepresentation(config);
    }

    private String stringRepresentation(DockerClientConfig config) {

        if (config == null) {
            return "";
        }

        return  "    dockerHost=" + config.getDockerHost() + "\n" +
                "    dockerCertPath='" + config.getDockerCertPath() + "'\n" +
                "    dockerTlsVerify='" + config.getDockerTlsVerify() + "'\n" +
                "    apiVersion='" + config.getApiVersion() + "'\n" +
                "    registryUrl='" + config.getRegistryUrl() + "'\n" +
                "    registryUsername='" + config.getRegistryUsername() + "'\n" +
                "    registryPassword='" + config.getRegistryPassword() + "'\n" +
                "    registryEmail='" + config.getRegistryEmail() + "'\n" +
                "    dockerConfig='" + config.getDockerConfig() + "'\n";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy