Search in sources :

Example 1 with DockerAccess

use of io.fabric8.maven.docker.access.DockerAccess 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)

Example 2 with DockerAccess

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

the class AbstractDockerMojo method execute.

/**
 * Entry point for this plugin. It will set up the helper class and then calls
 * {@link #executeInternal(ServiceHub)}
 * which must be implemented by subclass.
 *
 * @throws MojoExecutionException
 * @throws MojoFailureException
 */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (!skip) {
        log = new AnsiLogger(getLog(), useColor, verbose, !settings.getInteractiveMode(), getLogPrefix());
        authConfigFactory.setLog(log);
        LogOutputSpecFactory logSpecFactory = new LogOutputSpecFactory(useColor, logStdout, logDate);
        ConfigHelper.validateExternalPropertyActivation(project, images);
        // The 'real' images configuration to use (configured images + externally resolved images)
        this.minimalApiVersion = initImageConfiguration(getBuildTimestamp());
        DockerAccess access = null;
        try {
            if (isDockerAccessRequired()) {
                DockerAccessFactory.DockerAccessContext dockerAccessContext = getDockerAccessContext();
                access = dockerAccessFactory.createDockerAccess(dockerAccessContext);
            }
            ServiceHub serviceHub = serviceHubFactory.createServiceHub(project, session, access, log, logSpecFactory);
            executeInternal(serviceHub);
        } catch (DockerAccessException | ExecException exp) {
            logException(exp);
            throw new MojoExecutionException(log.errorMessage(exp.getMessage()), exp);
        } catch (MojoExecutionException exp) {
            logException(exp);
            throw exp;
        } finally {
            if (access != null) {
                access.shutdown();
            }
        }
    }
}
Also used : DockerAccess(io.fabric8.maven.docker.access.DockerAccess) LogOutputSpecFactory(io.fabric8.maven.docker.log.LogOutputSpecFactory) ServiceHub(io.fabric8.maven.docker.service.ServiceHub) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) ExecException(io.fabric8.maven.docker.access.ExecException) AnsiLogger(io.fabric8.maven.docker.util.AnsiLogger) DockerAccessFactory(io.fabric8.maven.docker.service.DockerAccessFactory)

Example 3 with DockerAccess

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

the class WaitService method prepareWaitCheckers.

private List<WaitChecker> prepareWaitCheckers(ImageConfiguration imageConfig, Properties projectProperties, String containerId) throws MojoExecutionException {
    WaitConfiguration wait = getWaitConfiguration(imageConfig);
    if (wait == null) {
        return Collections.emptyList();
    }
    List<WaitChecker> checkers = new ArrayList<>();
    if (wait.getUrl() != null) {
        checkers.add(getUrlWaitChecker(imageConfig.getDescription(), projectProperties, wait));
    }
    if (wait.getLog() != null) {
        log.debug("LogWaitChecker: Waiting on %s", wait.getLog());
        checkers.add(new LogWaitChecker(wait.getLog(), dockerAccess, containerId, log));
    }
    if (wait.getTcp() != null) {
        try {
            Container container = queryService.getMandatoryContainer(containerId);
            checkers.add(getTcpWaitChecker(container, imageConfig.getDescription(), projectProperties, wait.getTcp()));
        } catch (DockerAccessException e) {
            throw new MojoExecutionException("Unable to access container.", e);
        }
    }
    if (wait.getHealthy() == Boolean.TRUE) {
        checkers.add(new HealthCheckChecker(dockerAccess, containerId, imageConfig.getDescription(), log));
    }
    if (wait.getExit() != null) {
        checkers.add(new ExitCodeChecker(wait.getExit(), queryService, containerId));
    }
    return checkers;
}
Also used : WaitConfiguration(io.fabric8.maven.docker.config.WaitConfiguration) Container(io.fabric8.maven.docker.model.Container) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException)

Aggregations

MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 DockerAccess (io.fabric8.maven.docker.access.DockerAccess)2 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)2 DockerConnectionDetector (io.fabric8.maven.docker.access.DockerConnectionDetector)1 ExecException (io.fabric8.maven.docker.access.ExecException)1 DockerAccessWithHcClient (io.fabric8.maven.docker.access.hc.DockerAccessWithHcClient)1 WaitConfiguration (io.fabric8.maven.docker.config.WaitConfiguration)1 LogOutputSpecFactory (io.fabric8.maven.docker.log.LogOutputSpecFactory)1 Container (io.fabric8.maven.docker.model.Container)1 DockerAccessFactory (io.fabric8.maven.docker.service.DockerAccessFactory)1 ServiceHub (io.fabric8.maven.docker.service.ServiceHub)1 AnsiLogger (io.fabric8.maven.docker.util.AnsiLogger)1 IOException (java.io.IOException)1