Appendix A. Using a Nexus repository server on a Single-node OpenShift Cluster

While developing your cloud-native applications with Java and Maven, you may be required to build them repeatedly. You can deploy a Nexus Repository server alongside the Fabric8 Launcher tool on your Single-node OpenShift Cluster and use it to fetch artifacts from the Maven Central repository and cache them locally. This reduces the network load when building your application, and helps accelerate the build and rolling updates.

Prerequisites

  • Your Single-node OpenShift Cluster configured to use at least 4096 MiB of RAM and use the required oc CLI tool version.

    minishift delete # Delete the previous instance of Single-node OpenShift Cluster
    minishift config set memory 4096
    minishift start
    Warning

    The procedure described below works with Minishift. It has not been tested for use with CDK.

  • The Fabric8 Launcher tool deployed to your Single-node OpenShift Cluster.
  • A booster application deployed to your Single-node OpenShift Cluster.

Procedure

  1. Log in to your Single-node OpenShift Cluster instance.

    oc login https://LOCAL_OPENSHIFT_URL:PORT -u developer -p developer

    You can reuse the Docker daemon instance used by Single-node OpenShift Cluster to download the latest versions of the Nexus Docker container image.

    eval $(minishift docker-env)
    docker pull openshift/jenkins-2-centos7
    docker pull openshiftio/launchpad-jenkins-slave
    docker pull sonatype/nexus
  2. Create a new project to contain the Nexus server. You can also use the New Project button on the Web console to do this.

    oc new-project NEXUS_PROJECT_NAME
  3. Deploy the Nexus container image.

    oc new-app sonatype/nexus
  4. Expose the service route URL of the Nexus server.

    oc expose svc/nexus
  5. Attach a persistent volume claim with a minimum size of 10 GiB to the pod running your Nexus application.

    oc volumes dc/nexus --add --name 'nexus-volume-1' --type 'pvc' --mount-path '/sonatype-work/' --claim-name 'nexus-pv' --claim-size '10Gi' --overwrite
  6. Navigate to the project containing your booster application.

    oc project MY_PROJECT_NAME
  7. Define and start a new build.

    Pass in a parameter to set the value of the MAVEN_MIRROR_URL to match the service URL of your Nexus application:

    Note

    Ensure that the YAML template of the builder image you are using for your application has the MAVEN_MIRROR_URL environment variable defined. If it does not, see the Nexus documentation for instructions on configuring your build manually before proceeding.

    $ oc new-build MY_APP_NAME:latest~SCM_REPOSITORY_URL \
    -e MAVEN_MIRROR_URL='http://nexus.NEXUS_PROJECT_NAME:8081/nexus/content/groups/public'

    Nexus comes pre-configured for the Maven Central repository, but you may need other repositories for your application. To access images provided by Red Hat, add the Red Hat JBoss Middleware Early Access Maven Repository to your Nexus instance.

  8. Ensure that your new build is using Nexus to retrieve artifacts. Do one of the following:

    • Navigate to http://nexus-NEXUS_PROJECT_NAME.LOCAL_OPENSHIFT_HOSTNAME/nexus/content/groups/public to view the list of artifacts stored in your local repository.
    • Check the log output of the build:

      $ oc logs build/MY_APP_NAME-1 --follow

    If your build uses Nexus to retrieve artifacts, the build log output should reference the path http://nexus.NEXUS_PROJECT_NAME:8081/.