Hello,
Let me say it's a great project and it's a real pleasure to use in our development life cycle.
However, I'm having a hard time with one particular use case. I'm not particular sure whether it's the right place to ask question. Please forward me to right place if it is not.
The question:
How does one use properly maven resource filtering capability? I've found mentioning of assembly filter flag in some other issues. I've tried, but I kinda failed / didn't like the result.
Let me explain my use case first:
ADD-ing some configuration file from src/main/dockerWhat I've tried:
<fileSet>, which took the original file and placed it somewhere attarget/docker/registry-xyz.com/artifact/0.0.1-SNAPSHOT/build/maven/home/username/path1/path2/target/docker/registry-xyz.com/artifact/0.0.1-SNAPSHOT/build/maven/MY_FILEI'm struggling to find the proper workaround and come up with concise and clear configuration snippet to get it done.
Any suggestions, maybe some links to examples or documentation etc ... I would really appreciate that...
First of all thanks for using d-m-p :)
Currently filtering is not supported yet when using Dockerfiles directly (see #205 which should be implemented soon).
For an asemmbly <files> this should work however when setting the property filtered. The target in this fileset should be relative to the specified basedir within the Docker container (not somewhere below target).
The following snippet is not tested but should you make the usage clear:
<files>
<file>
<source>src/main/docker/app.properties</source>
<outputDirectory>/</outputDirectory>
<filtered>true</filtered>
</file>
</files>
This will put an app.properties filtered into the top-level dir, which is the assemblies basedir (/maven in the target image by default).
Does this answer your question ?
Thanks, it helps a lot.
First of all I got one more idea to try, second I got the place to look for updates regarding this use case (the issue you have so kindly linked).
Thanks. I will close this issue as dup for linked issue.
This is a snippet from our pom that uses a Dockerfile to generate the image; The docker file has maven replacement properties in the FROM line
FROM ${docker.rc.registry.host}/${docker.tomcat.namespace}:${tomcat.base.image.tag}
Each of the ${} is replaced by maven when copying the resource to the build directory, target. The target folder set is then used as input to building the image.
Chris Snider
Senior Software Engineer
Intelligent Software Solutions, Inc.
[Description: Description: Description: cid:[email protected]]
From: Roland Huß [mailto:[email protected]]
Sent: Monday, November 16, 2015 12:41 PM
To: rhuss/docker-maven-plugin [email protected]
Subject: Re: [docker-maven-plugin] Question: how to use maven resource filtering? (#330)
First of all thanks for using d-m-p :)
Currently filtering is not supported yet when using Dockerfiles directly (see #205https://github.com/rhuss/docker-maven-plugin/issues/205 which should be implemented soon).
For an asemmbly
The following snippet is not tested but should you make the usage clear:
<file>
<source>src/main/docker/app.properties</source>
<outputDirectory>/</outputDirectory>
<filtered>true</filtered>
</file>
This will put an app.properties filtered into the top-level dir, which is the assemblies basedir (/maven in the target image by default).
Does this answer your question ?
—
Reply to this email directly or view it on GitHubhttps://github.com/rhuss/docker-maven-plugin/issues/330#issuecomment-157147260.
Hi @leonardinius @vberruchon,
below is my answer (similar to @chris-snider):
First, let's make sure our plugin versions are properly defined in the <pluginManagement> section:
<build>
...
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.jolokia</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.13.7</version>
<configuration>
<verbose>true</verbose>
</configuration>
</plugin>
</plugins>
</pluginManagement>
...
</build>
Step 1: setup maven-resources-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>filter-dockerfiles</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<resources>
<!-- # Filtered Resources -->
<resource>
<directory>${project.basedir}/src/main/docker</directory>
<filtering>true</filtering>
<includes>
<include>Dockerfile</include>
</includes>
</resource>
<!-- # Unfiltered Resources -->
<resource>
<directory>${project.basedir}/src/main/docker</directory>
<filtering>false</filtering>
<excludes>
<exclude>Dockerfile</exclude>
</excludes>
</resource>
</resources>
<outputDirectory>${project.build.directory}/docker</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Note: the <outputDirectory>${project.build.directory}/docker</outputDirectory> is important for 2 reasons a) when you do custom resource filtering you should always send the filtered (modified) resource to the build output directory (${project.build.directory}) as good practice, and b) this acts as the Dockerfile input for the Docker maven plugin below
Step 2: setup docker-maven-plugin:
<plugin>
<groupId>org.jolokia</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<images>
<image>
<name>${docker.image.name}:${project.version}</name>
<alias>${project.artifactId}</alias>
<build>
<assembly>
<dockerFileDir>${project.build.directory}/docker</dockerFileDir>
</assembly>
</build>
</image>
</images>
</configuration>
<executions>
<execution>
<id>build-docker-image</id>
<goals>
<goal>build</goal>
</goals>
<phase>package</phase>
</execution>
<execution>
<id>push-docker-image</id>
<goals>
<goal>push</goal>
</goals>
<phase>deploy</phase>
</execution>
</executions>
</plugin>
You can now add Maven variable interpolation ${...} inside your src/main/docker/Dockerfile, for example I do something like:
FROM ${docker.repo}/${docker.groupId}/base:${project.version}
MAINTAINER ${docker.maintainer}
...
using properties such as:
<properties>
<docker.repo>docker.example.com</docker.repo>
<docker.groupId>example</docker.groupId>
<docker.artifactId>${project.artifactId}</docker.artifactId>
<docker.image.name>${docker.repo}/${docker.groupId}/${docker.artifactId}</docker.image.name>
<docker.maintainer>"Example Engineering" <[email protected]></docker.maintainer>
</properties>
Setting <dockerFileDir>${project.build.directory}/docker</dockerFileDir> makes my build fail with Execution docker of goal io.fabric8:docker-maven-plugin:0.15.16:build failed: A tar file cannot include itself. probbably beacuse it causes the docker-build.tar to reference itself. When I open the tar it has a Dockerfile at root, a maven directory, and a directory structure corresponding to the docker repository with tmp, build and work folders.
Most helpful comment
Hi @leonardinius @vberruchon,
below is my answer (similar to @chris-snider):
First, let's make sure our plugin versions are properly defined in the
<pluginManagement>section:Step 1: setup
maven-resources-plugin:Note: the
<outputDirectory>${project.build.directory}/docker</outputDirectory>is important for 2 reasons a) when you do custom resource filtering you should always send the filtered (modified) resource to the build output directory (${project.build.directory}) as good practice, and b) this acts as theDockerfileinput for the Docker maven plugin belowStep 2: setup
docker-maven-plugin:You can now add Maven variable interpolation
${...}inside yoursrc/main/docker/Dockerfile, for example I do something like:using properties such as: