Search in sources :

Example 11 with MojoParameters

use of io.fabric8.maven.docker.util.MojoParameters in project docker-maven-plugin by fabric8io.

the class DockerAssemblyManager method getAssemblyFiles.

/**
 * Extract all files with a tracking archiver. These can be used to track changes in the filesystem and triggering
 * a rebuild of the image if needed ('docker:watch')
 */
public AssemblyFiles getAssemblyFiles(String name, BuildImageConfiguration buildConfig, MojoParameters mojoParams, Logger log) throws InvalidAssemblerConfigurationException, ArchiveCreationException, AssemblyFormattingException, MojoExecutionException {
    BuildDirs buildDirs = createBuildDirs(name, mojoParams);
    AssemblyConfiguration assemblyConfig = buildConfig.getAssemblyConfiguration();
    String assemblyName = assemblyConfig.getName();
    DockerAssemblyConfigurationSource source = new DockerAssemblyConfigurationSource(mojoParams, buildDirs, assemblyConfig);
    Assembly assembly = getAssemblyConfig(assemblyConfig, source);
    synchronized (trackArchiver) {
        MappingTrackArchiver ta = (MappingTrackArchiver) trackArchiver;
        ta.init(log, assemblyName);
        assembly.setId("tracker");
        assemblyArchiver.createArchive(assembly, assemblyName, "track", source, false);
        return ta.getAssemblyFiles(mojoParams.getSession());
    }
}
Also used : AssemblyConfiguration(io.fabric8.maven.docker.config.AssemblyConfiguration) Assembly(org.apache.maven.plugin.assembly.model.Assembly)

Example 12 with MojoParameters

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

Example 13 with MojoParameters

use of io.fabric8.maven.docker.util.MojoParameters in project docker-maven-plugin by fabric8io.

the class DockerFileUtil method createInterpolator.

/**
 * Create an interpolator for the given maven parameters and filter configuration.
 *
 * @param params The maven parameters.
 * @param filter The filter configuration.
 * @return An interpolator for replacing maven properties.
 */
public static FixedStringSearchInterpolator createInterpolator(MojoParameters params, String filter) {
    String[] delimiters = extractDelimiters(filter);
    if (delimiters == null) {
        // Don't interpolate anything
        return FixedStringSearchInterpolator.create();
    }
    DockerAssemblyConfigurationSource configSource = new DockerAssemblyConfigurationSource(params, null, null);
    // Patterned after org.apache.maven.plugin.assembly.interpolation.AssemblyExpressionEvaluator
    return AssemblyInterpolator.fullInterpolator(params.getProject(), DefaultAssemblyReader.createProjectInterpolator(params.getProject()), configSource).withExpressionMarkers(delimiters[0], delimiters[1]);
}
Also used : DockerAssemblyConfigurationSource(io.fabric8.maven.docker.assembly.DockerAssemblyConfigurationSource)

Example 14 with MojoParameters

use of io.fabric8.maven.docker.util.MojoParameters in project docker-maven-plugin by fabric8io.

the class DockerAssemblyConfigurationSourceTest method testEmptyAssemblyConfig.

@Test
public void testEmptyAssemblyConfig() {
    DockerAssemblyConfigurationSource source = new DockerAssemblyConfigurationSource(new MojoParameters(null, null, null, null, null, null, "/src/docker", "/output/docker", null), null, null);
    assertEquals(0, source.getDescriptors().length);
}
Also used : MojoParameters(io.fabric8.maven.docker.util.MojoParameters) Test(org.junit.Test)

Example 15 with MojoParameters

use of io.fabric8.maven.docker.util.MojoParameters in project docker-maven-plugin by fabric8io.

the class SourceMojo method executeInternal.

@Override
protected void executeInternal(ServiceHub hub) throws DockerAccessException, MojoExecutionException {
    MojoParameters params = createMojoParameters();
    List<ImageConfiguration> imageConfigs = new ArrayList<>();
    for (ImageConfiguration imageConfig : getResolvedImages()) {
        BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
        if (buildConfig != null) {
            if (buildConfig.skip()) {
                log.info("%s: Skipped creating source", imageConfig.getDescription());
            } else {
                imageConfigs.add(imageConfig);
            }
        }
    }
    if (sourceMode == BuildImageSelectMode.first && imageConfigs.size() > 0) {
        ImageConfiguration imageConfig = imageConfigs.get(0);
        File dockerTar = hub.getArchiveService().createDockerBuildArchive(imageConfig, params);
        projectHelper.attachArtifact(project, getArchiveType(imageConfig), getClassifier(null), dockerTar);
    } else {
        for (ImageConfiguration imageConfig : imageConfigs) {
            File dockerTar = hub.getArchiveService().createDockerBuildArchive(imageConfig, params);
            String alias = imageConfig.getAlias();
            if (alias == null) {
                throw new IllegalArgumentException("Image " + imageConfig.getDescription() + " must have an 'alias' configured to be " + "used as a classifier for attaching a docker build tar as source to the maven build");
            }
            projectHelper.attachArtifact(project, getArchiveType(imageConfig), getClassifier(alias), dockerTar);
        }
    }
}
Also used : MojoParameters(io.fabric8.maven.docker.util.MojoParameters) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) ArrayList(java.util.ArrayList) File(java.io.File) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Aggregations

File (java.io.File)7 MojoParameters (io.fabric8.maven.docker.util.MojoParameters)6 Test (org.junit.Test)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)3 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)3 IOException (java.io.IOException)3 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)2 ExecException (io.fabric8.maven.docker.access.ExecException)2 AssemblyFiles (io.fabric8.maven.docker.assembly.AssemblyFiles)2 AssemblyConfiguration (io.fabric8.maven.docker.config.AssemblyConfiguration)2 WatchImageConfiguration (io.fabric8.maven.docker.config.WatchImageConfiguration)2 ArrayList (java.util.ArrayList)2 Assembly (org.apache.maven.plugin.assembly.model.Assembly)2 MavenProject (org.apache.maven.project.MavenProject)2 FixedStringSearchInterpolator (org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator)2 BuildOptions (io.fabric8.maven.docker.access.BuildOptions)1 DockerAssemblyConfigurationSource (io.fabric8.maven.docker.assembly.DockerAssemblyConfigurationSource)1 AssemblyMode (io.fabric8.maven.docker.config.AssemblyMode)1 CleanupMode (io.fabric8.maven.docker.config.CleanupMode)1