This blog post is for you if you happen to have an old legacy Rails 2.x (read: pre-bundler) application and wish to deploy it to Viaduct.

Personally, I've tested this using an old Rails application which has Rails itself vendored into vendor/rails. It also has a few other Gem dependencies which need to be installed at the system level.

Firstly, create a new application in Viaduct as normal by entering your repository URL. Once created, you'll automatically be prompted to choose a platform, select Ruby 1.8.7 as this is probably the best version for old Rails apps.

Dependencies

Next, you'll need to document your dependencies into a Gemfile. Add a new config file which should contain a Gemfile similar to this (but with your dependencies rather than mine). You'll probably want to specify the older version of Rake as quite a few changes have happened in later versions which are not compatible with Rails 2.

source "https://rubygems.org"
gem "rake", "0.8.3"
gem "ferret", "0.11.6"
gem "tzinfo", "0.3.10"

Build Configuration

You'll need to add a few build commands. Head over to the Config menu and then select Build Commands. You'll need to create a command to install your dependencies.

bundle install --system

Starting your web server

You can start your webserver using whichever command takes your fancy but to keep things simple, we'll just use script/server. Select the Processes option and add a new web process with the command shown below:

script/server -p $PORT

Don't forget to check the Send HTTP Traffic checkbox so that traffic is send to your processes when you access your Viaduct domain. Also, select HTTP Check as the start detector.

Databases

If you have a database, go ahead and create a new database under the Databases tag and then add the following config file to your application.

$RAILS_ENV:
  adapter: mysql
  encoding: utf8
  database: "$VDT_DB_NAME\0"
  username: $VDT_DB_USER
  password: $VDT_DB_PASS
  host: $VDT_DB_HOST

(You'll note the odd "\0" on the database line - this is to resolve an issue with newer MySQL gems.)

You may also wish to add a new build command to run database migrations for you:

rake db:migrate

Rails Environmnet

Don't forget to add an environment variable to set your RAILS_ENV to production. You can do this from the Config then Environment Variables directory.

Downgrade RubyGems?

You may find your application doesn't work with the version of RubyGems included with the 1.8.7 stack. If you need to downgrade it, that's not a problem, just add a build command (at the top of your list) to run the following:

if [ $(gem -v) != "1.8.5" ]; then
  gem update --system 1.8.5
fi

Static Files

You'll want to set up your application to serve static files from your proxies rather than through your application. Just head over to the Config then Static Files page. Once there, turn on static file serving and enter public as the document root.

Deploy!

Now you're all ready to go, just go ahead and deploy your application and see what happens. If you have any errors, ensure that you have all dependencies installed and working correctly.

Tell us how you feel about this post?