use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project twister2 by DSC-SPIDAL.
the class TarGzipPacker method addTarGzipToArchive.
/**
* given tar.gz file will be copied to this tar.gz file.
* all files will be transferred to new tar.gz file one by one.
* original directory structure will be kept intact
*
* @param tarGzipFile the archive file to be copied to the new archive
*/
public boolean addTarGzipToArchive(String tarGzipFile) {
try {
// construct input stream
InputStream fin = Files.newInputStream(Paths.get(tarGzipFile));
BufferedInputStream in = new BufferedInputStream(fin);
GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in);
TarArchiveInputStream tarInputStream = new TarArchiveInputStream(gzIn);
// copy the existing entries from source gzip file
ArchiveEntry nextEntry;
while ((nextEntry = tarInputStream.getNextEntry()) != null) {
tarOutputStream.putArchiveEntry(nextEntry);
IOUtils.copy(tarInputStream, tarOutputStream);
tarOutputStream.closeArchiveEntry();
}
tarInputStream.close();
return true;
} catch (IOException ioe) {
LOG.log(Level.SEVERE, "Archive File can not be added: " + tarGzipFile, ioe);
return false;
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project docker-client by spotify.
the class CompressedDirectoryTest method testFileWithIgnore.
@Test
public void testFileWithIgnore() throws Exception {
// note: Paths.get(someURL.toUri()) is the platform-neutral way to convert a URL to a Path
final URL dockerDirectory = Resources.getResource("dockerDirectoryWithIgnore");
try (CompressedDirectory dir = CompressedDirectory.create(Paths.get(dockerDirectory.toURI()));
BufferedInputStream fileIn = new BufferedInputStream(Files.newInputStream(dir.file()));
GzipCompressorInputStream gzipIn = new GzipCompressorInputStream(fileIn);
TarArchiveInputStream tarIn = new TarArchiveInputStream(gzipIn)) {
final List<String> names = new ArrayList<>();
TarArchiveEntry entry;
while ((entry = tarIn.getNextTarEntry()) != null) {
final String name = entry.getName();
names.add(name);
}
assertThat(names, containsInAnyOrder("Dockerfile", "bin/", "bin/date.sh", "subdir2/", "subdir2/keep.me", "subdir2/do-not.ignore", "subdir3/do.keep", ".dockerignore"));
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project docker-client by spotify.
the class CompressedDirectoryTest method testFileWithEmptyDirectory.
@Test
public void testFileWithEmptyDirectory() throws Exception {
Path tempDir = Files.createTempDirectory("dockerDirectoryEmptySubdirectory");
tempDir.toFile().deleteOnExit();
assertThat(new File(tempDir.toFile(), "emptySubDir").mkdir(), is(true));
try (CompressedDirectory dir = CompressedDirectory.create(tempDir);
BufferedInputStream fileIn = new BufferedInputStream(Files.newInputStream(dir.file()));
GzipCompressorInputStream gzipIn = new GzipCompressorInputStream(fileIn);
TarArchiveInputStream tarIn = new TarArchiveInputStream(gzipIn)) {
final List<String> names = new ArrayList<>();
TarArchiveEntry entry;
while ((entry = tarIn.getNextTarEntry()) != null) {
final String name = entry.getName();
names.add(name);
}
assertThat(names, contains("emptySubDir/"));
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project docker-client by spotify.
the class CompressedDirectoryTest method testFile.
@Test
public void testFile() throws Exception {
// note: Paths.get(someURL.toUri()) is the platform-neutral way to convert a URL to a Path
final URL dockerDirectory = Resources.getResource("dockerDirectory");
try (CompressedDirectory dir = CompressedDirectory.create(Paths.get(dockerDirectory.toURI()));
BufferedInputStream fileIn = new BufferedInputStream(Files.newInputStream(dir.file()));
GzipCompressorInputStream gzipIn = new GzipCompressorInputStream(fileIn);
TarArchiveInputStream tarIn = new TarArchiveInputStream(gzipIn)) {
final List<String> names = new ArrayList<>();
TarArchiveEntry entry;
while ((entry = tarIn.getNextTarEntry()) != null) {
final String name = entry.getName();
names.add(name);
}
assertThat(names, containsInAnyOrder("Dockerfile", "bin/", "bin/date.sh", "innerDir/", "innerDir/innerDockerfile"));
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project docker-client by spotify.
the class DefaultDockerClientTest method integrationTest.
@Test
@SuppressWarnings("deprecation")
public void integrationTest() throws Exception {
// Pull image
sut.pull(BUSYBOX_LATEST);
// Create container
final ContainerConfig config = ContainerConfig.builder().image(BUSYBOX_LATEST).cmd("sh", "-c", "while :; do sleep 1; done").build();
final String name = randomName();
final ContainerCreation creation = sut.createContainer(config, name);
final String id = creation.id();
assertThat(creation.warnings(), anyOf(is(empty()), is(nullValue())));
assertThat(id, is(any(String.class)));
// Inspect using container ID
{
final ContainerInfo info = sut.inspectContainer(id);
assertThat(info.id(), equalTo(id));
assertThat(info.config().image(), equalTo(config.image()));
assertThat(info.config().cmd(), equalTo(config.cmd()));
}
// Inspect using container name
{
final ContainerInfo info = sut.inspectContainer(name);
assertThat(info.config().image(), equalTo(config.image()));
assertThat(info.config().cmd(), equalTo(config.cmd()));
}
// Start container
sut.startContainer(id);
final Path dockerDirectory = getResource("dockerSslDirectory");
// to a directory in a container
if (dockerApiVersionAtLeast("1.20")) {
try {
sut.copyToContainer(dockerDirectory, id, "/tmp");
} catch (Exception e) {
fail("error copying files to container");
}
// Copy the same files from container
final ImmutableSet.Builder<String> filesDownloaded = ImmutableSet.builder();
try (TarArchiveInputStream tarStream = new TarArchiveInputStream(dockerApiVersionLessThan("1.24") ? sut.copyContainer(id, "/tmp") : sut.archiveContainer(id, "/tmp"))) {
TarArchiveEntry entry;
while ((entry = tarStream.getNextTarEntry()) != null) {
filesDownloaded.add(entry.getName());
}
}
// Check that we got back what we put in
final File folder = new File(dockerDirectory.toString());
final File[] files = folder.listFiles();
if (files != null) {
for (final File file : files) {
if (!file.isDirectory()) {
Boolean found = false;
for (final String fileDownloaded : filesDownloaded.build()) {
if (fileDownloaded.contains(file.getName())) {
found = true;
}
}
assertTrue(found);
}
}
}
}
// Kill container
sut.killContainer(id);
try {
// Remove the container
sut.removeContainer(id);
} catch (DockerRequestException e) {
// CircleCI doesn't let you remove a container :(
if (!CIRCLECI) {
// Verify that the container is gone
exception.expect(ContainerNotFoundException.class);
sut.inspectContainer(id);
}
}
}
Aggregations