Search in sources :

Example 1 with DockerConnectionDetector

use of io.fabric8.maven.docker.access.DockerConnectionDetector in project docker-maven-plugin by fabric8io.

the class DockerAccessFactory method createDockerAccess.

public DockerAccess createDockerAccess(DockerAccessContext dockerAccessContext) throws MojoExecutionException, MojoFailureException {
    try {
        DockerConnectionDetector dockerConnectionDetector = createDockerConnectionDetector(dockerAccessContext, dockerAccessContext.getLog());
        DockerConnectionDetector.ConnectionParameter connectionParam = dockerConnectionDetector.detectConnectionParameter(dockerAccessContext.getDockerHost(), dockerAccessContext.getCertPath());
        String version = dockerAccessContext.getMinimalApiVersion() != null ? dockerAccessContext.getMinimalApiVersion() : API_VERSION;
        DockerAccess access = new DockerAccessWithHcClient("v" + version, connectionParam.getUrl(), connectionParam.getCertPath(), dockerAccessContext.getMaxConnections(), dockerAccessContext.getLog());
        access.start();
        setDockerHostAddressProperty(dockerAccessContext, connectionParam.getUrl());
        String serverVersion = access.getServerApiVersion();
        if (!EnvUtil.greaterOrEqualsVersion(serverVersion, version)) {
            throw new MojoExecutionException(String.format("Server API version %s is smaller than required API version %s", serverVersion, version));
        }
        return access;
    } catch (IOException e) {
        throw new MojoExecutionException("Cannot create docker access object ", e);
    }
}
Also used : DockerAccess(io.fabric8.maven.docker.access.DockerAccess) DockerAccessWithHcClient(io.fabric8.maven.docker.access.hc.DockerAccessWithHcClient) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DockerConnectionDetector(io.fabric8.maven.docker.access.DockerConnectionDetector) IOException(java.io.IOException)

Aggregations

DockerAccess (io.fabric8.maven.docker.access.DockerAccess)1 DockerConnectionDetector (io.fabric8.maven.docker.access.DockerConnectionDetector)1 DockerAccessWithHcClient (io.fabric8.maven.docker.access.hc.DockerAccessWithHcClient)1 IOException (java.io.IOException)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1