Previous posts have described how to improve build time of Java builds on OpenShift (OpenShift blog) using a Sonatype Nexus Repository Manager (Sonatype blog).
You can now download Maven dependencies from within the OpenShift cluster using a repository manager. This dramatically speeds up the build times for JEE projects because the dependencies are local and you don't need to download them from somewhere on the internet every single time. However, we are still downloading the dependencies every time.
When using a Jenkins pipeline in an OpenShift environment, we can use dedicated Maven slave build pods to do the heavy lifting during a Maven build.
In order to further speed up the builds, we could create a customized Maven slave pod container image that already contains all of the dependencies—the problem is that this image may be out of date rather quickly if the dependencies change often.
Recent versions of Jenkins allow the addition of a volume to a slave pod definitions—and luckily, an OpenShift Persistent Volume Claim is one of the options available.
We can now create a Persistent Volume Claim in the same project that our Jenkins pod is running—because all the Maven slave pods are executed in that same project. Once we have created the Persistent Volume Claim (using a size that is sufficient for our cached repository artifacts and ReadWriteMany as the access mode) we can mount this volume into the Maven slave pods at /home/jenkins/.m2.
The first time we execute a build we now download the dependencies into our slave pod and therefore into our persistent volume. This download can happen from either the original repository locations or from a repository manager inside the firewall.
The next time we execute a build the dependencies are already in the right location; and all the pod needs to do is execute the build, therefore, decreasing build times rather dramatically.
This approach should work for both individual build pods, but because the repository is shared through the PVC, it should also work well for multiple parallel build pods. When building multiple different projects, simply make sure that the Persistent Volume Claim is big enough to hold the aggregate set of dependencies.
Here is how to set this up in Jenkins on OpenShift:
- In OpenShift go to your Jenkins project (the project where your Jenkins pod is running)
- In the navigator on the left click on Storage
- Click Create Storage
-
Use the following settings:
- Name: maven-slave-pvc
- Access Mode: Shared Access (RWX)
- Size: An appropriate size for your environment. E.g. 20 Gi.
- Click Create
-
Login to Jenkins
-
Find the
Mavenslave pod definition. -
Use the following settings for the PVC:
- Scroll all the way to the bottom of the page and click Save.
The next time you execute your pipeline in a Maven slave pod you will notice improved build times.
Note that while the author didn't experience any problems with this approach, make sure to run your own tests before deploying this approach into a production environment.
Sobre el autor
Más como éste
La paradoja agéntica y los argumentos a favor de la IA híbrida
Deja de administrar el pasado y comienza a forjar el futuro de TI
Collaboration In Product Security | Compiler
Keeping Track Of Vulnerabilities With CVEs | Compiler
Navegar por canal
Automatización
Las últimas novedades en la automatización de la TI para los equipos, la tecnología y los entornos
Inteligencia artificial
Descubra las actualizaciones en las plataformas que permiten a los clientes ejecutar cargas de trabajo de inteligecia artificial en cualquier lugar
Nube híbrida abierta
Vea como construimos un futuro flexible con la nube híbrida
Seguridad
Vea las últimas novedades sobre cómo reducimos los riesgos en entornos y tecnologías
Edge computing
Conozca las actualizaciones en las plataformas que simplifican las operaciones en el edge
Infraestructura
Vea las últimas novedades sobre la plataforma Linux empresarial líder en el mundo
Aplicaciones
Conozca nuestras soluciones para abordar los desafíos más complejos de las aplicaciones
Virtualización
El futuro de la virtualización empresarial para tus cargas de trabajo locales o en la nube