Friday, April 4, 2014

Binary deployment to OpenShift


OpenShift is a great platform for developers. However with its inherent dependency on GIT and GIT centric build and deployment life cycle, at times it is not easy to gain control over the build and deployment process. Specially if one is not using GIT as source code repository, Jenkins for build and deployment and Maven for dependency management and build.

OpenShift have recently decoupled the dependency on the GIT repository for the deployment of the war files.
The blog outlines the use of rhc client tools for deployment. This frees the build process from any dependency on GIT. You can use any method of build and use rhc client to deploy the artifacts to OpenShift application.



Following are the steps
  • Create OpenShift application without GIT
$ rhc create-app -a -t jbossews-2.0 --no-git
  • Configure app for binary deployment and manual deployment
             $ rhc configure-app --deployment-type binary
            $ rhc configure-app -a --no-auto-deploy
  • Specify the number of deployments for the app
           $ rhc configure-app --keep-deployments
  • Create project structure as follows
project/
|--- build-dependencies/
            |-- .m2
|--- dependencies/
            |-- jbossews/
                        |-- webapps
|--- repo/
    |-- target/
    |-- .openshift/
                        |-- config/ à this could contain tomcat config files and logging configurations
                        |-- markers/
                                    |-- java7 à this file is important as this will specify the java runtime
                        |-- cron/
                        |-- action_hooks/
    |-- webapps/
                        |-- ROOT.war à this is the binary artifact result of Jenkins build process
  • Create a tar file out of this project such that build-dependencies, dependencies and repo should be at the root of the tar ball.
$ tar -cvzf .tar.gz ./
  • Now we are ready to deploy the binary to an OpenShift application
$ rhc deploy .tar.gz -a --hot-deploy

Hot deployment will skip stop and start of cartridge.

Following is the snippet of deployment

Deployment of file '/root/webapp5.tar.gz' in progress for application kitchensink ...
Starting deploy for binary artifact
Stopping gear
Creating new deployment directory
Preparing deployment
Preparing build for deployment
Deployment id is a13a8631
Distributing deployment
Distribution status: success
Activating deployment
+ tmp=/var/lib/openshift/533d3289d2478635a4000001/jbossews//tmp
+ '[' -d /var/lib/openshift/533d3289d2478635a4000001/jbossews//tmp ']'
+ for d in '$tmp/*'
+ '[' -d '/var/lib/openshift/533d3289d2478635a4000001/jbossews//tmp/*' ']'
++ ls /var/lib/openshift/533d3289d2478635a4000001/app-root/runtime/repo//webapps
+ '[' 'ROOT.war
webapp3.war' ']'
+ rsync -r --delete /var/lib/openshift/533d3289d2478635a4000001/app-root/runtime/repo//webapps/ /var/lib/openshift/533d3289d2478635a4000001/jbossews//webapps/
Starting jbossews cartridge
Found 127.1.246.1:8080 listening port
Activation status: success
Deployment status: success
Success


       Additionally following commands are handy for other deployment related tasks and rollback

  • Save a binary (tar.gz) snapshot of the deployment currently active:
            $ rhc save-snapshot --deployment

  • List all the deployments of a particular application
           $ rhc deployments

1:16 PM, deployment 853b30c8
1:17 PM, deployment 481a33c9

  • Rollback to that previous deployment (activate):
           $ rhc activate-deployment -a
 
Hope this is helpful. Please comment if you want to know more on specific topics. I would be glad to help.

No comments:

Post a Comment