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());
}
}
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());
}
}
}
};
}
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]);
}
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);
}
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);
}
}
}
Aggregations