Contents
Ruby Rack
Installation
-
Open Web Platform Installer and install "Ruby project":
- Open project's home page and follow steps in "Ruby Rack over HTTP with Thin" section:
- Create config.ru file with the following content:
run lambda { |env| [200, {'Content-Type'=>'text/plain'}, StringIO.new("Hello World!\n")] }
Output of example rack application:
Deployment
To deploy Ruby Rack 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
<?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%" />
<!-- Use this APP_WORKER with HTTP Ruby engine and Thin. Thin need to be installed.
-->
<add name="APP_WORKER" value="GEM_HOME\bin\thin start" />
<!--
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>
Depending on the version of Ruby and transport you need you can use different Helcon Zoo appliction engines as a 'scriptProcessor' value. Following engines are available: ruby.1.8.rack, ruby.1.9.rack, ruby.1.9.http, ruby.2.0.rack, ruby.2.0.http.
Environment variables:
-
APP_WORKER
— path to the main application script. Note, Helicon Zoo automatically detects Rails and picks up “config.ru” file. -
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 intoRAILS_ENV
variable.