= Developing Java applications using a Nexus Container for maven dependencies in OpenShift Origin / OpenShift 3
This sample project demonstrates how you can use Nexus in an OpenShift environment. How you can create applications that will fetch the dependencies from your internal nexus container.
NOTE: This is a Proof of Concept. NOT SUPPORTED!!!
The steps that will be done are the following:
== Deploy a nexus container configured for accessing Red Hat's maven repository Our nexus instance will live in a project called (ci), so to start, we need to create this project and add all the required resources:
Nexus 2:
oc new-project ci --display-name="Continuous Integration for OpenShift" --description="This project holds all continuous integration required infrastructure, like Nexus, Jenkins,..."
Nexus 3:
oc new-project ci --display-name="Continuous Integration for OpenShift" --description="This project holds all continuous integration required infrastructure, like Nexus, Jenkins,..."
Nexus works better with anyuid. To enable it (as admin):
Once we have created all the nexus resources, we can go ahead and create a nexus instance. There is 2 templates for creating a Nexus instance (ephemeral and persitent) in the ci project. To create your project just go do in the ci project:
image:images/add_to_project.png[Add to project]
image:images/template.png[Select template]
image:images/instantiate.png[Create Nexus instance]
image:images/nexus_pod.png[Nexus application]
image:images/nexus_console.png[Nexus console]
NOTE: By default, nexus credentials will be admin/admin123
=== Details to know It is very important to know that the service is available through DNS internally to all other applications running in OpenShift, and externally at the provided hostname:
Also, important to understand that if OpenShift is configured with the SDN multitenant plugin, you need to allow access to this project (ci) from any other project that wants to use it, or by making the ci project global, with:
=== Defining your Persistent Volume for using nexus-persistent template If you want to create a nexus persistent instance, you need to provide with a persistent volume named: nexus-pv with ReadWriteOnce mode and the ammount of space that you wish. You can use hostPath, nfs, or any other storage. See examples link:nexus/ose3/resources/pv/[here].
As an example (in an all-in-one VM), you can do as root (cluster:admin) the following:
mkdir /tmp/nexus
chmod 777 /tmp/nexus
oc create -f - <<-EOF { "apiVersion": "v1", "kind": "PersistentVolume", "metadata": { "name": "nexus-pv", "labels": { "type": "local" } }, "spec": { "hostPath": { "path": "/tmp/nexus" }, "accessModes": [ "ReadWriteOnce" ], "capacity": { "storage": "5Gi" }, "persistentVolumeReclaimPolicy": "Retain" } } EOF
== Install new resources that will use Nexus I have provided with a file that will install all the required resources needed to work with the Nexus instance provided in the OpenShift install.
To install the Wildfly version:
oc new-project wildfly-nexus-builds --display-name="Wildfly builds with Nexus" --description="Building Applications in Wildfly using Nexus for dependency management"
To install the EAP version:
oc new-project eap-nexus-builds --display-name="EAP builds with Nexus" --description="Building Applications in EAP using Nexus for dependency management"
Following there is a description of what these files provide.
=== ImageStreams This project will load the required ImageStreams for Wildfly 8.1, Wildfly 9 and Wildfly 10 that are initially defined in the link:https://raw.githubusercontent.com/openshift/origin/master/examples/image-streams/image-streams-centos7.json[openshift origin project].
Also, it installs the EAP 6.4 ImageStream defined in link:https://raw.githubusercontent.com/jboss-openshift/application-templates/ose-v1.2.0/jboss-image-streams.json[JBoss Openshift application templates] project.
These ImageStreams provide the base images used.
We will create a new version of the S2I Builders, and for these, we also create some ImageStreams:
=== S2I Builder images I have created an extended version of link:builders/wildfly-nexus/8.1[Wildfly 8.1], link:builders/wildfly-nexus/9.0[Wildfly 9] and link:builders/wildfly-nexus/10.0[Wildfly 10] as well as link:builders/eap-nexus/6.4[EAP 6.4] images where I'm replacing the provided settings.xml file with one of my own, that will look for dependencies in the provided Nexus instance in the OpenShift environment.
We need a BuildConfig for each of the S2I images so that these images are created and pushed into the appropriate ImageStreams.
Here we can see the BuildConfig for the Wildfly 8.1 Image:
=== Templates The Wildfly images are builder Images, so you can use it directly for creating applications. On the other hand, EAP provides with some templates for different use cases that can be used. We need to provide our own version of these templates, where we'll be changing the Builder image.
As an example, here I show a changed version of the base https://raw.githubusercontent.com/jboss-openshift/application-templates/ose-v1.2.0/eap/eap64-basic-s2i.json[EAP 6.4 Basic template].
link:builders/eap-nexus/eap-nexus-resources.json#L108-L430[See the code]
== Create a sample application
=== Sample Wildfly-nexus S2I image
Content type
Image
Digest
Size
390.1 MB
Last updated
almost 10 years ago
docker pull jalammas/nexus-ose