Search in sources :

Example 21 with DockerAccessException

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

Example 22 with DockerAccessException

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

the class WatchService method watch.

public synchronized void watch(WatchContext context, BuildService.BuildContext buildContext, List<ImageConfiguration> images) throws DockerAccessException, MojoExecutionException {
    // Important to be be a single threaded scheduler since watch jobs must run serialized
    ScheduledExecutorService executor = null;
    try {
        executor = Executors.newSingleThreadScheduledExecutor();
        for (StartOrderResolver.Resolvable resolvable : runService.getImagesConfigsInOrder(queryService, images)) {
            final ImageConfiguration imageConfig = (ImageConfiguration) resolvable;
            String imageId = queryService.getImageId(imageConfig.getName());
            String containerId = runService.lookupContainer(imageConfig.getName());
            ImageWatcher watcher = new ImageWatcher(imageConfig, context, imageId, containerId);
            long interval = watcher.getInterval();
            WatchMode watchMode = watcher.getWatchMode(imageConfig);
            log.info("Watching " + imageConfig.getName() + (watchMode != null ? " using " + watchMode.getDescription() : ""));
            ArrayList<String> tasks = new ArrayList<>();
            if (imageConfig.getBuildConfiguration() != null && imageConfig.getBuildConfiguration().getAssemblyConfiguration() != null) {
                if (watcher.isCopy()) {
                    String containerBaseDir = imageConfig.getBuildConfiguration().getAssemblyConfiguration().getTargetDir();
                    schedule(executor, createCopyWatchTask(watcher, context.getMojoParameters(), containerBaseDir), interval);
                    tasks.add("copying artifacts");
                }
                if (watcher.isBuild()) {
                    schedule(executor, createBuildWatchTask(watcher, context.getMojoParameters(), watchMode == WatchMode.both, buildContext), interval);
                    tasks.add("rebuilding");
                }
            }
            if (watcher.isRun() && watcher.getContainerId() != null) {
                schedule(executor, createRestartWatchTask(watcher), interval);
                tasks.add("restarting");
            }
            if (tasks.size() > 0) {
                log.info("%s: Watch for %s", imageConfig.getDescription(), StringUtils.join(tasks.toArray(), " and "));
            }
        }
        log.info("Waiting ...");
        if (!context.isKeepRunning()) {
            runService.addShutdownHookForStoppingContainers(context.isKeepContainer(), context.isRemoveVolumes(), context.isAutoCreateCustomNetworks());
        }
        wait();
    } catch (InterruptedException e) {
        log.warn("Interrupted");
    } finally {
        if (executor != null) {
            executor.shutdownNow();
        }
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StartOrderResolver(io.fabric8.maven.docker.util.StartOrderResolver) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) WatchImageConfiguration(io.fabric8.maven.docker.config.WatchImageConfiguration) WatchMode(io.fabric8.maven.docker.config.WatchMode) ArrayList(java.util.ArrayList)

Example 23 with DockerAccessException

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

the class HealthCheckChecker method check.

@Override
public boolean check() {
    try {
        final ContainerDetails container = docker.getContainer(containerId);
        if (container == null) {
            log.debug("HealthWaitChecker: Container %s not found");
            return false;
        }
        if (container.getHealthcheck() == null) {
            throw new IllegalArgumentException("Can not wait for healthstate of " + imageConfigDesc + ". No HEALTHCHECK configured.");
        }
        if (first) {
            log.info("%s: Waiting to become healthy", imageConfigDesc);
            log.debug("HealthWaitChecker: Waiting for healthcheck: '%s'", container.getHealthcheck());
            first = false;
        } else if (log.isDebugEnabled()) {
            log.debug("HealthWaitChecker: Waiting on healthcheck '%s'", container.getHealthcheck());
        }
        return container.isHealthy();
    } catch (DockerAccessException e) {
        log.warn("Error while checking health: %s", e.getMessage());
        return false;
    }
}
Also used : DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) ContainerDetails(io.fabric8.maven.docker.model.ContainerDetails)

Example 24 with DockerAccessException

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

the class DockerAccessIT method testExecContainer.

private void testExecContainer() throws DockerAccessException {
    Arguments arguments = new Arguments();
    arguments.setExec(Lists.newArrayList("echo", "test", "echo"));
    String execContainerId = dockerClient.createExecContainer(this.containerId, arguments);
// assertThat(dockerClient.startExecContainer(execContainerId), is("test echo"));
}
Also used : Arguments(io.fabric8.maven.docker.config.Arguments)

Example 25 with DockerAccessException

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

the class BuildMojo method buildAndTag.

protected void buildAndTag(ServiceHub hub, ImageConfiguration imageConfig) throws MojoExecutionException, DockerAccessException {
    EnvUtil.storeTimestamp(getBuildTimestampFile(), getBuildTimestamp());
    BuildService.BuildContext buildContext = getBuildContext();
    ImagePullManager pullManager = getImagePullManager(determinePullPolicy(imageConfig.getBuildConfiguration()), autoPull);
    BuildService buildService = hub.getBuildService();
    buildService.buildImage(imageConfig, pullManager, buildContext);
    if (!skipTag) {
        buildService.tagImage(imageConfig.getName(), imageConfig);
    }
}
Also used : BuildService(io.fabric8.maven.docker.service.BuildService) ImagePullManager(io.fabric8.maven.docker.service.ImagePullManager)

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