GithubHelp home page GithubHelp logo

nexus-ose's Introduction

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

  • Install all base images we will be using

    • Centos: centos:cetos7

    • Wildfly 8: docker.io/openshift/wildfly-81-centos

    • EAP 6: registry.access.redhat.com/jboss-eap-6/eap-openshift

  • Create a version of wildfly and EAP S2I images that will use by default the nexus instance created

  • Create a version of templates using this new S2I images

  • Create a sample application using Wildfly-nexus S2I image

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,..."

oc create -f nexus/ose3/nexus-resources.json -n ci

Nexus 3:

oc new-project ci --display-name="Continuous Integration for OpenShift" --description="This project holds all continuous integration required infrastructure, like Nexus, Jenkins,..."

oc create -f nexus/ose3/nexus3-resources.json -n ci

Nexus works better with anyuid. To enable it (as admin):

oc adm policy add-scc-to-user anyuid -z nexus -n ci

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:

  • Add to project

Add to project

  • Select Image or Template (filter with nexus) and select one of the templates (nexus-persistent or nexus-ephemeral)

Select template

  • Provide with the required parameters.

Create Nexus instance

  • Wait for deployment

Nexus application

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:

  • External DNS: nexus.apps.10.2.2.2.xip.io

  • Internal DNS: nexus.ci.svc.cluster.local

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:

oadm pod-network make-projects-global ci

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 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

oc adm policy add-scc-to-user hostaccess -z nexus -n ci

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"

oc create -f builders/wildfly-nexus/wildfly-nexus-resources.json

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"

oc create -f builders/eap-nexus/eap-nexus-resources.json

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 openshift origin project.

{
   "apiVersion": "v1",
   "kind": "ImageStream",
   "metadata": {
      "creationTimestamp": null,
      "name": "wildfly-8"
   },
   "spec": {
      "tags": [
         {
            "from": {
               "Kind": "ImageStreamTag",
               "Name": "8.1"
            },
            "name": "latest"
         },
         {
            "annotations": {
               "description": "Build and run Java applications on Wildfly 8.1",
               "iconClass": "icon-wildfly",
               "sampleRepo": "https://github.com/bparees/openshift-jee-sample.git",
               "supports": "wildfly:8.1,jee,java",
               "tags": "builder,wildfly,java",
               "version": "8.1"
            },
            "from": {
               "Kind": "DockerImage",
               "Name": "openshift/wildfly-81-centos7:latest"
            },
            "name": "8.1"
         }
      ]
   }
}
....

Also, it installs the EAP 6.4 ImageStream defined in JBoss Openshift application templates project.

TODO: Copy content here

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:

{
   "apiVersion": "v1",
   "kind": "ImageStream",
   "metadata": {
      "creationTimestamp": null,
      "name": "wildfly-nexus-8"
   },
   "spec": {
      "tags": [
         {
            "annotations": {
               "description": "Build and run Java applications on Wildfly 8.1 using Nexus",
               "iconClass": "icon-wildfly",
               "sampleRepo": "https://github.com/bparees/openshift-jee-sample.git",
               "supports": "wildfly:8.1,jee,java",
               "tags": "builder,wildfly,java,nexus",
               "version": "8.1"
            },
            "name": "latest"
         }
      ]
   }
}
...

S2I Builder images

I have created an extended version of Wildfly 8.1, Wildfly 9 and Wildfly 10 as well as 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:

{
   "kind": "BuildConfig",
   "apiVersion": "v1",
   "metadata": {
      "name": "wildfly-nexus-8"
   },
   "spec": {
      "triggers": [
         {
            "type": "GitHub",
            "github": {
               "secret": "secret"
            }
         },
         {
            "type": "Generic",
            "generic": {
               "secret": "secret"
            }
         },
         {
            "type": "ImageChange",
            "imageChange": {}
         }
      ],
      "source": {
         "type": "Git",
         "git": {
            "uri": "https://github.com/jorgemoralespou/nexus-ose",
            "ref": "master"
         },
         "contextDir": "builders/wildfly-nexus/8.1"
      },
      "strategy": {
         "type": "Docker",
         "dockerStrategy": {
            "from": {
               "kind": "ImageStreamTag",
               "name": "wildfly-8:latest"
            }
         }
      },
      "output": {
         "to": {
            "kind": "ImageStreamTag",
            "name": "wildfly-nexus-8:latest"
         }
      },
      "resources": {}
   }
}

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 EAP 6.4 Basic template.

Create a sample application

Sample Wildfly-nexus S2I image

nexus-ose's People

Contributors

garethahealy avatar jorgemoralespou avatar sabre1041 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nexus-ose's Issues

Nexus improvements

1)The deploy strategy should be changed from rolling to recreate. During rolling deployment with persistent volumes concurrent access on the same volume cause concurrent access exceptions. Additionally there is no real need for rooling
2) the post deployment hook is incorrectly structured. it should be part of the recreatePrams object
3) the command object requires two params, first on been /bin/bash

  1. Utilze the environment variable NEXUS_BASE_URL. The default of localhost will fail as the post deploy pod can land on any machine

Below is a example. DC that should function with out a issue

ind: DeploymentConfig
metadata:
annotations:
openshift.io/deployment.cancelled: "6"
creationTimestamp: null
labels:
application: nexus-persistent
name: nexus
spec:
replicas: 1
selector:
deploymentconfig: nexus
strategy:
recreateParams:
post:
execNewPod:
command:
- /bin/bash
- /usr/local/bin/addjbossrepos.sh
containerName: nexus
env:
- name: NEXUS_BASE_URL
value: http://nexus:8081
failurePolicy: Ignore
timeoutSeconds: 600
resources: {}
type: Recreate
template:
metadata:
creationTimestamp: null
labels:
deploymentconfig: nexus
spec:
containers:
- image: 172.30.57.241:5000/codefestutils/nexus-ose:latest
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
httpGet:
path: /
port: 8081
scheme: HTTP
initialDelaySeconds: 180
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
name: nexus
ports:
- containerPort: 8081
protocol: TCP
readinessProbe:
failureThreshold: 3
httpGet:
path: /
port: 8081
scheme: HTTP
initialDelaySeconds: 20
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 2Gi
requests:
memory: 1Gi
securityContext:
capabilities: {}
privileged: false
terminationMessagePath: /dev/termination-log
volumeMounts:
- mountPath: /sonatype-work
name: data
dnsPolicy: ClusterFirst
restartPolicy: Always
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
- name: data
persistentVolumeClaim:
claimName: nexus-data
test: false
triggers:

  • type: ConfigChange
    status: {}

can not build image

hi
i read your article from https://blog.openshift.com/improving-build-time-java-builds-openshift/ based on this I create project but when i create app it show following error:

Downloading "https://github.com/jorgemoralespou/nexus-ose.git" ...
Cloning source from https://github.com/jorgemoralespou/nexus-ose.git
Step 1 : FROM library/centos@sha256:ee06bb52b1fc453a72cee57b4ee4afb94d8e0aca479cd9dae5999f96e1e4f7a4
Trying to pull repository docker.io/library/centos ...
manifest unknown: manifest unknown
error: build error: manifest unknown: manifest unknown

I use openshift v1.3.0-alpha.2 ,I also test under openshift v1.2.0 ,it also show following error:

I0707 01:13:07.466654 1 builder.go:57] Master version "v1.2.0", Builder version "v1.2.0"
I0707 01:13:07.469749 1 builder.go:145] Running build with cgroup limits: api.CGroupLimits{MemoryLimitBytes:92233720368547, CPUShares:2, CPUPeriod:100000, CPUQuota:-1, MemorySwap:92233720368547}
I0707 01:13:07.471217 1 source.go:197] Downloading "https://github.com/jorgemoralespou/nexus-ose" ...
F0707 01:13:07.674656 1 builder.go:204] Error: build error: fatal: unable to access 'https://github.com/jorgemoralespou/nexus-ose/': Peer's Certificate has expired.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.