use of io.fabric8.maven.docker.config.CopyConfiguration in project docker-maven-plugin by fabric8io.
the class PropertyConfigHandler method resolve.
@Override
public List<ImageConfiguration> resolve(ImageConfiguration fromConfig, MavenProject project, MavenSession session) throws IllegalArgumentException {
Map<String, String> externalConfig = fromConfig.getExternalConfig();
String prefix = getPrefix(externalConfig);
Properties properties = EnvUtil.getPropertiesWithSystemOverrides(project);
PropertyMode propertyMode = getMode(externalConfig);
ValueProvider valueProvider = new ValueProvider(prefix, properties, propertyMode);
RunImageConfiguration run = extractRunConfiguration(fromConfig, valueProvider);
BuildImageConfiguration build = extractBuildConfiguration(fromConfig, valueProvider, project);
WatchImageConfiguration watch = extractWatchConfig(fromConfig, valueProvider);
CopyConfiguration copyConfig = extractCopyConfig(fromConfig, valueProvider);
String name = valueProvider.getString(NAME, fromConfig.getName());
String alias = valueProvider.getString(ALIAS, fromConfig.getAlias());
String removeNamePattern = valueProvider.getString(REMOVE_NAME_PATTERN, fromConfig.getRemoveNamePattern());
String copyNamePattern = valueProvider.getString(COPY_NAME_PATTERN, fromConfig.getCopyNamePattern());
String stopNamePattern = valueProvider.getString(STOP_NAME_PATTERN, fromConfig.getStopNamePattern());
if (name == null) {
throw new IllegalArgumentException(String.format("Mandatory property [%s] is not defined", NAME));
}
return Collections.singletonList(new ImageConfiguration.Builder().name(name).alias(alias).removeNamePattern(removeNamePattern).copyNamePattern(copyNamePattern).stopNamePattern(stopNamePattern).runConfig(run).buildConfig(build).watchConfig(watch).copyConfig(copyConfig).build());
}
use of io.fabric8.maven.docker.config.CopyConfiguration in project docker-maven-plugin by fabric8io.
the class CopyMojo method copyFromTemporaryContainers.
private void copyFromTemporaryContainers(DockerAccess dockerAccess, RunService runService, RegistryService registryService, ArchiveService archiveService, QueryService queryService, GavLabel gavLabel) throws IOException, MojoExecutionException {
List<ImageConfiguration> imageConfigurations = getResolvedImages();
for (ImageConfiguration imageConfiguration : imageConfigurations) {
CopyConfiguration copyConfiguration = imageConfiguration.getCopyConfiguration();
String imageName = imageConfiguration.getName();
if (isEmpty(copyConfiguration)) {
log.debug("Copy configuration is not defined for %s image, skipping coping", imageName);
continue;
}
try (ContainerRemover containerRemover = new ContainerRemover(log, runService, removeVolumes)) {
String containerId = createContainer(runService, registryService, imageConfiguration, gavLabel);
containerRemover.setContainerId(containerId);
log.debug("Created %s container from %s image", containerId, imageName);
copy(dockerAccess, archiveService, containerId, imageName, copyConfiguration);
}
}
}
use of io.fabric8.maven.docker.config.CopyConfiguration in project docker-maven-plugin by fabric8io.
the class CopyMojo method copyFromStartedContainers.
private void copyFromStartedContainers(DockerAccess dockerAccess, RunService runService, ArchiveService archiveService, GavLabel gavLabel) throws IOException, MojoExecutionException {
List<ContainerDescriptor> containerDescriptors = runService.getContainers(gavLabel);
for (ContainerDescriptor containerDescriptor : containerDescriptors) {
ImageConfiguration imageConfiguration = containerDescriptor.getImageConfig();
CopyConfiguration copyConfiguration = imageConfiguration.getCopyConfiguration();
String imageName = imageConfiguration.getName();
if (isEmpty(copyConfiguration)) {
log.debug("Copy configuration is not defined for %s image, skipping coping", imageName);
continue;
}
String containerId = containerDescriptor.getContainerId();
log.debug("Found %s container of %s image started by start mojo", containerId, imageName);
copy(dockerAccess, archiveService, containerId, imageName, copyConfiguration);
}
}
use of io.fabric8.maven.docker.config.CopyConfiguration in project docker-maven-plugin by fabric8io.
the class CopyMojo method copyFromExistingContainers.
private void copyFromExistingContainers(DockerAccess dockerAccess, ArchiveService archiveService, QueryService queryService) throws IOException, MojoExecutionException {
List<ImageConfiguration> imageConfigurations = getResolvedImages();
for (ImageConfiguration imageConfiguration : imageConfigurations) {
CopyConfiguration copyConfiguration = imageConfiguration.getCopyConfiguration();
String imageName = imageConfiguration.getName();
if (isEmpty(copyConfiguration)) {
log.debug("Copy configuration is not defined for %s image, skipping coping", imageName);
continue;
}
Collection<Container> containers = getContainersForImage(queryService, imageConfiguration);
if (containers.isEmpty()) {
log.warn("Found no containers of %s image", imageName);
continue;
}
if (containers.size() > 1) {
log.warn("Found more than one container of %s image", imageName);
}
for (Container container : containers) {
String containerId = container.getId();
log.debug("Found %s container of %s image", containerId, imageName);
copy(dockerAccess, archiveService, containerId, imageName, copyConfiguration);
}
}
}
use of io.fabric8.maven.docker.config.CopyConfiguration in project docker-maven-plugin by fabric8io.
the class PropertyConfigHandlerTest method testCopyConfiguration.
@Test
public void testCopyConfiguration() {
imageConfiguration = new ImageConfiguration.Builder().externalConfig(new HashMap<>()).copyConfig(new CopyConfiguration.Builder().entries(Collections.singletonList(new CopyConfiguration.Entry("/test4/path", "project/dir"))).build()).build();
makeExternalConfigUse(PropertyMode.Override);
final List<ImageConfiguration> configs = resolveImage(imageConfiguration, props(k(ConfigKey.NAME), "image", k(ConfigKey.FROM), "base", k(ConfigKey.COPY_ENTRIES) + ".1", "/test1", k(ConfigKey.COPY_ENTRIES) + ".2." + CopyConfiguration.CONTAINER_PATH_PROPERTY, "/test2", k(ConfigKey.COPY_ENTRIES) + ".2." + CopyConfiguration.HOST_DIRECTORY_PROPERTY, "/root/dir", k(ConfigKey.COPY_ENTRIES) + ".3." + CopyConfiguration.CONTAINER_PATH_PROPERTY, "/test3/path", k(ConfigKey.COPY_ENTRIES) + ".3." + CopyConfiguration.HOST_DIRECTORY_PROPERTY, "project/dir"));
assertEquals(1, configs.size());
final CopyConfiguration copyConfig = configs.get(0).getCopyConfiguration();
final List<CopyConfiguration.Entry> copyEntries = copyConfig.getEntries();
assertEquals(3, copyEntries.size());
assertCopyEntryEquals(new CopyConfiguration.Entry("/test1", null), copyEntries.get(0));
assertCopyEntryEquals(new CopyConfiguration.Entry("/test2", "/root/dir"), copyEntries.get(1));
assertCopyEntryEquals(new CopyConfiguration.Entry("/test3/path", "project/dir"), copyEntries.get(2));
}
Aggregations