How to deploy a self contained Rails application on Tomcat, painlessly!
Here at work we have a Postfix email server which handles all our email for multiple domains. The authentication and users are handled via the PostgreSQL database backend. To make life easy, I used Rails to scaffold a few tables in that Postfix PostgreSQL database. End result, is an easy to use interface to manage emails and domains. However, deployment isn't as fun as it could be, even with mongrel. I still have to have Rails/Ruby installed AND manage startup scripts to start the mongrel instance for my Rails MailManager application. Well JRuby to the rescue!
Here is how I created a self-contained Rails Application that can be reused in any Tomcat deployment.
I used the pure Ruby PostgreSQL implementation instead of the Java-centric ActiveRecord-JDBC solution, so I can develop using native Ruby while deploying via WAR using JRuby without any database.yml changes!
First off we want to instal GoldSpike which adds rake tasks to create WAR files.
script/plugin install svn://rubyforge.org/var/svn/jruby-extras/trunk/rails-integration/plugins/goldspike
Now I needed to implement a self-contained postgres-pr module. I implemented it as a Rails Plugin!
Create the postgres plugin
./script/generate plugin postgres
Copy the postgres pure implementation gem files to your Rails plugin
cp -rf /opt/local/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/* ./vender/plugins/postgres/lib/
Setup database.yml
I setup host as pdatabase, so on any server you deploy the WAR just add an alias to /etc/hosts ; 127.0.0.1 pdatabase
production:
adapter: postgresql
database: postfix
username: victori
password: .......
host: pdatabase
Run the rake task to build your reusable self-contained web application
rake war:standalone:create
Pretty darn easy eh?