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