diff --git a/doc/changelog.md b/doc/changelog.md index efa9efb95..299ea5f6d 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -3,6 +3,7 @@ * **0.24-SNAPSHOT** - Fix possible NPE when logging to a file and the parent directory does not exist yet (#911) (#940) - Change content type to "application/json" when talking to the Docker daemon (#945) + - Use docker.skip.tag property on push and remove (#954) ([#869](https://github.com/fabric8io/docker-maven-plugin/issues/869)) - Property placeholders are not interpolated when they are the only thing in the XML element value (#960) - Fix deadlock waiting on docker log pattern to match (#767, #981, #947) diff --git a/src/main/asciidoc/inc/_docker-remove.adoc b/src/main/asciidoc/inc/_docker-remove.adoc index 4f9e0ac86..f16a6a375 100644 --- a/src/main/asciidoc/inc/_docker-remove.adoc +++ b/src/main/asciidoc/inc/_docker-remove.adoc @@ -5,7 +5,6 @@ This goal can be used to clean up images and containers. By default all images with a build configuration are removed. You can tune this by setting the property `removeMode` (property: `docker.removeMode`) to one of the following values: -[[config-image-build]] .removeMode Values [cols="1,5"] |=== @@ -34,3 +33,13 @@ Considering three images 'db','tomcat' and 'data' where 'data' is the only image * `mvn -Ddocker.removeMode=all {plugin}:remove` will remove all three images * `mvn -Ddocker.filter=data,tomcat {plugin}:remove` will remove 'data' * `mvn -Ddocker.filter=data,tomcat -Ddocker.removeMode=all {plugin}:remove` will remove 'data' and 'tomcat' + +.Remove options +[cols="1,5,1"] +|=== +| Element | Description | Property + +| *skipTag* +| If set to `true` this plugin won't remove any tags +| `docker.skip.tag` +|=== \ No newline at end of file diff --git a/src/main/asciidoc/inc/_global-configuration.adoc b/src/main/asciidoc/inc/_global-configuration.adoc index bfc8681b2..0bc375a9f 100644 --- a/src/main/asciidoc/inc/_global-configuration.adoc +++ b/src/main/asciidoc/inc/_global-configuration.adoc @@ -126,7 +126,9 @@ By default a progress meter is printed out on the console, which is omitted when | `docker.skip.run` | *skipTag* -| If set to `true` this plugin won't add any tags to images that have been built with `{plugin}:build` +| If set to `true` this plugin won't add any tags to images that have been built with `{plugin}:build`. + +If set to `true` this plugin won't push any tags with `{plugin}:push`. + +If set to `true` this plugin won't remove any tags with `{plugin}:remove`. + | `docker.skip.tag` | *skipMachine* diff --git a/src/main/asciidoc/inc/build/_configuration.adoc b/src/main/asciidoc/inc/build/_configuration.adoc index 4b2e20f53..fae7ebb0e 100644 --- a/src/main/asciidoc/inc/build/_configuration.adoc +++ b/src/main/asciidoc/inc/build/_configuration.adoc @@ -96,6 +96,9 @@ A provided `` takes precedence over the name given here. This tag is usefu | *skip* | if set to true disables building of the image. This config option is best used together with a maven property +| *skipTag* +| If set to `true` this plugin won't add any tags to images. Property: `docker.skip.tag` + | *tags* | List of additional `tag` elements with which an image is to be tagged after the build. Whitespace is trimmed from each element and empty elements are ignored. diff --git a/src/main/asciidoc/inc/push/_configuration.adoc b/src/main/asciidoc/inc/push/_configuration.adoc index ec5b6e124..047b690c5 100644 --- a/src/main/asciidoc/inc/push/_configuration.adoc +++ b/src/main/asciidoc/inc/push/_configuration.adoc @@ -9,6 +9,10 @@ | If set to `true` the plugin won't push any images that have been built. | `docker.skip.push` +| *skipTag* +| If set to `true` this plugin won't push any tags +| `docker.skip.tag` + | *pushRegistry* | The registry to use when pushing the image. See <> for more details. diff --git a/src/main/java/io/fabric8/maven/docker/BuildMojo.java b/src/main/java/io/fabric8/maven/docker/BuildMojo.java index 1dde7943d..1199a19c9 100644 --- a/src/main/java/io/fabric8/maven/docker/BuildMojo.java +++ b/src/main/java/io/fabric8/maven/docker/BuildMojo.java @@ -10,7 +10,6 @@ import io.fabric8.maven.docker.service.ImagePullManager; import io.fabric8.maven.docker.service.ServiceHub; import io.fabric8.maven.docker.util.EnvUtil; -import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; @@ -25,11 +24,14 @@ @Mojo(name = "build", defaultPhase = LifecyclePhase.INSTALL) public class BuildMojo extends AbstractBuildSupportMojo { - @Parameter(property = "docker.skip.tag", defaultValue = "false") - private boolean skipTag; - @Parameter(property = "docker.skip.build", defaultValue = "false") protected boolean skipBuild; + + /** + * Skip building tags + */ + @Parameter(property = "docker.skip.tag", defaultValue = "false") + protected boolean skipTag; @Override protected void executeInternal(ServiceHub hub) throws DockerAccessException, MojoExecutionException { diff --git a/src/main/java/io/fabric8/maven/docker/PushMojo.java b/src/main/java/io/fabric8/maven/docker/PushMojo.java index f38ad03a0..07f38ed55 100644 --- a/src/main/java/io/fabric8/maven/docker/PushMojo.java +++ b/src/main/java/io/fabric8/maven/docker/PushMojo.java @@ -22,7 +22,13 @@ public class PushMojo extends AbstractDockerMojo { @Parameter(property = "docker.skip.push", defaultValue = "false") private boolean skipPush; - + + /** + * Skip building tags + */ + @Parameter(property = "docker.skip.tag", defaultValue = "false") + private boolean skipTag; + @Parameter(property = "docker.push.retries", defaultValue = "0") private int retries; @@ -35,6 +41,6 @@ public void executeInternal(ServiceHub hub) throws DockerAccessException, MojoEx return; } - hub.getRegistryService().pushImages(getResolvedImages(), retries, getRegistryConfig(pushRegistry)); + hub.getRegistryService().pushImages(getResolvedImages(), retries, getRegistryConfig(pushRegistry), skipTag); } } diff --git a/src/main/java/io/fabric8/maven/docker/RemoveMojo.java b/src/main/java/io/fabric8/maven/docker/RemoveMojo.java index 9dbae2fd2..8585c6b8a 100644 --- a/src/main/java/io/fabric8/maven/docker/RemoveMojo.java +++ b/src/main/java/io/fabric8/maven/docker/RemoveMojo.java @@ -19,12 +19,12 @@ import io.fabric8.maven.docker.config.ImageConfiguration; import io.fabric8.maven.docker.service.QueryService; import io.fabric8.maven.docker.service.ServiceHub; +import io.fabric8.maven.docker.util.ImageName; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; -import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -52,7 +52,13 @@ public class RemoveMojo extends AbstractDockerMojo { @Parameter(property = "docker.removeMode") private String removeMode; - + + /** + * Skip building tags + */ + @Parameter(property = "docker.skip.tag", defaultValue = "false") + private boolean skipTag; + @Override protected void executeInternal(ServiceHub hub) throws DockerAccessException { for (ImageConfiguration image : getResolvedImages()) { @@ -61,9 +67,11 @@ protected void executeInternal(ServiceHub hub) throws DockerAccessException { if (imageShouldBeRemoved(image)) { removeImage(hub, name); - // Remove any tagged images - for (String tag: getImageBuildTags(image)){ - removeImage(hub, name + ":" + tag); + if(!skipTag) { + // Remove any tagged images + for (String tag: getImageBuildTags(image)){ + removeImage(hub, new ImageName(name, tag).getFullName()); + } } } } diff --git a/src/main/java/io/fabric8/maven/docker/service/RegistryService.java b/src/main/java/io/fabric8/maven/docker/service/RegistryService.java index e52b66580..7505f393e 100644 --- a/src/main/java/io/fabric8/maven/docker/service/RegistryService.java +++ b/src/main/java/io/fabric8/maven/docker/service/RegistryService.java @@ -37,11 +37,12 @@ public class RegistryService { * @param imageConfigs images to push (but only if they have a build configuration) * @param retries how often to retry * @param registryConfig a global registry configuration + * @param skipTag flag to skip pushing tagged images * @throws DockerAccessException * @throws MojoExecutionException */ public void pushImages(Collection imageConfigs, - int retries, RegistryConfig registryConfig) throws DockerAccessException, MojoExecutionException { + int retries, RegistryConfig registryConfig, boolean skipTag) throws DockerAccessException, MojoExecutionException { for (ImageConfiguration imageConfig : imageConfigs) { BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration(); String name = imageConfig.getName(); @@ -58,9 +59,11 @@ public void pushImages(Collection imageConfigs, docker.pushImage(name, authConfig, configuredRegistry, retries); log.info("Pushed %s in %s", name, EnvUtil.formatDurationTill(start)); - for (String tag : imageConfig.getBuildConfiguration().getTags()) { - if (tag != null) { - docker.pushImage(new ImageName(name, tag).getFullName(), authConfig, configuredRegistry, retries); + if (!skipTag) { + for (String tag : imageConfig.getBuildConfiguration().getTags()) { + if (tag != null) { + docker.pushImage(new ImageName(name, tag).getFullName(), authConfig, configuredRegistry, retries); + } } } }