Thursday, 23 June 2016

Deploy your code residing on github to OpenShift

# Usecase : There is an existing application code in your github/gitlab repo and you want to deploy it on your choice of application server(JBoss EAP) running on OpenShift.

Source-To-Image (S2I) is a standalone tool which is very useful when creating builder images. As the name suggests we will be taking the source code from our git repository and will create a docker image using it. Once image is created we can assign this image to a container, which would be running the version of the code which we fed to S2I.

OpenShift Allows to create applications wither using `oc` command line utility or directly through the management console. First it requires a project to be created, which contains the applications, services and routes.

Here is how you can create a project and an application using `oc` utility.


  
  $ oc login $MASTER_SERVER_URL -u $USERNAME -p $PASSWORD
  $ oc new-project demo
  $ oc new-app eap64-basic-s2i \
        --param=APPLICATION_NAME=ticket-monster \
        --param=SOURCE_REPOSITORY_URL=https://github.com/nikhilmone/ticket-monster.git \
        --param=SOURCE_REPOSITORY_REF=2.7.0.Final \
        --param=CONTEXT_DIR=demo


You can also create the project and application from thre management console, as shown below :

Login to management console with your credentials and create a project.



Now add an application to your newly created project. You see below templates which you can choose from as your base image:



I chose `jboss-eap64-openshift:1.1`, since I want to deploy a J2EE application on JBoss EAP 6.4, which I have aleady created.
[](https://github.com/nikhilmone/jboss-eap-quickstarts.git). Then I choose branch name as `6.4.x` and the sub-directory as `kitchensink`. These two things are completely optional and you can skip this if your git repository is not too complex.



Click on advanced and configure your routing, deployment and build config. I have kept all the options default as I want to expose my application on public internet and want to trigger build and deployment after a code push.



Submit the information above and a new application is created. In this page you can see a `git webhook` that you can set in your github repo. So that as soon as you push the new code to git repo, a rest call will be made to your master server and a new build will e triggered, which eventually triggers a new deployment as well.


Let's click on `Go to overview` link and it takes you to this page. Here you can see a build is triggered.



Click on `view logs`


You can also tail the logs from `oc` command line utility. Simply do :

 $ oc get pods
 $ oc logs $POD_NAME



Now the build is successful and finished. Let's run `oc get pods` again and we can see OpenShift has triggered a deployment. You can tail the logs again if you wish.


Let's go to overview page again. We can see the application is deployed and has been exposed as service via a route.


Let's click on the service url and it takes us to the application landing page.


Done. You have a application running in cloud !! :)

Wednesday, 22 June 2016

OpenShift : Platform as a Service by Red Hat

OpenShift is Red Hat's Platform-as-a-Service (PaaS) that allows developers to quickly develop, host, and scale applications in a cloud environment. With OpenShift you have a choice of offerings, including online, on-premise, and open source project options. Please refer below for all the documentation related to OpenShift :

https://docs.openshift.com/enterprise/3.0/welcome/index.html

## OpenShift 3 Architecture :















We will be going through multiple usecases through the series of blog posts.