Search in sources :

Example 6 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 7 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 8 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 9 with CopyConfiguration

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

the class CopyConfigurationTest method empty.

@Test
public void empty() {
    final CopyConfiguration cfg = new Builder().build();
    assertEntries(cfg, null);
    assertEntriesAsProperties(cfg, null);
}
Also used : Builder(io.fabric8.maven.docker.config.CopyConfiguration.Builder) Test(org.junit.Test)

Example 10 with CopyConfiguration

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

the class CopyConfigurationTest method assertEntries.

private void assertEntries(final CopyConfiguration cfg, Collection<Entry> expected) {
    final List<Entry> actual = cfg.getEntries();
    if (expected == null) {
        assertNull(actual);
        return;
    }
    assertNotNull(actual);
    assertEquals(expected.size(), actual.size());
    final Iterator<Entry> actualIterator = actual.iterator();
    for (Entry expectedEntry : expected) {
        final Entry actualEntry = actualIterator.next();
        assertEquals(expectedEntry.getContainerPath(), actualEntry.getContainerPath());
        assertEquals(expectedEntry.getHostDirectory(), actualEntry.getHostDirectory());
    }
}
Also used : Entry(io.fabric8.maven.docker.config.CopyConfiguration.Entry)

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