-
Notifications
You must be signed in to change notification settings - Fork 13
Step 12.5 deploy to openshift
Purpose: in this step we will see how to deploy you app to openshift, redhat's cloud computing platform.
cd ~/devel/apps
git clone git://github.com/opensas/play-demo.git
cd play-demo
git checkout origin/12.5-deploy_to_openshift
Creating an account at heroku is really easy. Go to openshift express homepage and click on signup to create a new account, enter a valid email address and just follow the instructions you'll receive by mail.
Before installing openshift client tools, you'll have to install git and ruby gems. On a debian based linux distribution is as easy as
sudo apt-get install ruby rubygems ruby-dev
and then
sudo gem install rhc
On some distributions the gem installation directory is not automatically added to the path. Find the location of your gems with gem environment
and add it to you system's PATH environment variable. For more details have a look at this stack overflow question and this thread at openshift's forum.
If you get the error
invalid date format in specification
you'll have to edit json_pure gem's specification file and enter a date like 2011-09-18. Check this openshift thread for more info.
Follow these instructions to add openshift tools on windows, mac or linux. You can also see this video.
Before actually deplying any app to openshift, you should first create a domain, which will appear in the URL of your apps according to the following scheme:
http://<application name>-<domain-name>.rhcloud.com
So create a domain with the following command:
rhc-create-domain -n my_domain -l [email protected] -p my_password
Here you will have to enter the mail ans password you used to register your account at aopenshift, not your email's password.
Openshift will then create a pair of private and public keys as libra_id_rsa and libra_id_rsa.pub at you .ssh directory. It will ask you for a password to access the private key.
Generating OpenShift Express ssh key to /home/sas/.ssh/libra_id_rsa
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/sas/.ssh/libra_id_rsa.
Your public key has been saved in /home/sas/.ssh/libra_id_rsa.pub.
The key fingerprint is:
26:86:45:1d:7e:01:81:bd:ac:b6:77:52:0e:0d:1d:23 sas@sas-box
The key's randomart image is:
+--[ RSA 2048]----+
| .+++. |
| ...E o. |
| ...+.o |
| o +.. |
| . o.So |
| .oo. o |
| . . + |
| . o o |
| . o |
+-----------------+
Contacting https://openshift.redhat.com
Creation successful
You can go to openshift's console to see your newly created domain.
Create a directory like ~/devel/apps/openshift and issue the following command:
rhc-create-app -l [email protected] -p my_password -t jbossas-7.0 -a playdemo
Here we are creating an jboss application named playdemo.
We will be asked for our private key password.
You can go to https://openshift.redhat.com/app/dashboard to see your brand new app. You can even see it running at http://playdemo-playdemo.rhcloud.com/. Openshift has also created and cloned a git repository for us.
Deploying a play app to openshift, it's just a matter of generating the exploded war folder and then push it to openshift repo.
So first of all we are going to get rid of several files we want need.
Go to the newly created repo and run:
cd ~/devel/apps/openshift/playdemo
rm -fr pom.xml src
git add -A
git commit -m "get rid of needless files"
git push origin
Now we'll just create a dummy application with
cd ~/devel/apps
play new playdemo
edit app/views/Application/index.html file and replace the welcome tag with something like Hello from openshift.
and issue the following command to generate the war exploded folder to our openshift app's git repo. (adjust folder name accordingly)
cd ~/devel/apps/
play war playdemo -o openshift/playdemo/deployments/ROOT.war
Lastly, create a ROOT.war.dodeploy file to tell jboss to go ahead and deploy our app
touch openshift/playdemo/deployments/ROOT.war.dodeploy
Everytime you want to force a new deploy, you'll just have to update the contents of the dodeploy and issue a push.
Now will commit our changes and push them to openshift to deploy our app.
cd ~/devel/apps/openshift/playdemo
git add -A
git commit -m "deploy dummy play application"
git push origin
In order to check the logs and see what's going on in our server on red hat's cloud, open another terminal and issue the following command
rhc-tail-files -l login -p password -a playdemo
.
The first time it will take quite some time to complete the deploy, because git is pushing all play libraries, but further deploys will just push the modified files so it will be much faster.
Currently openshift will not work with a war compiled with JDK 7, so be sure to use a JDK 1.6.x version. Check it with the
java -version
command.
Now you can check that your application is up and running at http://playdemo-playdemo.rhcloud.com/.
We could continue working with our app on a directory and then generating the exploded war to the deployments folder of our local openshift repository. But it is more confortable to just move the app to our repo.
So we will just copy our app from ~/devel/apps/play-demo to ~/devel/apps/openshift/playdemo folder.
Don't forget you can fetch the ap with the following commands:
cd ~/devel/apps
git clone git://github.com/opensas/play-demo.git
cd play-demo
git checkout origin/12.5-deploy_to_openshift
now copy the app to the openshift repository
cd ~/devel/apps
cp -r play-demo/app/ openshift/playdemo/
cp -r play-demo/conf/ openshift/playdemo/
cp -r play-demo/jar/ openshift/playdemo/
cp -r play-demo/lib/ openshift/playdemo/
cp -r play-demo/modules/ openshift/playdemo/
cp -r play-demo/public/ openshift/playdemo/
cp -r play-demo/test/ openshift/playdemo/
and edit conf/application.conf file adjust set the name of the app to playdemo
application.name=playdemo
And now create the war file (notice the --exclude param to avoid entering an infinite loop), commit the files and push to openshift
play war -o deployments/ROOT.war --exclude deployments
git add -A
git commit -m "play demo application deployed to openshift"
git push
In order to let play create the database tables, you'll have to uncomment
jpa.ddl=update
in the application.conf file
http://devcenter.heroku.com/articles/play
http://toolbelt.herokuapp.com/linux/readme
http://www.jamesward.com/2011/08/29/getting-started-with-play-framework-on-heroku
Now we are going to Step 14 - deploy to gae.