Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to publish Play Framework application from Jenkins to load balanced environment

I have just started to setup bullet proof nightly build environment to Play based application. So far I have not found a good tutorial about this topic. Could you review currently solution I am setuping? Thanks.

Setup Play Framework to Jenkins server and create a job, which creates a distribution package every 24h from the git/svn repository.

play dist

Above command creates app-1.0.zip file. File is copied and unzipped to multiple nodes. We are using load balancer. Eventually file is unzipped to /home/play/webapp/app-1.0 folder.

After unzip I change symlink /home/play/webapp/app => /home/play/webapp/app-1.0 and reload project. Is this symlink really needed? Can I just unzip files over old files? Do I really need to unzip project? Can I just create a jar file and run it on server?

play reload

Finally old app is removed.

rm -rf /home/play/webapp/app-0.9

Version app-0.9 was originally started by running a following script.

/etc/init.d/play start

Script is a modification of following script:

http://monocaffe.blogspot.fr/2012/09/a-play-framework-server-setup.html

Basically script runs following command, which I found from the start file inside app-xxx.zip file.

exec java $* -cp "`dirname $0`/lib/*" play.core.server.NettyServer `dirname $0`

I did also thought about creating a reload script, which verifies play application is running, if not, play application is started, not restarted.

/etc/init.d/play reload

Best regards, Markku

like image 945
Markku Avatar asked Oct 11 '12 06:10

Markku


2 Answers

I have created a python script to deploy continuously from Jenkins a play application. Basically what the script does is the following:

  • Poll Jenkins to check if a new build is available
  • If one is available
    • Check out the code corresponding to the commit
    • Compile
    • Create a package.
    • Restart the play server
  • Else sleep for a delay before polling another time

The restart strategy is currently basic, but you could modify the script to implement another one quite easily. There is no more documentation but code and configuration file is readable and commented.

like image 117
mchv Avatar answered Oct 18 '22 10:10

mchv


I'm the guy from the blog you posted. In that post I suggest you should have all the Play jars in a single location (/home/play/libs/current -> play-2.0.4), so there's no need to do play dist. In our case we use play stage, scp our files separately to webapps/foo/0.1-SNAPSHOT-20121011/ and then change the symlink current.

After unzip I change symlink /home/play/webapp/app => /home/play/webapp/app-1.0 and reload project. Is this symlink really needed? Can I just unzip files over old files?

That's how I like our setups, using symlinks, but that's only because I want to keep, to some extent, previous versions, specially if those are the ones from CI.

Can I just create a jar file and run it on server?

Technically, you could create a runnable JAR which contained ALL Play's and your dependencies including Netty, but that would be a huge file (only the Play deps are 33MB), you loose the ability to easily change the Play version being used (which I've changed three times in the last two months) and finally, you would need to use something more than Play since this option is not supported (i.e. http://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html)

I did also thought about creating a reload script, which verifies play application is running, if not, play application is started, not restarted.

This is the deploy script shown in the blog entry:

#!/bin/bash
#
# Script to automate CI deployments. Simply stop all
# servers, change the "current" symlinks to the given
# target folder and finally, start all servers
#

export JAVA_HOME="/usr/lib/jvm/default-java"

play_home="/home/play"
webapps_folder="${play_home}/webapps"

apps=( "foo" "bar" "api" )

for app in ${apps[@]}; do

    echo "Stopping server ${app}"
    ${play_home}/bin/${app} stop

    echo "Regenerate current symlink of ${app}"
    rm ${webapps_folder}/${app}/current
    ln -s ${webapps_folder}/${app}/${1} ${webapps_folder}/${app}/current

    echo "Starting server ${app}"
    ${play_home}/bin/${app} nohup

done

exit 0

The idea of this script is to be called with SSH from an ANT script in Jenkins, or manually like ./deploy 0.1-SNAPSHOT-20121012

like image 30
Eldelshell Avatar answered Oct 18 '22 10:10

Eldelshell