Cannot find 'dockerFileDir' in class io.fabric8.maven.docker.config.ImageConfiguration - docker

I am building docker through fabric8 maven plugin. I am getting the below error when build mvn clean package docker:build
Unable to parse configuration of mojo io.fabric8:docker-maven-plugin:0.21.0:build for parameter dockerFileDir: Cannot find 'dockerFileDir' in class io.fabric8.maven.docker.config.ImageConfiguration -> [Help 1]
Plugin configuration
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.21.0</version>
<configuration>
<dockerHost>unix:///var/run/docker.sock</dockerHost>
<verbose>true</verbose>
<images>
<image>
<name>${docker.image.prefix}/${docker.image.name}</name>
<dockerFileDir>{project.basedir}/src/main/docker/</dockerFileDir>
<!--copies artifact to docker build dir in target-->
<assembly>
<descriptorRef>artifact</descriptorRef>
</assembly>
<tags>
<tag>latest</tag>
<tag>${project.version}</tag>
</tags>
</image>
</images>
</configuration>
</plugin>
Anyone help me about this issue
Thanks in Advance

dockerFileDir as well as tags should be within build tag:
<image>
<name>${docker.image.prefix}/${docker.image.name}</name>
<build>
<dockerFileDir>{project.basedir}/src/main/docker/</dockerFileDir>
<tags>
<tag>latest</tag>
<tag>${project.version}</tag>
</tags>
</build>
....
</image>

Related

Docker cp maven package into running container by maven

For local development I'd like to copy a maven war package into a docker container right after mvn package has created the package. How can I accomplish this?
My workflow as of right now is with a specific dockerid:
$ mvn clean package
$ docker cp the.war dockerid:/usr/local/tomcat/webapps/the.war
A Tomcat server in the docker container recognizes the new war and starts again.
I tried adding the maven-antrun-plugin. However, the war is not deployed, whether I use it in the install or package phase. I get no error or warning with e.g. mvn clean package. However, the.war file is not copied into the docker container.
Below the dockerid is hardcoded momentarily.
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.jdk>1.8</version.jdk>
<version.maven.compiler>3.6.1</version.maven.compiler>
...
</properties>
...
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
</dependency>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<exec executable="docker">
<arg value="cp"/>
<arg value="${basedir}/target/the.war"/>
<arg value="dockerid:/usr/local/tomcat/webapps/the.war"/>
</exec>
</target>
</configuration>
</execution>
</executions>
</plugin>

Building docker image locally with Jib

I am trying to build docker image locally with Jib for project but am stuck at this issue. Can some one help me to find the solution?
This is the plugin i used in pom.xml
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<from>
<image>openjdk:16</image>
</from>
<container>
<ports>
<port>8080</port>
</ports>
<format>OCI</format>
</container>
</configuration>
</plugin>
jib-maven-plugin calls methods of com.google.common.base.Preconditions provided by Guava. It seems that for some reason, the runtime classpath for jib-maven-plugin has an old version of Guava. (This can happen, for example, if you have another plugin that pulls in an old version.)
You can force a specific version for a plugin runtime classpath. Here's an example:
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>3.1.4</version>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>30.1.1-jre</version>
</dependency>
</dependencies>
<configuration>
(BTW, I'm using the latest Jib 3.1.4 and the corresponding Guava version.)

Jib - where to copy webapp folder inside image?

I am creating docker image using google's Jib maven plugin, image gets created successfully and backend services are working fine but my webapp folder is not part of that image. Before jib i was creating a zip containing everything (including webapp folder in the root of that zip along with executable jar) which was working fine.
Now the image created by jib has classes, libs, resources in the app root. How and where should i copy webapp folder ?
It worked for me by using external directories provided by maven jib plugin.
<extraDirectories>
<paths>
<path>webapp</path>
<path>
<from>webapp</from>
<into>/app/webapp</into>
</path>
</paths>
</extraDirectories>
I am currently using running a spring-boot version 2.4.10 and the application is packed as a jar.
My project have JSPs at:
src/main/webapp/WEB-INF/jsp
This is important because it allows me to run the application as an executable jar: java -jar ./target/app.jar --spring.profiles.active=prod
jib-plugin doesn't copy the src/main/webapp directory to the container image by default, so we need to add it manually by including the following configuration.
<extraDirectories>
<paths>
<path>
<from>src/main/webapp/WEB-INF</from>
<into>/app/resources/META-INF/resources/WEB-INF</into>
</path>
</paths>
</extraDirectories>
I provide jib-plugin a custom entrypoint.sh
The entrypoint.sh is located at src/main/jib
#!/bin/sh
echo "The application will start in ${APPLICATION_SLEEP}s..." && sleep ${APPLICATION_SLEEP}
exec java ${JAVA_OPTS} -noverify -XX:+AlwaysPreTouch \
-Djava.security.egd=file:/dev/./urandom -cp /app/resources/:/app/classes/:/app/libs/* \
"com.demo.application.Application" "$#"
My final jib-plugin configuration is the following:
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>${jib-maven-plugin.version}</version>
<configuration>
<from>
<image>adoptopenjdk:11-jre-hotspot</image>
</from>
<to>
<image>myprivateregistry/app/${project.name}</image>
<tags>
<tag>latest</tag>
<tag>${project.version}</tag>
</tags>
</to>
<container>
<entrypoint>
<shell>bash</shell>
<option>-c</option>
<arg>/entrypoint.sh</arg>
</entrypoint>
<ports>
<port>8080</port>
</ports>
<environment>
<SPRING_OUTPUT_ANSI_ENABLED>ALWAYS</SPRING_OUTPUT_ANSI_ENABLED>
<APPLICATION_SLEEP>0</APPLICATION_SLEEP>
</environment>
<creationTime>USE_CURRENT_TIMESTAMP</creationTime>
</container>
<extraDirectories>
<paths>
<path>src/main/jib</path>
<path>
<from>src/main/webapp/WEB-INF</from>
<into>/app/resources/META-INF/resources/WEB-INF</into>
</path>
</paths>
<permissions>
<permission>
<file>/entrypoint.sh</file>
<mode>755</mode>
</permission>
</permissions>
</extraDirectories>
</configuration>
<!-- Make JIB plugin run during the packing life cycle -->
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
The above didn't work for me but the below did.
<extraDirectories>
<paths>
<path>
<from>../path/to/frontend/app/dist</from>
<into>/app/resources/static</into>
</path>
</paths>
</extraDirectories>

Maven(pom.xml) do not run a plugin during deploy/install phase

If I have a pom.xml with the following code:
<build>
<plugins>
<plugin>
<groupId>something</groupId>
<artifactId>XXX</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
...
</configuration>
</execution>
</executions>
</plugins>
</build>
When I run mvn clean package, I want to run that plugin(which actually runs).
but
If I run mvn clean deploy, given phase package is previous to phase deploy is gonna run either(which I don't want to).
Is there any way to not run this plugin during deploy?
By the way: I cannot modify the mvn command executed, I need to do this inside the pom.xml file
The only way that I know to selectively enable a plugin is through Maven profile:
<project ...>
...
<build>
...
</build>
<profiles>
<profile>
<id>someprofile</id>
<build>
<plugins>
<plugin>
<groupId>something</groupId>
<artifactId>XXX</artifactId>
...
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
You would then run mvn package -Psomeprofile to run the plugin, or mvn deploy to not run it.
There are additional ways to automatically activate a profile. You will have to read the docs to see if any of those apply to you.

Docker-maven-plugin PostgreSQL - create new database and apply Flyway migrations

I want to use docker-maven-plugin to deploy PostgreSQL container and run some integration tests over it.
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.20.0</version>
<executions>
<execution>
<id>prepare-it-database</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<images>
<image>
<name>postgres:9.5.4</name>
<alias>it-database</alias>
<run>
<ports>
<port>it-database.port:5432</port>
</ports>
<wait>
<log>database system is ready to accept connections</log>
<time>20000</time>
</wait>
</run>
</image>
</images>
</configuration>
</execution>
</executions>
</plugin>
Is it possible to run another goal (mvn e.g. flyway:migrate) from this plugin?
No, this plugin does not execute other Maven plugins (and very few do that).
What you need to do is to bind d-m-p's start goal to pre-integration-test, and then also bind flyway plugin to pre-integration-test Maven phase.

Resources