Search in sources :

Example 1 with CopyConfiguration

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());
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) WatchImageConfiguration(io.fabric8.maven.docker.config.WatchImageConfiguration) RunImageConfiguration(io.fabric8.maven.docker.config.RunImageConfiguration) CopyConfiguration(io.fabric8.maven.docker.config.CopyConfiguration) WatchImageConfiguration(io.fabric8.maven.docker.config.WatchImageConfiguration) Properties(java.util.Properties) RunImageConfiguration(io.fabric8.maven.docker.config.RunImageConfiguration) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Example 2 with CopyConfiguration

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);
        }
    }
}
Also used : ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) CopyConfiguration(io.fabric8.maven.docker.config.CopyConfiguration)

Example 3 with 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);
    }
}
Also used : ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) CopyConfiguration(io.fabric8.maven.docker.config.CopyConfiguration) ContainerDescriptor(io.fabric8.maven.docker.service.RunService.ContainerDescriptor)

Example 4 with 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);
        }
    }
}
Also used : Container(io.fabric8.maven.docker.model.Container) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) CopyConfiguration(io.fabric8.maven.docker.config.CopyConfiguration)

Example 5 with 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));
}
Also used : HashMap(java.util.HashMap) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) RunImageConfiguration(io.fabric8.maven.docker.config.RunImageConfiguration) CopyConfiguration(io.fabric8.maven.docker.config.CopyConfiguration) AbstractConfigHandlerTest(io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest) Test(org.junit.Test)

Aggregations

CopyConfiguration (io.fabric8.maven.docker.config.CopyConfiguration)7 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)5 Entry (io.fabric8.maven.docker.config.CopyConfiguration.Entry)4 Test (org.junit.Test)4 Builder (io.fabric8.maven.docker.config.CopyConfiguration.Builder)3 Properties (java.util.Properties)3 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)2 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)2 WatchImageConfiguration (io.fabric8.maven.docker.config.WatchImageConfiguration)1 AbstractConfigHandlerTest (io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)1 Container (io.fabric8.maven.docker.model.Container)1 ContainerDescriptor (io.fabric8.maven.docker.service.RunService.ContainerDescriptor)1 File (java.io.File)1 HashMap (java.util.HashMap)1