Search in sources :

Example 56 with ImageConfiguration

use of io.fabric8.maven.docker.config.ImageConfiguration in project docker-maven-plugin by fabric8io.

the class LogOutputSpecFactory method addPrefix.

private void addPrefix(LogOutputSpec.Builder builder, String logPrefix, ImageConfiguration imageConfig, String containerId) {
    String prefixFormat = logPrefix;
    if (prefixFormat == null) {
        prefixFormat = DEFAULT_PREFIX_FORMAT;
    }
    FormatParameterReplacer formatParameterReplacer = new FormatParameterReplacer(getPrefixFormatParameterLookups(imageConfig, containerId));
    builder.prefix(formatParameterReplacer.replace(prefixFormat));
}
Also used : FormatParameterReplacer(io.fabric8.maven.docker.util.FormatParameterReplacer)

Example 57 with ImageConfiguration

use of io.fabric8.maven.docker.config.ImageConfiguration in project docker-maven-plugin by fabric8io.

the class LogOutputSpecFactory method createSpec.

// ================================================================================================
public LogOutputSpec createSpec(String containerId, ImageConfiguration imageConfiguration) {
    LogOutputSpec.Builder builder = new LogOutputSpec.Builder();
    LogConfiguration logConfig = extractLogConfiguration(imageConfiguration);
    addLogFormat(builder, logConfig);
    addPrefix(builder, logConfig.getPrefix(), imageConfiguration, containerId);
    builder.file(logConfig.getFileLocation()).useColor(useColor).logStdout(logStdout).color(logConfig.getColor());
    return builder.build();
}
Also used : LogConfiguration(io.fabric8.maven.docker.config.LogConfiguration)

Example 58 with ImageConfiguration

use of io.fabric8.maven.docker.config.ImageConfiguration in project docker-maven-plugin by fabric8io.

the class BuildService method autoPullBaseImage.

private void autoPullBaseImage(ImageConfiguration imageConfig, ImagePullManager imagePullManager, BuildContext buildContext) throws DockerAccessException, MojoExecutionException {
    BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
    if (buildConfig.getDockerArchive() != null) {
        // No auto pull needed in archive mode
        return;
    }
    String fromImage;
    if (buildConfig.isDockerFileMode()) {
        fromImage = extractBaseFromDockerfile(buildConfig, buildContext);
    } else {
        fromImage = extractBaseFromConfiguration(buildConfig);
    }
    if (fromImage != null && !DockerAssemblyManager.SCRATCH_IMAGE.equals(fromImage)) {
        registryService.pullImageWithPolicy(fromImage, imagePullManager, buildContext.getRegistryConfig(), queryService.hasImage(fromImage));
    }
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Example 59 with ImageConfiguration

use of io.fabric8.maven.docker.config.ImageConfiguration 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 60 with ImageConfiguration

use of io.fabric8.maven.docker.config.ImageConfiguration in project docker-maven-plugin by fabric8io.

the class WatchService method createCopyWatchTask.

private Runnable createCopyWatchTask(final ImageWatcher watcher, final MojoParameters mojoParameters, final String containerBaseDir) throws MojoExecutionException {
    final ImageConfiguration imageConfig = watcher.getImageConfiguration();
    final AssemblyFiles files = archiveService.getAssemblyFiles(imageConfig, mojoParameters);
    return new Runnable() {

        @Override
        public void run() {
            List<AssemblyFiles.Entry> entries = files.getUpdatedEntriesAndRefresh();
            if (entries != null && entries.size() > 0) {
                try {
                    log.info("%s: Assembly changed. Copying changed files to container ...", imageConfig.getDescription());
                    File changedFilesArchive = archiveService.createChangedFilesArchive(entries, files.getAssemblyDirectory(), imageConfig.getName(), mojoParameters);
                    dockerAccess.copyArchive(watcher.getContainerId(), changedFilesArchive, containerBaseDir);
                    callPostExec(watcher);
                } catch (MojoExecutionException | IOException | ExecException e) {
                    log.error("%s: Error when copying files to container %s: %s", imageConfig.getDescription(), watcher.getContainerId(), e.getMessage());
                }
            }
        }
    };
}
Also used : AssemblyFiles(io.fabric8.maven.docker.assembly.AssemblyFiles) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) WatchImageConfiguration(io.fabric8.maven.docker.config.WatchImageConfiguration) ExecException(io.fabric8.maven.docker.access.ExecException) IOException(java.io.IOException) File(java.io.File)

Aggregations

BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)50 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)38 AbstractConfigHandlerTest (io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)24 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)14 Test (org.junit.Test)13 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)10 File (java.io.File)9 IOException (java.io.IOException)9 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)8 ArrayList (java.util.ArrayList)8 GeneratorContext (io.fabric8.maven.generator.api.GeneratorContext)7 MojoFailureException (org.apache.maven.plugin.MojoFailureException)7 Before (org.junit.Before)7 VolumeConfig (io.fabric8.maven.core.config.VolumeConfig)6 Fabric8ServiceException (io.fabric8.maven.core.service.Fabric8ServiceException)6 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)5 Expectations (mockit.Expectations)5 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)4 ExecException (io.fabric8.maven.docker.access.ExecException)4 WatchImageConfiguration (io.fabric8.maven.docker.config.WatchImageConfiguration)4