Author Archive

Continuous Integration on OpenShift using Jenkins

Hi,

In this article we will discuss about Continuous Integration. What it is? Why to use it? and how to integrate the this model on OpenShift.

While working on a code change, a developer takes a copy of the current code base on which to work. As other developers submit changed code to the source code repository, this copy gradually does not reflect the repository code. There may be addition/removal of new/old libraries and resources, that the developer may not be aware of and can result in potential conflicts.

The longer a branch of code remains checked out, the greater the risk of multiple integration conflicts and failures becomes when it is reintegrated into the main line. When developers submit code to the repository they must first update their code to reflect the changes in the repository since they took their copy. The more changes the repository contains, the more work developers must do before submitting their own changes. In a worst-case scenario, developers may have to discard their changes and completely redo the work.

Continuous integration involves integrating early and often, so as to avoid above issues. The practice aims to reduce rework and thus reduce cost and time. With CI each programmer must do a complete build and run (and pass) all unit tests before submitting their work. Integration tests are usually run automatically on a CI server when it detects a new commit.

Lets see how we can use jenkins on Openshift :

Step-1 :

We will create an application using jbossas-7 web cartridge with jenkins enabled. This will eventually create two applications in your OpenShift account, one as jenkins and one as your app.

$ rhc app create -a $application name -t jbossas-7 –enable-jenkins

for example :

..
[userone@userone OpenShift]$ rhc app create -a testjenkins -t jbossas-7 --enable-jenkins
Password: ********

Creating application: jenkins in userone
Now your new domain name is being propagated worldwide (this might take a minute)...
Confirming application 'jenkins' is available:  Success!

jenkins published:  http://jenkins-userone.rhcloud.com/
git url:  ssh://0b514430c6c24688aa0475d34cfe8a95@jenkins-userone.rhcloud.com/~/git/jenkins.git/

Jenkins created successfully.  Please make note of these credentials:

   User: admin
   Password: CgyLzMVUzVg3

Note:  You can change your password at: https://jenkins-userone.rhcloud.com/me/configure

Creating application: testjenkins in userone
Now your new domain name is being propagated worldwide (this might take a minute)...
Warning: Permanently added the RSA host key for IP address '23.22.145.126' to the list of known hosts.
Now embedding the jenkins client into 'testjenkins'...
Confirming application 'testjenkins' is available:  Success!

testjenkins published:  http://testjenkins-userone.rhcloud.com/
git url:  ssh://2483a237b65e44cf932d1e6ecc49f047@testjenkins-userone.rhcloud.com/~/git/testjenkins.git/
Successfully created application: testjenkins
..

Note : Make sure to save the credentials for Jenkins server.

Step-2 :

Log in to Jenkins console by navigating to : https://jenkins-yourdomain name.rhcloud.com/

You will see a build with your application name.

jenkins_build

Step-3 :

Now open a terminal on your local machine and navigate to the directory from where you ran Step-1. There will be a directory with your application name.

$ cd testjenkins/deployments

Now put a sample application (war/ear) inside it. You can also put an exploded war/ear but just make sure to create an empty file as “yourapplication.war.dodeploy”.

for eg :

..
[userone@userone deployments]$ pwd
/home/userone/Studies/OpenShift/testjenkins/deployments
[userone@userone deployments]$ ls -ltra
total 12
-rw-rw-r--. 1 userone userone    0 Jul 21 12:47 .gitkeep
drwxr-xr-x. 6 userone userone 4096 Jul 21 12:47 ..
-rw-rw-r--. 1 userone userone    0 Jul 21 13:05 PostDataDemo.war.dodeploy
drwxrwxr-x. 3 userone userone 4096 Jul 21 13:05 .
drwxrwxr-x. 4 userone userone 4096 Jul 21 13:07 PostDataDemo.war
..

Step-4 :

Now push the changes to OpenShift repository :

$ cd $yourappdir

$ git add .

$ git commit -a -m “my first commit”

$ git push

Once we push the changes you will see a build is getting scheduled on Jenkins server and you can track it from Jenkis console (mentioned in Step-2)

for eg:

..
[userone@userone testjenkins]$ git add .


[userone@userone testjenkins]$ git commit -a -m "unexploded commit"
[master e08e8bc] unexploded commit
 6 files changed, 49 insertions(+), 0 deletions(-)
 delete mode 100644 deployments/PostDataDemo.war
 create mode 100644 deployments/PostDataDemo.war.dodeploy
 create mode 100644 deployments/PostDataDemo.war/META-INF/MANIFEST.MF
 create mode 100644 deployments/PostDataDemo.war/WEB-INF/web.xml
 create mode 100644 deployments/PostDataDemo.war/index.jsp
 create mode 100644 deployments/PostDataDemo.war/logout.jsp
 create mode 100644 deployments/PostDataDemo.war/test.jsp


[userone@userone testjenkins]$ git push
Counting objects: 14, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (11/11), 1.25 KiB, done.
Total 11 (delta 1), reused 0 (delta 0)
remote: Executing Jenkins build.
remote: 
remote: You can track your build at https://jenkins-userone.rhcloud.com/job/testjenkins-build
remote: 
remote: Waiting for build to schedule....Done
remote: Waiting for job to complete.........................................................Done
remote: SUCCESS
remote: New build has been deployed.
To ssh://2483a237b65e44cf932d1e6ecc49f047@testjenkins-userone.rhcloud.com/~/git/testjenkins.git/
   8e4fe25..e08e8bc  master -> master
..

From console you can see :

The build is successful.

Step-5 :

Now try to access your application. Just make sure if you have given a context root for your application you need to add it in front of your openshift app url. for eg :

http://testjenkins-userone.rhcloud.com/PostDataDemo/

where “PostDataDemo” was context root of my application.

So from here you can make changes in any part of your code and just follow step-4. If by any chance there are any issues in code or build fails.. need not to worry as when build fails the content will not be deployed and hence won’t affect your running application.

In case of any issue, you can tail jenkins or application logs, using below command :

$ rhc app tail -a jenkins

$ rhc app tail -a $yourapplication name

Also you can check Jenkins build console output, by logging in Jenkins server from browser.

You can always tweak in your Jenkins configuration to have added functionalities. 🙂

Regards,
MiddlewareMagic Team 🙂


Web Aliasing in OpenShift

Hi,

In this article we will discuss about aliasing our application on OpenShift. A website alias is a way to link one domain name to another or in siple words.. a website alias is a nickname for a website.

For eg: The domains mytest.net and mytest.com have been registered by a company, entering either in a web browser will find the same content.

There are few resons for using web aliases :

1. Handle common misspellings : a user might incorrectly type a URL, for example, mtest.com instead of mytest.com. Organizations often register commonly misspelled versions of their domains and point them to the correct URL.

2. Re-branding : an organization may purchase another organization and choose to re-brand the domain name or multiple domains (organizationA.org and organizationB.org become organizationC.org.) Viewers likely will continue to use the old bookmarks that will send them to the new site.

3. At times developers come up with some idea to create a web-site and later want to fork it as per requirement.

4. Direct viewers to a different page.

So lets see, how to to do this in openshift :

Step-1 : Assuming that you have an application running on openshift, we will run below command :

$ rhc domain show

for eg :

..
[userone@userone OpenShift]$ rhc domain show
Password: ********


User Info
=========
Namespace: userone
  RHLogin: userone@blah.com


Application Info
================
kitchensink
    Framework: jbossas-7
     Creation: 2012-07-16T05:40:14-04:00
         UUID: cdw8a6h5ju12345u7894561230f5y9w
      Git URL: ssh://cdw8a6h5ju12345u7894561230f5y9w@kitchensink-userone.rhcloud.com/~/git/kitchensink.git/
   Public URL: http://kitchensink-userone.rhcloud.com/

Above command shows one existing application kitchensink with existing openshift account.

Step-2 : Lets add alias to it :

rhc-ctl-app -a $ApplicationName -c add-alias –alias www.youralias.com

for eg:

[userone@userone OpenShift]$ rhc-ctl-app -a kitchensink -c add-alias --alias www.myalias.com
Password: ********


RESULT:
Success
..

Note : Make sure you own the domain name that you are adding. You can check www.domain.com, www.godaddy.com, www.bigrock.in, www.joker.com etc .to get you own domain.

Step-3 : Now let us confirm it has been added :

$ rhc domain show

for eg:

..
[userone@userone OpenShift]$ rhc domain show
Password: ********


User Info
=========
Namespace: userone
  RHLogin: userone@blah.com


Application Info
================
kitchensink
    Framework: jbossas-7
     Creation: 2012-07-16T05:40:14-04:00
         UUID: cdw8a6h5ju12345u7894561230f5y9w
      Git URL: ssh://cdw8a6h5ju12345u7894561230f5y9w@kitchensink-userone.rhcloud.com/~/git/kitchensink.git/
   Public URL: http://kitchensink-userone.rhcloud.com/
      Aliases: www.myalias.com

 Embedded: 
      None

Step 4 : Above we can see we have an alias added as “www.myalias.com”. Now try to hit the url from web-browser, it should work 🙂

Adding multiple aliases :

You can add multiple aliases to same application using the same command mentioned in Step-2.

Removing aliases :

To remove your aliases you can run below command :

$ rhc-ctl-app -a $ApplicationName -c remove-alias –alias www.youralias.com

for eg:

..
[userone@userone OpenShift]$ rhc-ctl-app -a kitchensink -c remove-alias --alias www.myalias.com
Password: ********


RESULT:
Success
..

Stay high on OpenShift !!

Regards,
MiddlewareMagic Team 🙂


Port-Forwarding on OpenShift

Hi,

In this article we will discuss about port forwarding and how to do it on OpenShift. Port forwarding allows remote computers to connect to a specific computer or service within a private local-area network.

In a typical residential network, nodes obtain Internet access through a DSL or cable modem connected to a router or network address translator (NAT/NAPT). Hosts on the private network are connected to an Ethernet switch or communicate via a wireless LAN. The NAT device’s external interface is configured with a public IP address. The computers behind the router, on the other hand, are invisible to hosts on the Internet as they each communicate only with a private IP address.

When configuring port forwarding, the network administrator sets aside one port number on the gateway for the exclusive use of communicating with a service in the private network, located on a specific host. External hosts must know this port number and the address of the gateway to communicate with the network-internal service. For eg:

– Running a public HTTP server within a private LAN
– Accessing apllication server consoles
– Permitting Secure Shell access to a host on the private LAN from the Internet
– For monitoring applications or services using sniffing tools such as wily, Nagios
– Permitting FTP access to a host on a private LAN from the Internet

Usually only one of the private hosts can use a specific forwarded port at one time, but configuration is sometimes possible to differentiate access by the originating host’s source address.

Unix-like operating systems sometimes use port forwarding where port numbers smaller than 1024 can only be created by software running as the root user. Running with superuser privileges (in order to bind the port) may be a security risk to the host, therefore port forwarding is used to redirect a low-numbered port to another high-numbered port, so that application software may execute as a common operating system user with reduced privileges.

We can achieve port-forwarding in OpenShift as well. We can port forward JBoss AS admin console, mysql, JBoss remoting and AJP ports to our local machinne and can use them for monitoring and management purpose. All we need to do is to create an application and then forward the ports to local box. Below are the steps:

Step-1 : Create an OpenShift application using :

rhc app create -a $application-name -t jbossas-7 -l $userid

for eg:

..
[userone@userone OpenShift]# rhc app create -a testapp -t jbossas-7 -l openshift-id@blah.com
Password: 
Creating application: testapp in mydomain

MESSAGES:
OpenShift is currently being upgraded, some services may be unavailable.

Now your new domain name is being propagated worldwide (this might take a minute)...
Warning: Permanently added the RSA host key for IP address '207.246.174.134' to the list of known hosts.
Enter passphrase for key '/userone/.ssh/libra_id_rsa': 
Confirming application 'testapp' is available:  Success!

testapp published:  http://testapp-mydomain.rhcloud.com/
git url:  ssh://pqrs7b6d3cf24ce12345a1ec3c1b7d98@testapp-mydomain.rhcloud.com/~/git/testapp.git/
Successfully created application: testapp
..

Step-2 : Forward the ports :

rhc-port-forward -a $application-name -l $userid

for eg:

..
[userone@userone OpenShift]$ rhc-port-forward -a testapp -l openshift-id@blah.com
Password: ********

Checking available ports...

Binding httpd -> 127.3.77.9:8080...
Binding java -> 127.3.77.8:3528...
Binding java -> 127.3.77.8:4447...
Binding java -> 127.3.77.8:5445...
Binding java -> 127.3.77.8:5455...
Binding java -> 127.3.77.8:8080...
Binding java -> 127.3.77.8:9990...
Binding java -> 127.3.77.8:9999...
Binding mysqld -> 127.3.77.8:3306...
Use ctl + c to stop
..

Step-3 : Now you can tru to use services available through forwarded ports.

for eg: Accessing JBoss AS 7 admin console :

type below in address bar of your browser :

127.3.77.9:9990

Note : If you want to forward only a particular port not all of them, due to some security or management reasons. for eg. only port 9990, try below command :

ssh -N -L 127.3.77.9:9990:127.3.77.9:9990 $ssh-key@$app-name-$namespace.rhcloud.com

Cheers,
Middleware Magic Team 🙂


Copyright © 2010-2012 Middleware Magic. All rights reserved. |