diff --git a/src/main/asciidoc/inc/_implicit-properties.adoc b/src/main/asciidoc/inc/_implicit-properties.adoc new file mode 100644 index 000000000..815c339e4 --- /dev/null +++ b/src/main/asciidoc/inc/_implicit-properties.adoc @@ -0,0 +1,7 @@ += Implicit properties + +There are some implicit configurations in docker maven plugin that are not so straightforward. These are simply workarouds to get docker-maven-plugin's flow right; just to overcome limitations of Maven and other things. Some of these are mentioned below: + +* If the only value of the `env` parameter is a docker-maven-plugin internal property which has been set implicitly you have to prefix the property with a single `+` like in `+${docker.container.test.ip}`. This is necessary due to some Maven limitations which simply interpolates a lone, non defined property, to an empty string which can't then be replaced by this plugin after the initial interpolation phase. + +* When providing port mapping in a format like `host.ip:host.port:80`, you need to prefix property with a single `+`. In this form, the host ip of the container will be placed into a Maven property name host.ip. If docker reports that value to be 0.0.0.0, the value of docker.host.address will be substituted instead. In the event you want to use this form and have the container bind to a specific hostname/ip address, you can declare a Maven property of the same name (host.ip in this example) containing the value to use. host:port works in the same way as described above. diff --git a/src/main/asciidoc/index.adoc b/src/main/asciidoc/index.adoc index 8e4b22f17..35014a142 100644 --- a/src/main/asciidoc/index.adoc +++ b/src/main/asciidoc/index.adoc @@ -44,4 +44,6 @@ include::inc/_registry.adoc[] include::inc/_authentication.adoc[] +include::inc/_implicit-properties.adoc[] + include::inc/_links.adoc[] diff --git a/src/main/java/io/fabric8/maven/docker/access/ContainerCreateConfig.java b/src/main/java/io/fabric8/maven/docker/access/ContainerCreateConfig.java index 3ff7d0c9d..c26a823f9 100644 --- a/src/main/java/io/fabric8/maven/docker/access/ContainerCreateConfig.java +++ b/src/main/java/io/fabric8/maven/docker/access/ContainerCreateConfig.java @@ -57,6 +57,12 @@ public ContainerCreateConfig environment(String envPropsFile, MapemptyMap()); JSONArray env = getEnvArray(cc); assertNotNull(env); - assertEquals(3, env.length()); + assertEquals(6, env.length()); List envAsString = convertToList(env); assertTrue(envAsString.contains("JAVA_OPTS=-Xmx512m")); assertTrue(envAsString.contains("TEST_SERVICE=SECURITY")); assertTrue(envAsString.contains("EXTERNAL_ENV=TRUE")); + assertTrue(envAsString.contains("TEST_HTTP_ADDR=${docker.container.consul.ip}")); + assertTrue(envAsString.contains("TEST_CONSUL_IP=+${docker.container.consul.ip}:8080")); + assertTrue(envAsString.contains("TEST_CONSUL_IP_WITHOUT_DELIM=${docker.container.consul.ip}:8225")); } @Test @@ -53,7 +56,7 @@ public void testEnvironmentEmptyPropertiesFile() { ContainerCreateConfig cc = new ContainerCreateConfig("testImage"); cc.environment(null, getEnvMap(),Collections.emptyMap()); JSONArray env = getEnvArray(cc); - assertEquals(2, env.length()); + assertEquals(5, env.length()); } @Test @@ -122,6 +125,9 @@ private Map getEnvMap() { Map envMap = new HashMap<>(); envMap.put("JAVA_OPTS", "-Xmx512m"); envMap.put("TEST_SERVICE", "LOGGING"); + envMap.put("TEST_HTTP_ADDR", "+${docker.container.consul.ip}"); + envMap.put("TEST_CONSUL_IP", "+${docker.container.consul.ip}:8080"); + envMap.put("TEST_CONSUL_IP_WITHOUT_DELIM", "${docker.container.consul.ip}:8225"); return envMap; }