

Hello habrazhiteli! Today I would like to talk about how you can use the free
solution from RedHat to place your sites in the cloud on the example of
Play! Framework . I will not describe each of the products separately. I have already
written about them more
than once , I will tell only about their interaction and my scheme for automating the assembly and deployment.
So let's get started. Having created the JBoss application on OpenShift, we get at the disposal of the Git-repository, in which the sample sources are located (for subsequent replacement with our samples) and compiled versions of these sources in the form of a WAR archive.
')
You can deploy the application in two ways: either by downloading the source code to the server, which will be compiled using pom.xml, using Maven, or by downloading the finished WAR-archive. Unfortunately, there are no other ways: you can upload files to the server only through Git. Of course, it is possible to join a server over SSH, but this is used more for administrative tasks. On this with the OpenShift-part for now finish.
Play! Framework version 2.1.1 (the latest at the moment), unfortunately, does not support the creation of a WAR archive, it works a little differently, creating a similar structure at the output:
my-first-application-1.0
└ lib
└ * .jar
└ start
I did not manage to make such distribution with OpenShift (meybie is possible - I will be glad to see the solution in the comments), so I stopped at using version 1.2.4.
So, create our application:
play new SuperApplication cd SuperApplication play idealize / play eclipsify
At this stage, we received a test application, which can be verified in its performance by executing the
play start
command.
Next,
add salt / pepper to taste, make the necessary changes - and we are ready to deploy the application.
It's time to return to our OpenShift repository, which can be cloned to the following address:
ssh://hashcode@superapplication-suffix.rhcloud.com/~/git/superapplication.git/
and in the end we will get something like this:
superapplication
└ .git
└ bullshit
└ .openshift
└ bullshit
└ deployments
└ ROOT.war <---
└ src
└ sources
What interests us is highlighted by an arrow. Accordingly, the task now is to make sure that our project is going to the archive called ROOT.war, copied to the right folder, commit and push.
Now a few words about my specific situation. Everything is much simpler if we are going to store the sources in the same repository. But it turned out that the Web part was just one of several modules present in my project, and the project itself was hosted on BitBucket. Therefore, I deleted the
src
folder from OpenShift as unnecessary, renamed the base directory to dist and used it purely for deployment (do not forget to push the changes), and the source code continued to host in a separate place. And now the shamanism begins ...
To automate the assembly and deployment, I chose Ant. I do not want to describe the contents of the script for a long time - it is well commented, so I will bring it straight away:
<project name="SuperApplication" default="dist" basedir="."> <property name="dist" location="..\dist"/> <property name="deployments" location="..\dist\deployments"/> <target name="dist" depends="clean" description="generate the distribution" > <exec executable="play.bat"> <arg line="war -o ${deployments}\ROOT" /> </exec> <zip destfile="${deployments}\ROOT.war" basedir="${deployments}\ROOT" /> <delete dir="${deployments}\ROOT"/> </target> <target name="deploy" description="upload war" > <exec executable="git" dir="${dist}"> <arg line="add ."/> </exec> <exec executable="git" dir="${dist}"> <arg line="commit -m 'Deploy'"/> </exec> <exec executable="git" dir="${dist}"> <arg line="push"/> </exec> </target> <target name="clean" description="clean up" > <delete file="${deployments}\ROOT.war" /> </target> </project>
That's basically it. Using the dist and deploy targets, we can respectively assemble and deploy our proket.
I can not say that the decision is elegant - rather, it looks like a crutch. But this crutch helps in the shortest possible time to establish a fast and convenient development of the site in a free cloud, which means it has the right to exist.
Good luck!