Search in sources :

Example 11 with DockerAccessException

use of io.fabric8.maven.docker.access.DockerAccessException 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 12 with DockerAccessException

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

the class BuildMojo method executeInternal.

@Override
protected void executeInternal(ServiceHub hub) throws DockerAccessException, MojoExecutionException {
    if (skipBuild) {
        return;
    }
    List<ImageConfiguration> resolvedImages = getResolvedImages();
    if (resolvedImages.isEmpty()) {
        // No Configuration found, so build one up dynamically.
        if (imageName == null) {
            /*
                 * Image name defaults to:
                 *     `${project.groupId}/${project.artifactId}:${project.version}`
                 */
            imageName = project.getGroupId() + "/" + project.getArtifactId() + ":" + project.getVersion();
        }
        ImageConfiguration aDefaultImageConfig = ImageConfiguration.getDefaultImageConfiguration(imageName, project.getBasedir().getAbsolutePath());
        processImageConfig(hub, aDefaultImageConfig);
        return;
    } else {
        // Iterate over all the ImageConfigurations and process one by one
        for (ImageConfiguration imageConfig : resolvedImages) {
            processImageConfig(hub, imageConfig);
        }
    }
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration)

Example 13 with DockerAccessException

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

the class StopMojo method getNetworksToRemove.

private Set<Network> getNetworksToRemove(QueryService queryService, PomLabel pomLabel) throws DockerAccessException {
    if (!autoCreateCustomNetworks) {
        return Collections.emptySet();
    }
    Set<Network> customNetworks = new HashSet<>();
    Set<Network> networks = queryService.getNetworks();
    for (ImageConfiguration image : getResolvedImages()) {
        final NetworkConfig config = image.getRunConfiguration().getNetworkingConfig();
        if (config.isCustomNetwork()) {
            Network network = getNetworkByName(networks, config.getCustomNetwork());
            if (network != null) {
                customNetworks.add(network);
                for (Container container : getContainersToStop(queryService, image)) {
                    if (!shouldStopContainer(container, pomLabel, image)) {
                        // it's sill in use don't collect it
                        customNetworks.remove(network);
                    }
                }
            }
        }
    }
    return customNetworks;
}
Also used : Container(io.fabric8.maven.docker.model.Container) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) RunImageConfiguration(io.fabric8.maven.docker.config.RunImageConfiguration) Network(io.fabric8.maven.docker.model.Network) NetworkConfig(io.fabric8.maven.docker.config.NetworkConfig) HashSet(java.util.HashSet)

Example 14 with DockerAccessException

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

the class StopMojo method executeInternal.

@Override
protected void executeInternal(ServiceHub hub) throws MojoExecutionException, DockerAccessException, ExecException {
    QueryService queryService = hub.getQueryService();
    RunService runService = hub.getRunService();
    PomLabel pomLabel = getPomLabel();
    if (!keepRunning) {
        if (invokedTogetherWithDockerStart()) {
            runService.stopStartedContainers(keepContainer, removeVolumes, autoCreateCustomNetworks, pomLabel);
        } else {
            stopContainers(queryService, runService, pomLabel);
        }
    }
    // Switch off all logging
    LogDispatcher dispatcher = getLogDispatcher(hub);
    dispatcher.untrackAllContainerLogs();
}
Also used : RunService(io.fabric8.maven.docker.service.RunService) QueryService(io.fabric8.maven.docker.service.QueryService) LogDispatcher(io.fabric8.maven.docker.log.LogDispatcher) PomLabel(io.fabric8.maven.docker.util.PomLabel)

Example 15 with DockerAccessException

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

the class VolumeRemoveMojo method executeInternal.

@Override
protected void executeInternal(ServiceHub serviceHub) throws DockerAccessException, MojoExecutionException {
    VolumeService volService = serviceHub.getVolumeService();
    for (VolumeConfiguration volume : getVolumes()) {
        log.info("Removing volume %s", volume.getName());
        volService.removeVolume(volume.getName());
    }
}
Also used : VolumeService(io.fabric8.maven.docker.service.VolumeService) VolumeConfiguration(io.fabric8.maven.docker.config.VolumeConfiguration)

Aggregations

DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)11 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)7 Container (io.fabric8.maven.docker.model.Container)6 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)5 Arguments (io.fabric8.maven.docker.config.Arguments)4 MojoFailureException (org.apache.maven.plugin.MojoFailureException)4 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)3 PortMapping (io.fabric8.maven.docker.access.PortMapping)3 File (java.io.File)3 IOException (java.io.IOException)3 ContainerCreateConfig (io.fabric8.maven.docker.access.ContainerCreateConfig)2 ContainerHostConfig (io.fabric8.maven.docker.access.ContainerHostConfig)2 ExecException (io.fabric8.maven.docker.access.ExecException)2 HttpBodyAndStatus (io.fabric8.maven.docker.access.hc.ApacheHttpClientDelegate.HttpBodyAndStatus)2 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)2 VolumeConfiguration (io.fabric8.maven.docker.config.VolumeConfiguration)2 LogDispatcher (io.fabric8.maven.docker.log.LogDispatcher)2 ContainerDetails (io.fabric8.maven.docker.model.ContainerDetails)2 Network (io.fabric8.maven.docker.model.Network)2