Docker-maven-plugin: [0.22.1] Filtering of DockerFile seems not to be working

Created on 8 Sep 2017  路  4Comments  路  Source: fabric8io/docker-maven-plugin

Configuration:

                <configuration>
                    <verbose>true</verbose>
                    <images>
                        <image>
                            <name>${docker.repository}/cheat-sheet</name>
                            <build>
                                <dockerFileDir>${project.basedir}</dockerFileDir>
                                <tags>
                                    <tag>${git.commit.id}</tag>
                                    <tag>latest</tag>
                                </tags>
                            </build>
                        </image>
                    </images>
                </configuration>`

Docker file:

FROM cogniteev/oracle-java
RUN apt-get update && apt-get install -y \
    git \
    openssh-client \
    vim
EXPOSE 8080
EXPOSE 1555
ADD ./bash-scripts /bash-scripts
ADD ./target/*.jar /
RUN chmod a+x /bash-scripts/*
ENTRYPOINT ["java", "-jar", "/${project.artifactId}-${project.version}.jar"]

Output:
[INFO] DOCKER> Step 8/8 : ENTRYPOINT java -jar /${project.artifactId}-${project.version}.jar

Most helpful comment

I have a PR for this #877.

All 4 comments

The documentation is a bit misleading:

Only properties which are set in the Maven build are replaced, all other remain untouched.

which means, only properties defined in the <properties> sections are interpolated, not the default properties set by Maven.

For you use case you should add a

<properties>
  <project.artifactId>${project.artifactId}</project.artifactId>
</properties>

to your properties sections (of course, you are free to choose another, shorter property name here, too).

It might make sense to allow all properties (also, the on implicitly set in the pom.xml, too), but that's requires an extension to the interpolation process. Pull requests welcome ;-)

I just stumbled over this: In my case we're setting a specific property via the command line, but that value isn't picked up by interpolation. Instead we get the _default_ value in the pom, so I cannot just use the above suggestion as I need to retain the default somehow. Other properties are similarly affected, so listing them explicitly is also not exactly nice.

Looking at how the maven filtering works in https://github.com/apache/maven-shared/blob/trunk/maven-filtering/src/main/java/org/apache/maven/shared/filtering/BaseFilter.java#L77 one needs to manually combine:

  1. The maven project properties (MavenProject#getProperties())
  2. The maven system properties (MavenSession#getSystemProperties())
  3. The maven user properties (MavenSession#getUserProperties())

Given the amount of places the plugin directly references mojoParameters.getProject().getProperties() I'm wondering whether the sanest approach would be to introduce a MojoProperties#getSessionProperties() helper that produces the correct properties, and then use that everywhere.

With that said, a work-around that we now will use is to manually execute the filtering of Dockerfiles into a new directory (and all non-Dockerfile content into the same directory), and then point dockerFileDir to that directory.

I think having such a utility method is a very good idea. @ankon if you feel fancy, we are accepting PRs ;-)

Actually, I'm a bit busy and as said, I think its a good idea to widen the interpolation scope, but I don't know when I would have time to implement it.

I have a PR for this #877.

Was this page helpful?
0 / 5 - 0 ratings