Wednesday, 17 June 2015

Publishing Java Applications with Cloud Foundry and IBM Bluemix

We'll be using the the java_buildpack to install a war file, preferable we could of used the Liberty for Java buildpack (liberty-for-java) but as this post should also work with non IBM Bluemix Cloud Foundry instances, we'll use the standard Java buildpack instead.

I am also going to be hosting this application at boriscloud.boriskuschel.com so I'll be setting up some routes.

First I am going add the boriskuschel.com domain to the "Cloud" space.

> cf create-domain "Boris's Cloud Blog" boriskuschel.com
Creating domain boriskuschel.com for org Boris's Cloud Blog as <Bluemix username>...
OK

Download and unzip this file and examine the manifest.yml. Manifest files make deploying into Cloud Foundry easier.

---
applications:
- name: boriscloud 
  memory: 512M
  instances: 1
  path: BorisCloud.war
  buildpack: java_buildpack

The java buildpack with use Tomcat to start the servlet. If you wish to use the WebSphere Liberty server specify:

  buildpack: liberty-for-java

This will use liberty instead of Tomcat.

The rest of the manifest options can be left as default.

By default, when we push the application it will be route the application to <application name>.mybluemix.net but as we want to bind it to boriscloud.boriskuschel.com we will specify the boriskuschel.com domain on the command line using the -d flag.

From within the unzipped boriscloud directory run:

> cf push -d boriskuschel.com
Using manifest file /home/kuschel/boriscloud/manifest.yml

Creating app boriscloud in org Boris's Cloud Blog / space Cloud as <Bluemix username>...
OK

Creating route boriscloud.boriskuschel.com...
OK

Binding boriscloud.boriskuschel.com to boriscloud...
OK

Uploading boriscloud...
Uploading app files from: /home/kuschel/boriscloud/BorisCloud.war
Uploading 7.1K, 9 files
Done uploading               
OK

Starting app boriscloud in org Boris's Cloud Blog / space Cloud as <Bluemix username>...

0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
1 of 1 instances running

App started

OK

App boriscloud was started using this command `JAVA_HOME=$PWD/.java-buildpack/open_jdk_jre JAVA_OPTS="-Djava.io.tmpdir=$TMPDIR -XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk_jre/bin/killjava.sh -Xmx382293K -Xms382293K -XX:MaxMetaspaceSize=64M -XX:MetaspaceSize=64M -Xss995K -Daccess.logging.enabled=false -Dhttp.port=$PORT" $PWD/.java-buildpack/tomcat/bin/catalina.sh run`

Showing health and status for app boriscloud in org Boris's Cloud Blog / space Cloud as <Bluemix username>...
OK

requested state: started
instances: 1/1
usage: 512M x 1 instances
urls: boriscloud.boriskuschel.com
last uploaded: Thu Jun 18 02:07:22 UTC 2015
stack: lucid64

     state     since                    cpu    memory           disk           details   
#0   running   2015-06-17 10:10:18 PM   0.0%   124.5M of 512M   125.6M of 1G      

Let's check out the routes.

> cf routes
Getting routes as <Bluemix username> ...

space   host         domain             apps   
Cloud   boriscloud   boriskuschel.com   boriscloud   

This presents a small issue, I'll need to update my domain's DNS server with a new CNAME record that points to boriscloud. So, our application will need to be put up on a domain that is owned by Bluemix so I can point to it with the CNAME record. I'll use the mybluemix.net domain that is owned by Bluemix.

> cf map-route boriscloud mybluemix.net -n boriscloud
Creating route boriscloud.mybluemix.net for org Boris's Cloud Blog / space Cloud as <Bluemix username>...
OK
Adding route boriscloud.mybluemix.net to app boriscloud in org Boris's Cloud Blog / space Cloud as <Bluemix username>...
OK

> cf routes
Getting routes as <Bluemix username> ...

space   host         domain             apps   
Cloud   boriscloud   boriskuschel.com   boriscloud   
Cloud   boriscloud   mybluemix.net      boriscloud   

That's better, now we can access the application from http://boriscloud.boriskuschel.com/test (and http://boriskuschel.mybluemix.net/test).

1 comment:

  1. Great Article
    Cloud Computing Projects


    Networking Projects

    Final Year Projects for CSE


    JavaScript Training in Chennai

    JavaScript Training in Chennai

    The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

    ReplyDelete