Save Multiple docker images into one tar.gz file with maven fabric8 plugin - fabric8

We are using io.fabric8:docker-maven-plugin:0.27.2 to build docker images.
my maven project consist of 3 modules (module1, module2 and module3). Each module builds a docker image based on the dockerfile present within each module.
Now, when I run mvn docker:save - I want to save all 3 docker images into one tar.gz file, myproject-1.0.0.tar.gz. Is it even possible with this plugin?
My Project Structure:
project
|-module1
|-DockerFile1
|-pom.xml
|-module2
|-DockerFile2
|-pom.xml
|-module3
|-DockerFile3
|-pom.xml
|-pom.xml
I'm using io.fabric8:docker-maven-plugin:0.27.2
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.27.2</version>
. . .
Any help is greatly appreciated!

You can save all images independly and then use maven assembly plugin to pack them in one file.
According to the documentation: you can save only one image in archive using this plugin. But you can execute docker:save for all needed images (it will create a few archives). And than assemble them.

Related

Maven. Exclude some file from uploading to local repository

I am creating an AWS Lambda package using maven-assembly-plugin. It generates several ZIP files in the target directory.
The Maven Plugin maven-install-plugin uploads all the JAR and ZIP files located in target subdirectory every time I deploy the project. These files are quite heavy. I don't need them in the local repository.
Is the a way to exclude them from uploading to local repository.
You can set the <skip> parameter of the maven install plugin to true. You do this in the <configuration> section of the plugin definition.

Including a maven artifact in Dockerfile

We have a requirement to include a maven artifact (a jar file) in a Dockerfile. This jar file is used an as argument in the run command of our application. What is the correct way of copying a maven artifact in the Dockerfile which does not exist in the build directory and only exists in the local maven repo? I have found that since maven artifacts wont be in the build context, the only way to copy it is from the .m2 directory of the container (.m2 directory contains all the maven artifacts). Is that correct or is there a better way?
Thanks
You can do that by copying the jar to your image when creating it.
here's an example. Assuming you wanna using the Quava jar, and it is already listed as a dependency in your POM.
Create Makefile in your root project (where you have your POM.xml),
create_image: Dockerfile build
docker build . -t myimage:mytag
build: POM.xml
mvn clean install
Create Dockerfile in the same directory:
FROM centos
COPY ~/.m2/repository/com/google/guava/14.0.1/guava.jar /
CMD ["sh run.sh", "/quava.jar']
and simply create your image using:
make create_image

Location of POM file in multi-module project for use in Maven Deploy Plugin

I have a multi-module Gradle project (which generates 3 artifacts per module, the sources, javadoc, and main jar). I need to generate a .pom file for my project for use with the Maven Deploy Plugin which is installed on an image that Gitlab CI uses. I have a (WIP) script which generates a .pom file with gradle, but I'm unsure of exactly where or how many .pom files I need for all of my modules.
Questions:
Where exactly should I be generating a .pom file(s) so that the
Maven Deploy Plugin can see it when I run mvn deploy:deploy in the
Gitlab yaml file?
Do I need a separate .pom file for each group of module artifacts?
Any help would be appreciated! Especially some sort of example of someone generating a .pom file with Gradle and then deploying with the Gitlab CI.

Does a Maven packaging type `docker` exists?

I am trying to figure out how to build Docker images as part of the Maven build process. Basically, I want to create a Maven project which builds a Docker image. I think this makes sense.
But what should the packaging type look like? It's obviously not jar, war or maven-plugin. I tried with docker but that does not exist.
Should I just go for pom or is there a way to configure custom package types?
Having it at pom feels wrong to me, as we are producing an output - a Docker image - which is usually not the case in regular pom types (parent pom, bom, ...).
Wow that's ambitious! When you say you want to build a docker image using Maven, I'm assuming you won't be using docker build or other docker commands to generate the final image. Docker images are TAR files so you can use the Maven Assembly plugin to generate the desired tar-file image.
In this case, your project's "type" would be "pom" so that the project itself generates a POM file containing the information about how it was built (such as name and version number). The Assembly plugin will also generate and attach the corresponding TAR file so that when you use mvn deploy or other commands which reference the package, the associated TAR file will be included.
If you are using docker commands to build the images then you are probably going to have to write a custom Maven extension -- depending on what you want to happen when you run mvn deploy. It really depends on your ultimate goal but if you are using this within the confines of Docker then you might do better with a plugin like dockerfile-maven which will allow your build to drive the docker workflow of docker build and/or docker push.
Spotify has created a dockerfile-maven-plugin that allows you to build and publish Docker images with maven. There is an example and lots of other useful info on the project page.
Of today, there's a Maven docker plugin that enables <packaging>docker</packaging>, here:
https://github.com/fabric8io/docker-maven-plugin
Doc here:
https://dmp.fabric8.io/
But take care to specify <extensions>true</extensions>!

Maven multi-module project - copying all dependencies into a single tar.gz

I'm looking to pull all of the dependencies from each module of my maven project and stick them into a single tar.gz file using the maven-assembly-plugin.
I currently have a pom setup as a parent to all of the modules. My idea was to use the maven-dependency-plugin to copy all of the dependencies to a single folder in the parents directory however when i use
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
The dependencies are copied into the modules build directory. Is there any way to set this output directory to one inside the parent project?
You are going at it the wrong way.
Instead of creating this archive inside the parent POM, you should create another module which will be responsible for creating it. This new module will have dependencies on all the other modules.
To create the archive, you need to use the maven-assembly-plugin. I strongly suggest that you read Chapter 8. Maven Assemblies of the Maven book to get you started with using assemblies. Basically, an assembly is created with the help of an assembly descriptor. In your case, you will need to configure this descriptor to use the tar.gz format.

Resources