How to convert dockerfile commands to maven xml entries? - java

I am dockerizing my Java applications by maven docker plugin.
I found a simple docker-maven-plugin that creates a simple docker file..
I want to know how to convert docker file command such as ADD,COPY,VOLUME etc. in to maven xml entries ?
I mean I need to be able to customize my dockerfile through maven pom.xml
I could not find any documentations or tutorial for this ...
Thanks for your input.

Related

How to make maven install in docker container

I have a multi-module project on maven. It is quite ancient and is going with a special dance with a tambourine.
Project structure
root
|__api
|__build
|__flash
|__gwt
|__server
|__service
|__shared
|__target
|__toolset
To build such a project, I have a special script that needs to be executed while at the root of the project.
./build/build_and_deploy.sh
When building on Windows, there are a lot of problems (problems with long paths, symbols and line separators get lost, etc.), so I want to build this project in docker.
At first I wanted to connect docker-maven-plugin from io.fabric8 as a plugin in maven, but as I understand it, it cannot run the build of itself in docker.
So I tried to write Dockerfile and ran into the following problems
I don't want to copy the .m2 folder to docker, there are a lot of dependencies there, it will be quite a long time.
I don't want to copy the project sources inside the container
I couldn't run the script./build/build_and_deploy.sh
How I see the solution to this problem.
Create a dockerfile, connect maven and java8 to it, and bash
Using Volume to connect the sources and maven repository
Because I work through VPN and the script is deployed, you need to find a solution to the problem through it (proxy/port forwarding???)
If you have experience or examples of a similar script or competent advice, then I will be glad to hear it
You can perform the build with Maven inside Docker.
For that you basically trigger something like docker build ., and the rest is inside the Dockerfile.
Start off from a container that has Maven, such as maven.
Add your whole project structure
Run your build script
Save your build result
To save your build result, you might want to upload it to some repository, or store it in a mounted volume that is available after the container run as well. Alternatively copy it to the next stage if you use a multistage docker build.
If you want to prevent repeated downloads of the .m2 directory or have many other dependencies in there, also mount it as volume when running the container.

Run command line argument e.g. "apt-get install libfontconfig1" using spring-boot-maven-plugin creating docker image

I have a problem where I have a spring boot application with a docker container. In this one I need to install "libfontconfig1", because I need that somehow in my application that creates an excel file.
I don't have a dockerfile, I create the image with the spring boot maven plugin and it would be such a hassle to change my way of creating the docker image just for the sake of such a small font config file.
Any help is much appreciated! :)

Passing parameters in docker-compose and into POM

I know there is a way to pass parameters in maven through the POM.
POM MAVEN
<properties>
<webproperty> ${webproperty} </webproperty>
</properties>
COMMAND LINE WITH MAVEN
mvn install "-Dwebproperty=chrome"
I recently switched over to Docker and I was wondering if there was still a way to pass the parameters through the POM? I was looking at some examples and was wondering if I was going about it the right way.
Docker YAML
build:
image: something/webtest
environment:
- HUB_HOST=hub
browser:
- BROWSER=${BROWSER_TYPE}
COMMAND LINE WITH DOCKER
docker-compose up BROWSER_TYPE=chrome
Also will this command still work.
System.getProperty("BROWSER_TYPE");
Thanks in advance!
The pom's parameters can not be passed in out side of pom xml. I think you can use a template file to generate each pom file seperately.
I figured it out:
Add an argument in the DockerFile.
ARG BROWSER
create the command in your jenkinsfile
BROWSER=chrome docker-compose up myrun
In the docker yaml file add it to the build
environment:
HUB_HOST=hub
browser= ${BROWSER}
Add it to the java command
-Dbrowser="$browser"
Use System.getProperty("browser") to call it in your code.

setting up versions using Eclipse, Maven, Git, Jenkins and Docker

I created a Docker container whose purpose is to run a Docker image that implements a REST API. The REST API is created with Java (using the Eclipse IDE, Maven and Spring Boot). When creating a jar file, it (jar file) is titled: workserver-0.0.1-SNAPSHOT.jar
The code is commited to a Gitlab server. When this takes place, a Jenkins job is created. The Jenkins job pulls down the code from the Gitlab Repository, creates a .jar file and then goes through the actions to turn the .jar file into a Docker image (or rather a .zip version of the Docker image).
"scp" is used move the zip file to a target system - where - the .zip file is unpacked (revealing the Docker image) and a container is started. The thing is, the Docker image being used has a version of "latest" (ex: imagename:latest).
I would like to use versions in this scenario starting with Eclipse (i.e. a pom.xml file holding a target workserver-2.2.13.jar file would eventually lead to Docker image that would be named imagename:2.3.13)
I have seen here how one can assign a version number in Docker:
Adding tags to docker image from jenkins
I have also seen that one can use tags and version numbers in Git :
ex: git tag -a v2.5 -m 'Version 2.5' As mentioned above, the Maven
pom.xml file contains instructions to produce a .jar file called:
workserver-0.0.1-SNAPSHOT.jar
The system is working fine. I can commit a change in Eclipse and in a few minutes, a new version of the Docker container has been spun up on the delivery system - ready for use.
The issue I have now is setting up the version numbers.
Any guidance in this area would be greatly appreciated.
TIA
I would recommend using the fabric8io docker maven plugin to create the docker image using maven. This plugin allows you to build, run, and push docker images.
In particular, you can setup the name field in the plugin configuration to be:
<name>workserver:%l<name>
The %l will be resolved to the maven project version, which is the same as the jar version. You can run the plugin explicitly using:
mvn io.fabric8:docker-maven-plugin:build
Or you can set the packaging in the pom to be:
<packaging>docker-build</packaging>
This will build the image whenever you docker an mvn package and will push the image on mvn deploy

deploy java jar remotely during maven build

I have a small maven project that build a java jar file. I added a plugin (maven-antrun-plugin) in order to start it during maven's build phase. This also works in the build server (Continuum) which is good.
Now I would also like to copy the artifact jar to another server. What is the best way for doing that? I saw that you can make maven execute bash script, would that be a good way?
thanks!
It depends on your server and what options you have for uploading jars there. One of the options could be to use Maven Wagon plugin, which supports number of protocols, including ssh, ftp, webdaw.

Categories

Resources