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

Property placeholders are not interpolated when they are the only thing in the XML element value #960

Closed
aaronjwhiteside opened this issue Feb 28, 2018 · 6 comments · Fixed by #964
Assignees

Comments

@aaronjwhiteside
Copy link

aaronjwhiteside commented Feb 28, 2018

Description

Property interpolation like ${docker.container.<container>.ip} only seem to work when they are adjacent to other text in the target XML element.

From the sample pom.xml:
<CONSUL_HTTP_ADDR>${docker.container.consul.ip}:8500</CONSUL_HTTP_ADDR>
Produces an environment variable of:
CONSUL_HTTP_ADDR=172.17.0.2:8500

However
<CONSUL_HTTP_ADDR>${docker.container.consul.ip}</CONSUL_HTTP_ADDR>
Just by itself produces an environment variable:
CONSUL_HTTP_ADDR=
When one would expect it to just contain: CONSUL_HTTP_ADDR=172.17.0.2

Also ${docker.container.<container>.ip} only seems to work when <link>ed with the container being referenced. If you comment out the <links> in the consul-test image, but leave the <dependsOn>, ${docker.container.consul.ip} fails to be interpolated even when other text is present in the xml element.

Info

  • d-m-p version : 0.23.0
  • Maven version (mvn -v) :
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T00:58:13-07:00)
Maven home: /opt/apache-maven-3.5.2
Java version: 1.8.0_141, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_141.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.12.6", arch: "x86_64", family: "mac"
  • Docker version :17.12.0-ce

Sample pom.xml to reproduce the problem

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>test</groupId>
    <artifactId>test</artifactId>
    <packaging>pom</packaging>
    <version>1.0.0-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.23.0</version>
                <configuration>
                    <allContainers>true</allContainers>
                    <removeVolumes>true</removeVolumes>
                    <showLogs>true</showLogs>

                    <images>
                        <image>
                            <alias>consul</alias>
                            <name>consul:1.0.6</name>
                            <run>
                                <env>
                                    <CONSUL_BIND_INTERFACE>eth0</CONSUL_BIND_INTERFACE>
                                </env>
                                <wait>
                                    <log>consul: New leader elected</log>
                                    <time>60000</time>
                                </wait>
                            </run>
                        </image>

                        <image>
                            <alias>consul-test</alias>
                            <name>consul:1.0.6</name>
                            <run>
                                <dependsOn>
                                    <container>consul</container>
                                </dependsOn>
                                <links>
                                    <link>consul</link>
                                </links>

                                <env>
                                    <!--suppress MavenModelInspection -->
                                    <!--<CONSUL_HTTP_ADDR>${docker.container.consul.ip}:8500</CONSUL_HTTP_ADDR>-->
                                    <CONSUL_HTTP_ADDR>${docker.container.consul.ip}</CONSUL_HTTP_ADDR>
                                </env>

                                <entrypoint>
                                    <shell>env</shell>
                                </entrypoint>

                                <wait>
                                    <time>60000</time>
                                    <exit>0</exit>
                                </wait>
                            </run>
                        </image>
                    </images>
                </configuration>

                <executions>
                    <!-- Start all the containers -->
                    <execution>
                        <id>start-containers</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>

                    <!-- Stop everything -->
                    <execution>
                        <id>stop-containers</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
@rhuss
Copy link
Collaborator

rhuss commented Feb 28, 2018

This sounds like an issue in StrSubstitutor as it is used in

envProps.put(entry.getKey(), StrSubstitutor.replace(value, mavenProps));

The problem with non interpolation of variables could be the startup order of containers, which is fixed when using a dependency like linking containers, but is random when not.

@aaronjwhiteside
Copy link
Author

Shouldn't <dependsOn> be the thing that determines ordering, not <links>?

@rhuss
Copy link
Collaborator

rhuss commented Feb 28, 2018

Both imply an order (as you obviously only can link to a running container), and there are even more implicite depdendencies as you can see in

public List<String> getDependencies() {
RunImageConfiguration runConfig = getRunConfiguration();
List<String> ret = new ArrayList<>();
if (runConfig != null) {
addVolumes(runConfig, ret);
addLinks(runConfig, ret);
addContainerNetwork(runConfig, ret);
addDependsOn(runConfig, ret);
}
return ret;
}

@aaronjwhiteside
Copy link
Author

OK fair enough, makes sense.

But I would expect that all the properties for a container be available when only dependsOn is used... Would you like me to open a separate ticket for this?

@aaronjwhiteside aaronjwhiteside changed the title Property placeholders don't work when they are the only thing in the XML element value Property placeholders are not interpolated when they are the only thing in the XML element value Mar 1, 2018
@rhuss
Copy link
Collaborator

rhuss commented Mar 1, 2018

Yes, agreed. I think its good enough to have this ticket and fix both issues simultaneously. Unfortunately, I'm quite busy these days, so can't promise when to work on it.

@rohanKanojia would this issue something for you to start with? I don't think its overly complicated and relatively clearly defined. Happy to help of course :)

@rohanKanojia rohanKanojia self-assigned this Mar 1, 2018
rohanKanojia added a commit to rohanKanojia/docker-maven-plugin that referenced this issue Mar 6, 2018
…hey are only thing in XML

Somehow these ${...} parameters are not being picked up by maven
properly when used solely without any suffix string literal, the maven
parameter string comes off as NULL. So adding a workaround for this.
We'll use +${...} as a parameter which would be handled by dmp afterwards
rohanKanojia added a commit to rohanKanojia/docker-maven-plugin that referenced this issue Mar 6, 2018
…hey are only thing in XML

Somehow these ${...} parameters are not being picked up by maven
properly when used solely without any suffix string literal, the maven
parameter string comes off as NULL. So adding a workaround for this.
We'll use +${...} as a parameter which would be handled by dmp afterwards
rohanKanojia added a commit to rohanKanojia/docker-maven-plugin that referenced this issue Mar 28, 2018
…hey are only thing in XML

Somehow these ${...} parameters are not being picked up by maven
properly when used solely without any suffix string literal, the maven
parameter string comes off as NULL. So adding a workaround for this.
We'll use +${...} as a parameter which would be handled by dmp afterwards
rohanKanojia added a commit to rohanKanojia/docker-maven-plugin that referenced this issue Mar 29, 2018
…hey are only thing in XML

Somehow these ${...} parameters are not being picked up by maven
properly when used solely without any suffix string literal, the maven
parameter string comes off as NULL. So adding a workaround for this.
We'll use +${...} as a parameter which would be handled by dmp afterwards
@rhuss rhuss closed this as completed in #964 Apr 3, 2018
rhuss added a commit that referenced this issue Apr 3, 2018
Fixes #960 Property placeholders are not interpolated when they are only thing in XML
@aaronjwhiteside
Copy link
Author

Does this also fix the container ordering issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants