Setting Up a Nexus Mirror for Maven
This tutorial assumes that you are working with a project that is already set up for use with Maven. If you are interested in using Maven with your Java project, it is highly recommended that you look at their guide.
In addition, be sure to check your application’s image for Maven mirror capabilities. Many images that use Maven have a environment variable that you can use to simplify this process. If it does not have this capability, read to configure your build properly.
Furthermore, make sure that you give each pod enough resources to function. You may have to edit the pod template in the Nexus deployment configuration to request more resources.
Download and deploy the official Nexus container image:
Use oc get routes to find the pod’s new external address.
The output should resemble:
NAME HOST/PORT PATH SERVICES PORT TERMINATION
nexus nexus-myproject.192.168.1.173.xip.io nexus 8081-tcp
This is a good time to set up . These will periodically check to see that Nexus is running properly.
Adding Persistence to Nexus
If you do not want persistent storage, continue to . However, your cached dependencies and any configuration customization will be lost if the pod is restarted for any reason. |
Create a persistent volume claim (PVC) for Nexus, so that the cached dependencies are not lost when the pod running the server terminates. PVCs require available persistent volumes (PV) in the cluster. If there are no PVs available and you do not have administrator access on your cluster, ask your system administrator to create a Read/Write Persistent Volume for you.
Otherwise, see Persistent Storage in OKD for instructions on creating a persistent volume.
Add a PVC to the Nexus deployment configuration.
$ oc set volume dc/nexus --add \
--name 'nexus-volume-1' \
--claim-name 'nexus-pv' \
--claim-size '1G' \
--overwrite
This removes the previous emptyDir volume for the deployment config and adds a claim for one gigabyte of persistent storage mounted at /sonatype-work
, which is where the dependencies will be stored. Due to the change in configuration, the Nexus pod will be redeployed automatically.
The next steps demonstrate defining a build that uses the new Nexus repository. The rest of the tutorial uses with wildfly-100-centos7 as a builder, but these changes should work for any project.
The example builder image supports as part of its environment, so we can use this to point our builder image to our Nexus repository. If your image does not support consuming an environment variable to configure a Maven mirror, you may need to modify the builder image to provide the correct Maven settings to point to the Nexus mirror.
$ oc new-build openshift/wildfly-100-centos7:latest~https://github.com/openshift/jee-ex.git \
-e MAVEN_MIRROR_URL='http://nexus.<Nexus_Project>:8081/nexus/content/groups/public'
$ oc logs build/jee-ex-1 --follow
Replace <Nexus_Project>
with the project name of the Nexus repository. If it is in the same project as the application that is using it, you can remove the <Nexus_Project>.
. .
In your web browser, navigate to http://