diff --git a/src/main/asciidoc/inc/_docker-save.adoc b/src/main/asciidoc/inc/_docker-save.adoc index 359e41a35..7de421b57 100644 --- a/src/main/asciidoc/inc/_docker-save.adoc +++ b/src/main/asciidoc/inc/_docker-save.adoc @@ -10,6 +10,31 @@ If the option `saveFile` is not set, the file name is calculated automatically: Please note that the exported image contains all image layers and can be quite large (also, it takes a bit to export the image). +.Controlling image compression +The file name extension is used to select a compression method for the output. +[cols="3,2,1"] +|=== +| Extensions | Compression | Type + +| .tar or unrecognized +| No compression +| .tar + +| .tar.gz, .tgz +| GZIP compression +| .tar.gz + +| .tar.bz, .tar.bz2, .tar.bzip2 +| BZIP2 compression +| .tar.bz + +|=== + +.Attaching the saved image as an artifact +If `saveClassifier` is set, the saved archive will be attached to the project using the provided classifier and the type determined from the file name. The placeholder `%a` will be replaced with the image alias. + +Note that using overriding the default to use `docker` or `docker-%a` may lead to a conflict if a source archive is also attached with <<{plugin}:source>>. + .Save options [cols="1,5,1"] |=== @@ -27,12 +52,8 @@ Please note that the exported image contains all image layers and can be quite l | The filename to save. | `docker.save.file` or `docker.file` or `file` -| *saveAttach* -| Whether to attach the saved archive to the project (`false` by default). -| `docker.save.attach` - | *saveClassifier* -| Sets the artifact classifier when attaching the saved archive to the project. If `saveAlias` is set, defaults to `archive-`, otherwise defaults to `archive`. Note that using overriding the default to use `docker` or `docker-` may lead to a conflict if a source archive is also attached with <<{plugin}:source>>. +| If set, attach the the saved archive to the project with the provided classifier. A placeholder of `%a` will be replaced with the image alias. | `docker.save.classifier` | *skipSave* diff --git a/src/main/java/io/fabric8/maven/docker/SaveMojo.java b/src/main/java/io/fabric8/maven/docker/SaveMojo.java index 71cea735f..62659c8e1 100644 --- a/src/main/java/io/fabric8/maven/docker/SaveMojo.java +++ b/src/main/java/io/fabric8/maven/docker/SaveMojo.java @@ -39,9 +39,6 @@ public class SaveMojo extends AbstractDockerMojo { @Parameter(property = "docker.skip.save", defaultValue = "false") private boolean skipSave; - @Parameter(property = "docker.save.attach", defaultValue = "false") - private boolean saveAttach; - @Parameter(property = "docker.save.classifier") private String saveClassifier; @@ -53,7 +50,8 @@ protected void executeInternal(ServiceHub serviceHub) throws DockerAccessExcepti return; } - String imageName = getImageName(images); + ImageConfiguration image = getImageToSave(images); + String imageName = image.getName(); String fileName = getFileName(imageName); ensureSaveDir(fileName); log.info("Saving image %s to %s", imageName, fileName); @@ -66,8 +64,9 @@ protected void executeInternal(ServiceHub serviceHub) throws DockerAccessExcepti serviceHub.getDockerAccess().saveImage(imageName, fileName, compression); log.info("%s: Saved image to %s in %s", imageName, fileName, EnvUtil.formatDurationTill(time)); - if(saveAttach) { - projectHelper.attachArtifact(project, compression.getFileSuffix(), getClassifier(), new File(fileName)); + String classifier = getClassifier(image); + if(classifier != null) { + projectHelper.attachArtifact(project, compression.getFileSuffix(), classifier, new File(fileName)); } } @@ -128,12 +127,12 @@ private void ensureSaveDir(String fileName) throws MojoExecutionException { } } - private String getImageName(List images) throws MojoExecutionException { + private ImageConfiguration getImageToSave(List images) throws MojoExecutionException { // specify image by name or alias if (saveName == null && saveAlias == null) { List buildImages = getImagesWithBuildConfig(images); if (buildImages.size() == 1) { - return buildImages.get(0).getName(); + return buildImages.get(0); } throw new MojoExecutionException("More than one image with build configuration is defined. Please specify the image with 'docker.name' or 'docker.alias'."); } @@ -142,7 +141,7 @@ private String getImageName(List images) throws MojoExecutio } for (ImageConfiguration ic : images) { if (equalName(ic) || equalAlias(ic)) { - return ic.getName(); + return ic; } } throw new MojoExecutionException(saveName != null ? @@ -160,12 +159,12 @@ private List getImagesWithBuildConfig(List