Helicon Zoo

Ruby on Rails (2.3.x and 3.x.x)

Installation

  1. Open Web Platform Installer and install "Ruby project":
    Ruby on Rails installation
  2. Open project's home page and follow steps in "Ruby on Rails" section:
    Ruby on Rails installation
    Ruby on Rails installation
  3. Output of example Rails application:
    Ruby on Rails installation

Deployment

To deploy Ruby on Rails application you will need to install Ruby Hosting Package on a target server. Then just copy IIS web site from one machine to another.

web.config example

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>

    <heliconZoo>
      <application name="ruby.project" >
        <environmentVariables>
          <add name="RAILS_RELATIVE_URL_ROOT" value="%APPL_VIRTUAL_PATH%" />
          <!--
          Deploy file includes the most common commands required to prepare application before launch (bundle install, migrations etc.)
          It is also possible to specify here any script which evenually will be run by rubyw.exe.
          -->
          <add name="DEPLOY_FILE" value="deploy.rb" />
          <!-- By default we run Rails in production mode -->
          <add name="RACK_ENV" value="production" />
          <!-- Web console location -->
          <!-- security rules for console are placed in /console/web.config -->
          <add name="CONSOLE_URL" value="console" />
        </environmentVariables>
      </application>
    </heliconZoo>

    <handlers>
      <!-- All transports below support Rails 2.3, 3.0 and 3.1 as well as any Rack-based application. Uncomment the one you wish to use. -->

      <!-- Ruby 1.9 over FastCGI -->
      <add name="ruby.project#x86" scriptProcessor="ruby.1.9.rack"  path="*" verb="*" modules="HeliconZoo_x86" preCondition="bitness32" resourceType="Unspecified" requireAccess="Script" />
      <add name="ruby.project#x64" scriptProcessor="ruby.1.9.rack"  path="*" verb="*" modules="HeliconZoo_x64" preCondition="bitness64" resourceType="Unspecified" requireAccess="Script" />


      <!-- Ruby 1.8 over FastCGI
      <add name="ruby.project#x86" scriptProcessor="ruby.1.8.rack"  path="*" verb="*" modules="HeliconZoo_x86" preCondition="bitness32" resourceType="Unspecified" requireAccess="Script" />
      <add name="ruby.project#x64" scriptProcessor="ruby.1.8.rack"  path="*" verb="*" modules="HeliconZoo_x64" preCondition="bitness64" resourceType="Unspecified" requireAccess="Script" />
      -->

      <!-- Ruby 1.9 over HTTP, using Thin or other back-end application server
      <add name="ruby.project#x86" scriptProcessor="ruby.1.9.http"  path="*" verb="*" modules="HeliconZoo_x86" preCondition="bitness32" resourceType="Unspecified" requireAccess="Script" />
      <add name="ruby.project#x64" scriptProcessor="ruby.1.9.http"  path="*" verb="*" modules="HeliconZoo_x64" preCondition="bitness64" resourceType="Unspecified" requireAccess="Script" />
      -->

    </handlers>

    <!-- URL Rewrite rules to pass static files, limit console access, etc. -->
    <rewrite>
      <rules>

        <!-- This rule rewrites '/' requests to /public/index.html -->
        <rule name="index" stopProcessing="true">
          <match url="^$" ignoreCase="false" />
          <conditions logicalGrouping="MatchAll" trackAllCaptures="true">
            <add input="{APPL_PHYSICAL_PATH}" pattern="(.*)" ignoreCase="false" />
            <add input="{C:1}public\index.html" matchType="IsFile" />
          </conditions>
          <action type="Rewrite" url="public/index.html" />
        </rule>

        <!-- Rewrite static files requests to /public folder to bypass Ruby processing.
             This speeds up static files significantly. Please put all your static
             files into the /public folder. -->
        <rule name="Static Files" stopProcessing="true">
          <match url="^(?!public)(.*)$" ignoreCase="false" />
          <conditions logicalGrouping="MatchAll" trackAllCaptures="true">
            <add input="{APPL_PHYSICAL_PATH}" pattern="(.*)" ignoreCase="false" />
            <add input="{C:1}public\{R:1}" matchType="IsFile" />
          </conditions>
          <action type="Rewrite" url="public/{R:1}" />
        </rule>

        <!-- This rule rewrites Rails assets requests. Copy web.config file from
             /public folder to /app/assets to speed it up. -->
        <rule name="Rails 3.1 assets" stopProcessing="true">
          <match url="^assets/(.*)$" ignoreCase="true" />
          <conditions logicalGrouping="MatchAll" trackAllCaptures="true">
            <add input="{APPL_PHYSICAL_PATH}" pattern="(.*)" ignoreCase="false" />
            <add input="{C:1}app\assets\{R:1}" matchType="IsFile" />
          </conditions>
          <action type="Rewrite" url="app/assets/{R:1}" />
        </rule>

        <!-- This rule shows welcome page when no Rack application exist. -->
        <rule name="Rewrite to Zoo index if that's an empty application" stopProcessing="true">
          <match url="^/?$" ignoreCase="false" />
          <conditions logicalGrouping="MatchAll" trackAllCaptures="true">
            <add input="{APPL_PHYSICAL_PATH}" pattern="(.*)" ignoreCase="false" />
            <add input="{C:1}config.ru" matchType="IsFile" negate="true" />
          </conditions>

          <action type="Rewrite" url="public/zoo-index.html" />
        </rule>

      </rules>
    </rewrite>

  </system.webServer>
</configuration>

Environment variables:

  • DEPLOY_FILE — optional path to a ruby script which is run before application launch and every time IIS application pool recycles. The script usually contains deployment instructions to satisfy application dependencies and database migrations.
  • DEPLOY_LOG — optional path to a text file containing the output of the deploy script. It’s recommended to set this variable if you use deploy script.
  • RACK_ENV — specifies application running mode. Default value is “production”. This variable is duplicated into RAILS_ENV variable.

deploy.rb example:

Deploy file is used to execute commands, such as components installations or database migrations, on a server when the application initially starts or updated. The following code is only an example. We recommend you to use deploy.py file that comes with the Python project template.


# This is a sample deploy script.
# Rename this file to deploy.rb and Helicon Zoo will execute this script as a deploy process.
# After execution is finished Helicon Zoo will rename it to deploy_done.rb
# Rename it to deploy.rb to start deploy task again when needed.


require 'rbconfig'

APP_ROOT = File.dirname( __FILE__ ).freeze
RUBY_BIN = RbConfig::CONFIG[ 'bindir' ].freeze
RACK_ENV = ( ENV[ 'RACK_ENV' ] || 'production' ).freeze

Dir.chdir( APP_ROOT )

def deploy( env, &block )
  return unless RACK_ENV == env.to_s
  block.call
end


def run( task, wrap = true )
  args = task.split
  cmd = args.shift

  ARGV.clear
  ARGV.unshift( *args )

  # We use 'load' because it doesn't spawn child ruby process,
  # which might be problematic in hosting environment.
  exe = File.join( RUBY_BIN, cmd )
  puts ">> #{exe} #{ARGV.inspect}"
  load( exe, wrap )
rescue Errno::EACCES => e
  puts 'Insufficient file system permissions.' +
    'Please make sure IIS application pool user has enough rights to access application files.' +
    "Usually Write permission isn't granted where it's needed. Exception: #{e}"
rescue Object => e
  puts e.to_s
  # Deploy tries to run all tasks. Some exceptions aren't relevant. See log if it matters.
end


deploy :development do
  run 'bundle install'
  run 'rake db:create --trace'
  run 'rake generate_session_store --trace'
  run 'rake db:migrate --trace'

  # TODO: add more development tasks here
end


deploy :production do
  run 'bundle install'
  run 'rake db:create --trace'
  run 'rake generate_session_store --trace'
  run 'rake db:migrate --trace'

  # TODO: add more production tasks here
end

Read Ruby related articles for more information >>