Skip to content

Commit

Permalink
Issue #1205 Increase GZIP compression speed for docker:save. (#1206)
Browse files Browse the repository at this point in the history
* Issue #1203 NPE if docker:save called with filename only.

Signed-off-by: William Rose <william.rose@nuance.com>

* Issue #1205 Increase GZIP compression speed for docker:save.

Signed-off-by: William Rose <william.rose@nuance.com>
  • Loading branch information
wrosenuance authored and rhuss committed Apr 12, 2019
1 parent 4097464 commit adc22e7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* **0.29-SNAPSHOT**
- Restore ANSI color to Maven logging if disabled during plugin execution and enable color for Windows with Maven 3.5.0 or later. Color logging is enabled by default, but disabled if the Maven CLI disables color (e.g. in batch mode) ([#1108](https://github.com/fabric8io/docker-maven-plugin/issues/1108))
- Fix NPE if docker:save is called with -Dfile=file-name-only.tar ([#1203](https://github.com/fabric8io/docker-maven-plugin/issues/1203))
- Improve GZIP compression performance for docker:save ([#1205](https://github.com/fabric8io/docker-maven-plugin/issues/1205))

* **0.29.0** (2019-04-08)
- Avoid failing docker:save when no images with build configuration are present ([#1185](https://github.com/fabric8io/docker-maven-plugin/issues/1185))
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/fabric8/maven/docker/SaveMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Properties;

import io.fabric8.maven.docker.config.ArchiveCompression;
import io.fabric8.maven.docker.util.EnvUtil;
import io.fabric8.maven.docker.util.ImageName;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
Expand Down Expand Up @@ -54,7 +55,9 @@ protected void executeInternal(ServiceHub serviceHub) throws DockerAccessExcepti
throw new MojoExecutionException("No image " + imageName + " exists");
}

long time = System.currentTimeMillis();
serviceHub.getDockerAccess().saveImage(imageName, fileName, ArchiveCompression.fromFileName(fileName));
log.info("%s: Saved image to %s in %s", imageName, fileName, EnvUtil.formatDurationTill(time));
}

private boolean skipSaveFor(List<ImageConfiguration> images) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ private ResponseHandler<Object> getImageResponseHandler(final String filename, f
public Object handleResponse(HttpResponse response) throws IOException {
try (InputStream stream = response.getEntity().getContent();
OutputStream out = compression.wrapOutputStream(new FileOutputStream(filename))) {
IOUtils.copy(stream, out);
IOUtils.copy(stream, out, 65536);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.GZIPOutputStream;
import java.util.zip.Deflater;

import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
import org.codehaus.plexus.archiver.tar.TarArchiver;
Expand Down Expand Up @@ -81,4 +81,11 @@ public static ArchiveCompression fromFileName(String filename) {
return ArchiveCompression.none;
}

private static class GZIPOutputStream extends java.util.zip.GZIPOutputStream {
private GZIPOutputStream(OutputStream out) throws IOException {
super(out, 65536);
// According to https://bugs.openjdk.java.net/browse/JDK-8142920, 3 is a better default
def.setLevel(3);
}
}
}

0 comments on commit adc22e7

Please sign in to comment.