diff --git a/src/main/asciidoc/inc/_image-configuration.adoc b/src/main/asciidoc/inc/_image-configuration.adoc index e19498d27..05320354a 100644 --- a/src/main/asciidoc/inc/_image-configuration.adoc +++ b/src/main/asciidoc/inc/_image-configuration.adoc @@ -13,4 +13,13 @@ Either a `` or `` section must be present (except when you are using include::image/_example.adoc[] +When using Maven profiles, it can be useful to override settings +of a particular image. To facilitate this, the element `` +can be used alongside the `` element. Each entry in `` +translates to an image configuration where the **alias** of the image +is set to the map entry's **key**. The examples above and below produce +identical image configurations. + +include::image/_example_imagesMap.adoc[] + include::image/_naming.adoc[] diff --git a/src/main/asciidoc/inc/image/_example_imagesMap.adoc b/src/main/asciidoc/inc/image/_example_imagesMap.adoc new file mode 100644 index 000000000..dce24e8a2 --- /dev/null +++ b/src/main/asciidoc/inc/image/_example_imagesMap.adoc @@ -0,0 +1,15 @@ + +.Example +[source,xml] +---- + + .... + + + %g/docker-demo:0.1 + .... + .... + + + +---- diff --git a/src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java b/src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java index c5b2c252e..bae1df990 100644 --- a/src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java +++ b/src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java @@ -4,8 +4,10 @@ import java.io.IOException; import java.util.Date; import java.util.List; +import java.util.Map; import java.util.Properties; +import com.google.common.collect.ImmutableList; import io.fabric8.maven.docker.access.DockerAccess; import io.fabric8.maven.docker.access.ExecException; import io.fabric8.maven.docker.config.BuildImageConfiguration; @@ -181,6 +183,12 @@ public abstract class AbstractDockerMojo extends AbstractMojo implements Context @Parameter private List images; + /** + * Image configurations configured via maps to allow overriding. + */ + @Parameter + private Map imagesMap; + // Docker-machine configuration @Parameter private DockerMachineConfiguration machine; @@ -216,7 +224,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { LogOutputSpecFactory logSpecFactory = new LogOutputSpecFactory(useColor, logStdout, logDate); - ConfigHelper.validateExternalPropertyActivation(project, images); + ConfigHelper.validateExternalPropertyActivation(project, getAllImages()); DockerAccess access = null; try { @@ -324,7 +332,7 @@ private String initImageConfiguration(Date buildTimeStamp) { // Resolve images resolvedImages = ConfigHelper.resolveImages( log, - images, // Unresolved images + getAllImages(), // Unresolved images new ConfigHelper.Resolver() { @Override public List resolve(ImageConfiguration image) { @@ -417,6 +425,22 @@ protected LogDispatcher getLogDispatcher(ServiceHub hub) { return dispatcher; } + private ImmutableList getAllImages() { + ImmutableList.Builder allImages = ImmutableList.builder(); + if (images != null) { + allImages.addAll(images); + } + if (imagesMap != null) { + imagesMap.forEach((alias, config) -> { + if (config.getAlias() == null) { + config.setAlias(alias); + } + allImages.add(config); + }); + } + return allImages.build(); + } + public ImagePullManager getImagePullManager(String imagePullPolicy, String autoPull) { return new ImagePullManager(getSessionCacheStore(), imagePullPolicy, autoPull); } diff --git a/src/main/java/io/fabric8/maven/docker/config/ImageConfiguration.java b/src/main/java/io/fabric8/maven/docker/config/ImageConfiguration.java index 361be452a..5fc162556 100644 --- a/src/main/java/io/fabric8/maven/docker/config/ImageConfiguration.java +++ b/src/main/java/io/fabric8/maven/docker/config/ImageConfiguration.java @@ -77,6 +77,10 @@ public String getAlias() { return alias; } + public void setAlias(String alias) { + this.alias = alias; + } + public String getStopNamePattern() { return stopNamePattern; }