Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #960 Property placeholders are not interpolated when they are only thing in XML #964

Merged
merged 1 commit into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/asciidoc/inc/_implicit-properties.adoc
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions src/main/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ include::inc/_registry.adoc[]

include::inc/_authentication.adoc[]

include::inc/_implicit-properties.adoc[]

include::inc/_links.adoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public ContainerCreateConfig environment(String envPropsFile, Map<String, String
String value = entry.getValue();
if (value == null) {
value = "";
} else if(value.matches("^\\+\\$\\{.*\\}$")) {
/*
* This case is to handle the Maven interpolation issue which used
* to occur when using ${..} only without any suffix.
*/
value = value.substring(1, value.length());
}
envProps.put(entry.getKey(), StrSubstitutor.replace(value, mavenProps));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,22 @@ public void testEnvironment() throws Exception {
cc.environment(copyPropsToFile(), envMap, Collections.<String, String>emptyMap());
JSONArray env = getEnvArray(cc);
assertNotNull(env);
assertEquals(3, env.length());
assertEquals(6, env.length());
List<String> 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
public void testEnvironmentEmptyPropertiesFile() {
ContainerCreateConfig cc = new ContainerCreateConfig("testImage");
cc.environment(null, getEnvMap(),Collections.<String, String>emptyMap());
JSONArray env = getEnvArray(cc);
assertEquals(2, env.length());
assertEquals(5, env.length());
}

@Test
Expand Down Expand Up @@ -122,6 +125,9 @@ private Map<String, String> getEnvMap() {
Map<String,String> envMap = new HashMap<>();
envMap.put("JAVA_OPTS", "-Xmx512m");
envMap.put("TEST_SERVICE", "LOGGING");
envMap.put("TEST_HTTP_ADDR", "+${docker.container.consul.ip}");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add also tests where the + sign is part of a value or when there is something in addition like in +${docker.container.consul.ip}additional_data (here, there should be no removal of the +)

envMap.put("TEST_CONSUL_IP", "+${docker.container.consul.ip}:8080");
envMap.put("TEST_CONSUL_IP_WITHOUT_DELIM", "${docker.container.consul.ip}:8225");
return envMap;
}

Expand Down