Google today announced Java as a new runtime environment for Google AppEngine. This not only enables developers to use the Java Language to build web applications but also opens the door for a lot of dynamic languages including my current favourite one Ruby. With the help of the Jruby project it is possible to deploy ruby apps in Googles Cloud.
At Bigcurl most applications are written in ruby and a new hosting option which is basicly free is always welcomed. Take a look at some of our internal apps for yourself (www.squidshot.com) and try to spot which ones are hosted in the cloud and which ones are hosted in a traditional data center.
This is a proof of concept which shows that it is possible to run ruby applications and maybe also ruby on rails applications on Google AppEngine. With the help of Ola Bini and the AppEngine Docs for Java , I created a tiny sinatra app (which acts as a placeholder for your much-more-logic-containing-app) and show how to use Google AppEngine as a ruby deployment option.
This was done on Mac OS X 10.5.6.
First check out a fresh copy of jruby
git clone git://kenai.com/jruby~main
go into the jruby dir
and compile jruby.
ant && ant jar-complete
Lets see if we have the correct version.
The output should be something like:
jruby 1.3.0 (ruby 1.8.6p287) (2009-04-08 r9524) (Java HotSpot(TM) Client VM 1.5.0_16) [i386-java]
Install some gems for our newly created jruby.
PATH-TO-JRUBY/bin/jruby -S gem install rake sinatra warbler
Get a fresh version from http://github.com/nicksieger/jruby-rack/tree/master
PATH-TO-JRUBY/bin/jruby -S rake SKIP_SPECS=true
We will come back to jruby-rack later.
Create the sinatra app.
Create a new folder "sinatra-app"
touch config.ru app.rb appengine-web.xml
mkdir views public config lib
Fill the files config.ru, config/warble.rb, appengine-web.xml and app.rb with the content from this gist: http://gist.github.com/91801
This is our basic Sinatra app. It will just display a string. But then we know it is working.
For a quick test run:
and go to http://localhost:4567/
Now we need to copy some files to the lib dir.
First go to the download section to find the Google App Engine SDK for Java. Version 1.2.0 - 04/07/09 is here.
After the download is finished we need to copy
appengine-java-sdk-1.2.0/lib/user/appengine-api-1.0-sdk-1.2.0.jarto the lib dir.
Copy following jar file from jruby-rack to lib folder.
Next up is jruby itself. Since Ola pointed to the 1000 file limit with AppEngine he wrote a script which splits the jruby-jar into two pieces.
But first copy
PATH-TO-JRUBY/lib/jruby-complete.jarto the lib folder of the sinatra app.
Then run his script in the lib folder and you should have two jar files instead of one.
ruby-stdlib.jar. You find the script here.
Now we should be ready to pack our application.
PATH-TO-JRUBY/bin/jruby -S warble
This should create a tmp folder and a .war file. Since AppEngine needs the exploded war folder and not the .war file, we simply ignore the file
tmp/war/WEB-INF/gems/gems/sinatra-0.9.1.1/lib/sinatra.rband commend out the last line which is
use_in_file_templates!. Somehow this makes problems with the runtime.
appengine-java-sdk-1.2.0/bin/dev_appserver.sh tmp/war/to get a local server up and running for testing stuff.
If you have no error on the console go to http://localhost:8080 and you should see a nice welcome message in form of the string from the app.
Things work fine? Lets deploy.
You need to be signed up as one of the 10.000 developers who have early access to the java runtime. Sign up here if you haven't allready.
If so got to the Google AppEngine, sign in and create a new application.
application-idyou get from there into the
appengine-web.xmlfile and replace
Run this to repopulate with the new id
PATH-TO-JRUBY/bin/jruby -S warble
and then deploy running
appengine-java-sdk-1.2.0/bin/appcfg.sh update tmp/war/
Now got to your-application-id.blogspot.com and it should work. The first request takes quite a while but the following should be fine.
Want to redirect naked domains in App Engine. Take a look here.