Search in sources :

Example 6 with ArchiveService

use of io.fabric8.maven.docker.service.ArchiveService in project docker-maven-plugin by fabric8io.

the class CopyMojo method copy.

private void copy(DockerAccess dockerAccess, ArchiveService archiveService, String containerId, String imageName, CopyConfiguration copyConfiguration) throws IOException, MojoExecutionException {
    List<CopyConfiguration.Entry> copyEntries = copyConfiguration.getEntries();
    for (CopyConfiguration.Entry copyEntry : copyEntries) {
        String containerPath = copyEntry.getContainerPath();
        if (containerPath == null) {
            log.error("containerPath of copy goal entry for %s image is not specified", imageName);
            throw new IllegalArgumentException("containerPath should be specified");
        }
        File hostDirectory = getHostDirectory(copyEntry.getHostDirectory());
        log.info("Copying %s from %s container into %s host directory", containerPath, containerId, hostDirectory.getAbsolutePath());
        Files.createDirectories(hostDirectory.toPath());
        try (FileRemover fileRemover = new FileRemover(log)) {
            File archiveFile = Files.createTempFile(TEMP_ARCHIVE_FILE_PREFIX, TEMP_ARCHIVE_FILE_SUFFIX).toFile();
            fileRemover.setFile(archiveFile);
            log.debug("Created %s temporary file for docker copy archive", archiveFile);
            log.debug("Copying %s from %s container into %s host file", containerPath, containerId, archiveFile);
            dockerAccess.copyArchiveFromContainer(containerId, containerPath, archiveFile);
            log.debug("Extracting %s archive into %s directory", archiveFile, hostDirectory);
            archiveService.extractDockerCopyArchive(archiveFile, hostDirectory);
        }
    }
}
Also used : Entry(io.fabric8.maven.docker.config.CopyConfiguration.Entry) CopyConfiguration(io.fabric8.maven.docker.config.CopyConfiguration) Entry(io.fabric8.maven.docker.config.CopyConfiguration.Entry) File(java.io.File)

Aggregations

CopyConfiguration (io.fabric8.maven.docker.config.CopyConfiguration)4 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)3 File (java.io.File)2 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)1 BuildService (io.fabric8.maven.core.service.BuildService)1 DockerAccess (io.fabric8.maven.docker.access.DockerAccess)1 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)1 Entry (io.fabric8.maven.docker.config.CopyConfiguration.Entry)1 Container (io.fabric8.maven.docker.model.Container)1 ArchiveService (io.fabric8.maven.docker.service.ArchiveService)1 QueryService (io.fabric8.maven.docker.service.QueryService)1 RegistryService (io.fabric8.maven.docker.service.RegistryService)1 RunService (io.fabric8.maven.docker.service.RunService)1 ContainerDescriptor (io.fabric8.maven.docker.service.RunService.ContainerDescriptor)1 GavLabel (io.fabric8.maven.docker.util.GavLabel)1 BuildBuilder (io.fabric8.openshift.api.model.BuildBuilder)1 BuildConfigBuilder (io.fabric8.openshift.api.model.BuildConfigBuilder)1 ImageStreamBuilder (io.fabric8.openshift.api.model.ImageStreamBuilder)1 ImageStreamStatusBuilder (io.fabric8.openshift.api.model.ImageStreamStatusBuilder)1 NamedTagEventListBuilder (io.fabric8.openshift.api.model.NamedTagEventListBuilder)1