X Tutup
Skip to content

Commit 742367d

Browse files
committed
Merge pull request #284 from docker-java/issue-283
Added GZIP compression for build context creation
2 parents 12ab37e + d8d3946 commit 742367d

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

src/main/java/com/github/dockerjava/core/CompressArchiveUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import static com.github.dockerjava.core.FilePathUtil.relativize;
44

5+
import java.io.BufferedOutputStream;
56
import java.io.File;
67
import java.io.FileOutputStream;
78
import java.io.IOException;
9+
import java.util.zip.GZIPOutputStream;
810

911
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
1012
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
@@ -16,8 +18,8 @@ public static File archiveTARFiles(File base, Iterable<File> files, String archi
1618
throws IOException {
1719
File tarFile = new File(FileUtils.getTempDirectoryPath(), archiveNameWithOutExtension + ".tar");
1820
tarFile.deleteOnExit();
19-
TarArchiveOutputStream tos = new TarArchiveOutputStream(new FileOutputStream(tarFile));
20-
try {
21+
try(TarArchiveOutputStream tos = new TarArchiveOutputStream(new GZIPOutputStream(
22+
new BufferedOutputStream(new FileOutputStream(tarFile))))) {
2123
tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
2224
for (File file : files) {
2325
TarArchiveEntry tarEntry = new TarArchiveEntry(file);
@@ -36,8 +38,6 @@ public static File archiveTARFiles(File base, Iterable<File> files, String archi
3638
}
3739
tos.closeArchiveEntry();
3840
}
39-
} finally {
40-
tos.close();
4141
}
4242

4343
return tarFile;

src/main/java/com/github/dockerjava/core/async/ResultCallbackTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ public void onComplete() {
6363

6464
@Override
6565
public void close() throws IOException {
66+
closed = true;
6667
if (stream != null)
6768
stream.close();
6869
completed.countDown();
69-
closed = true;
7070
}
7171

7272
/**

src/test/java/com/github/dockerjava/core/CompressArchiveUtilTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
import static org.hamcrest.CoreMatchers.is;
66
import static org.hamcrest.MatcherAssert.assertThat;
77

8+
import java.io.BufferedInputStream;
89
import java.io.File;
910
import java.io.FileInputStream;
1011
import java.io.FileOutputStream;
1112
import java.io.IOException;
13+
import java.util.zip.GZIPInputStream;
1214

1315
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
1416
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
@@ -43,7 +45,8 @@ private File extractFileByName(File archive, String filenameToExtract) throws IO
4345
expectedFile.delete();
4446
assertThat(expectedFile.exists(), is(false));
4547

46-
TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(new FileInputStream(archive));
48+
TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(new GZIPInputStream(
49+
new BufferedInputStream(new FileInputStream(archive))));
4750
TarArchiveEntry entry;
4851
while ((entry = tarArchiveInputStream.getNextTarEntry()) != null) {
4952
String individualFiles = entry.getName();

src/test/java/com/github/dockerjava/core/command/BuildImageCmdImplTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,17 @@ public void testAddAndCopySubstitution() throws Exception {
225225
String response = dockerfileBuild(baseDir);
226226
assertThat(response, containsString("testENVSubstitution successfully completed"));
227227
}
228+
229+
@Test
230+
public void testBuilderPerformance() throws Exception {
231+
File baseDir = new File(Thread.currentThread().getContextClassLoader().getResource("nginx").getFile());
232+
233+
String imageId = buildImage(baseDir);
234+
235+
InspectImageResponse inspectImageResponse = dockerClient.inspectImageCmd(imageId).exec();
236+
assertThat(inspectImageResponse, not(nullValue()));
237+
LOG.info("Image Inspect: {}", inspectImageResponse.toString());
238+
239+
assertThat(inspectImageResponse.getAuthor(), equalTo("Guillaume J. Charmes \"guillaume@dotcloud.com\""));
240+
}
228241
}

0 commit comments

Comments
 (0)
X Tutup