Creating an application using JBoss EAP builder image

In this recipe you will learn how to create an application using source code and the JBoss EAP builder image.

Create a project or use an existing project

If you want to, you can create a new project based on what you have learned in the previous recipe. Since we already have a project we will use it. Run the following command to make sure.

$ oc project ocp-test

Create an application that uses the JBoss EAP builder image

We will be using a sample application called "Kitchensink" (https://github.com/jbosschina/kitchensink). Taking that source-code; we will use the JBoss ImageStream (or the builder image) to assemble our application.

Open the browser and select your project.

Click into Add to Project button.

In the search text box type jboss-eap70-openshift and select the latest version tag for this builder image (at the moment of creation this lab it is jboss-eap70-openshift:1.4).

Fill the fields with the following information:

Click on Create and then on Continue to overview.

Build

Give it some seconds and you will see OpenShift starts the build process for you. You can view the list of builds using oc get builds command.

$ oc get build
NAME      TYPE      FROM          STATUS    STARTED              DURATION
ks-1      Source    Git@f45d121   Running   About a minute ago

Note the name of the build that is running i.e. ks-1. We will use that name to look at the build logs. Run the command as shown below to look at the build logs. This will run for a few mins. At the end you will notice that the docker image is successfully created and it will start pushing this to OpenShift’s internal docker registry.

$ oc get pods
NAME         READY     STATUS    RESTARTS   AGE
ks-1-build   1/1       Running   0          1m

We can check the logs by executing the following command:

$ oc log pod/ks-1-build
W0709 22:06:20.421747   13246 cmd.go:337] log is DEPRECATED and will be removed in a future version. Use logs instead.
Cloning "https://github.com/jbosschina/kitchensink.git" ...
	Commit:	f45d12197481417ae6c0a6ea043fa30fd5a9d55b (update eap version to 7)
	Author:	kylin <kylinsoong.1214@gmail.com>
	Date:	Thu Jul 6 19:20:34 2017 +0800
Found pom.xml... attempting to build with 'mvn -e -Popenshift -DskipTests -Dcom.redhat.xpaas.repo.redhatga package -Djava.net.preferIPv4Stack=true '
Picked up JAVA_TOOL_OPTIONS: -Duser.home=/home/jboss -Duser.name=jboss
Using Apache Maven 3.0.5 (Red Hat 3.0.5-17)
Maven home: /usr/share/maven
Java version: 1.8.0_131, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-2.b11.el7_3.x86_64/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "3.10.0-514.el7.x86_64", arch: "amd64", family: "unix"
Picked up JAVA_TOOL_OPTIONS: -Duser.home=/home/jboss -Duser.name=jboss
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building JBoss EAP Quickstart: kitchensink 7.1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
...
2/com/thoughtworks/xstream/xstream/1.3.1/xstream-1.3.1.jar (422 KB at 5401.2 KB/sec)
[INFO] Packaging webapp
[INFO] Assembling webapp [jboss-kitchensink] in [/home/jboss/source/target/jboss-kitchensink]
[INFO] Processing war project
[INFO] Copying webapp resources [/home/jboss/source/src/main/webapp]
[INFO] Webapp assembled in [105 msecs]
[INFO] Building war: /home/jboss/source/deployments/ROOT.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:24.383s
[INFO] Finished at: Sun Jul 09 14:05:02 UTC 2017
[INFO] Final Memory: 27M/560M
[INFO] ------------------------------------------------------------------------
Copying all war artifacts from /home/jboss/source/target directory into /opt/eap/standalone/deployments for later deployment...
Copying all ear artifacts from /home/jboss/source/target directory into /opt/eap/standalone/deployments for later deployment...
Copying all rar artifacts from /home/jboss/source/target directory into /opt/eap/standalone/deployments for later deployment...
Copying all jar artifacts from /home/jboss/source/target directory into /opt/eap/standalone/deployments for later deployment...
Copying all war artifacts from /home/jboss/source/deployments directory into /opt/eap/standalone/deployments for later deployment...
'/home/jboss/source/deployments/ROOT.war' -> '/opt/eap/standalone/deployments/ROOT.war'
Copying all ear artifacts from /home/jboss/source/deployments directory into /opt/eap/standalone/deployments for later deployment...
Copying all rar artifacts from /home/jboss/source/deployments directory into /opt/eap/standalone/deployments for later deployment...
Copying all jar artifacts from /home/jboss/source/deployments directory into /opt/eap/standalone/deployments for later deployment...
Pushing image 172.30.160.227:5000/ocp-test/ks:latest ...
Pushed 0/7 layers, 1% complete
Pushed 1/7 layers, 21% complete
Pushed 2/7 layers, 34% complete
Pushed 3/7 layers, 51% complete
Pushed 4/7 layers, 82% complete
Pushed 5/7 layers, 88% complete
Pushed 6/7 layers, 98% complete
Pushed 7/7 layers, 100% complete
Push successful

You will notice that in the logs that not only does it copy your source code to the builder image, but it also does a maven build to compile your code as well. Also, in the above log, note how the image is pushed to the local docker registry. The registry is running at 172.30.160.227 at port 5000.

Deployment

Once the image is pushed to the docker registry, OpenShift will trigger a deploy process. Let us also quickly look at the deployment configuration by running the following command. Note dc represents deploymentconfig.

$ oc get dc ks -o json
{
    "apiVersion": "v1",
    "kind": "DeploymentConfig",
    "metadata": {
        "annotations": {
            "openshift.io/generated-by": "OpenShiftWebConsole"
        },
        "creationTimestamp": "2017-07-09T14:03:27Z",
        "generation": 2,
        "labels": {
            "app": "ks"
        },
        "name": "ks",
        "namespace": "ocp-test",
        "resourceVersion": "4620099",
        "selfLink": "/oapi/v1/namespaces/ocp-test/deploymentconfigs/ks",
        "uid": "6199ccfa-64af-11e7-bbc1-0682973451aa"
    },
    "spec": {
        "replicas": 1,
        "selector": {
            "deploymentconfig": "ks"
        },
        "strategy": {
            "activeDeadlineSeconds": 21600,
            "resources": {},
            "rollingParams": {
                "intervalSeconds": 1,
                "maxSurge": "25%",
                "maxUnavailable": "25%",
                "timeoutSeconds": 600,
                "updatePeriodSeconds": 1
            },
            "type": "Rolling"
        },
        "template": {
            "metadata": {
                "creationTimestamp": null,
                "labels": {
                    "app": "ks",
                    "deploymentconfig": "ks"
                }
            },
            "spec": {
                "containers": [
                    {
                        "image": "172.30.160.227:5000/ocp-test/ks@sha256:00af62a71a5fca31896c3076dd9d98cba2a7a3319c80eb67e425166e40cb9270",
                        "imagePullPolicy": "Always",
                        "name": "ks",
                        "ports": [
                            {
                                "containerPort": 8080,
                                "protocol": "TCP"
                            },
                            {
                                "containerPort": 8443,
                                "protocol": "TCP"
                            },
                            {
                                "containerPort": 8778,
                                "protocol": "TCP"
                            }
                        ],
                        "resources": {},
                        "terminationMessagePath": "/dev/termination-log"
                    }
                ],
                "dnsPolicy": "ClusterFirst",
                "restartPolicy": "Always",
                "securityContext": {},
                "terminationGracePeriodSeconds": 30
            }
        },
        "test": false,
        "triggers": [
            {
                "imageChangeParams": {
                    "automatic": true,
                    "containerNames": [
                        "ks"
                    ],
                    "from": {
                        "kind": "ImageStreamTag",
                        "name": "ks:latest",
                        "namespace": "ocp-test"
                    },
                    "lastTriggeredImage": "172.30.160.227:5000/ocp-test/ks@sha256:00af62a71a5fca31896c3076dd9d98cba2a7a3319c80eb67e425166e40cb9270"
                },
                "type": "ImageChange"
            },
            {
                "type": "ConfigChange"
            }
        ]
    },
    "status": {
        "availableReplicas": 1,
        "conditions": [
            {
                "lastTransitionTime": "2017-07-09T14:05:49Z",
                "lastUpdateTime": "2017-07-09T14:05:49Z",
                "message": "Deployment config has minimum availability.",
                "status": "True",
                "type": "Available"
            },
            {
                "lastTransitionTime": "2017-07-09T14:05:44Z",
                "lastUpdateTime": "2017-07-09T14:05:50Z",
                "message": "replication controller \"ks-1\" successfully rolled out",
                "reason": "NewReplicationControllerAvailable",
                "status": "True",
                "type": "Progressing"
            }
        ],
        "details": {
            "causes": [
                {
                    "imageTrigger": {
                        "from": {
                            "kind": "ImageStreamTag",
                            "name": "ks:latest",
                            "namespace": "ocp-test"
                        }
                    },
                    "type": "ImageChange"
                }
            ],
            "message": "image change"
        },
        "latestVersion": 1,
        "observedGeneration": 2,
        "readyReplicas": 1,
        "replicas": 1,
        "unavailableReplicas": 0,
        "updatedReplicas": 1
    }
}

Note where the image is picked from. It shows that the deployment picks the image from the local registry (same ip address and port as in buildconfig) and the image tag is the same as what we built earlier. This means the deployment step deploys the application image what was built earlier during the build step.

If you get the list of pods, you’ll notice that the application gets deployed quickly and starts running in its own pod.

$ oc get pods
NAME         READY     STATUS      RESTARTS   AGE
ks-1-9b244   1/1       Running     0          6m
ks-1-build   0/1       Completed   0          9m

Adding route

This step is very much the same as what we did in previous exercises. We will check the service and add a route to expose that service.

$ oc get service ks
NAME      CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
ks        172.30.163.207   <none>        8080/TCP,8443/TCP,8778/TCP   10m

Route should be already created.

$ oc get route
NAME      HOST/PORT                                    PATH      SERVICES   PORT       TERMINATION   WILDCARD
ks        ks-ocp-test.apps.example.com             ks         8080-tcp                 None

Run the application

Now access the application by using the route you got in the previous step. You can use either curl or your browser.

$ curl ks-ocp-test.apps.example.com

<html>
<head>
<meta http-equiv="Refresh" content="0; URL=index.jsf">
</head>
</html>

Go to https://ks-ocp-test.apps.example.com via your browser. Please replace your username with yours.

Congratulations! In this exercise you have learned how to create, build and deploy a JBoss EAP application using OpenShift’s JBoss EAP Builder Image.

results matching ""

    No results matching ""