Making Windows Installer for Ruby on Rails Application

You'll be needing these applications:
Inno Setup
Inno Setup homepage
ISTool
ISTool homepage
SetEnv
SetEvn CodeProject
Ruby binaries
Ruby FTP
ImageMagick binaries (if you are using imagemagick)
ImageMagick Binary Release, choose the zip archive for windows
MySQL binaries
MySQL Downloads, choose the zip archive for windows

Steps to create installer:
0. Extract ruby to some folder, i.e. c:\ruby\bin
1. Install required gem. Probably you'll notice messages telling missing required dll like iconv.dll, readline.dll, zlib.dll. Search the dll from the net and copy them to the ruby\bin folder. Make sure everything works by creating and running Ruby on Rails application.
2. Extract ImageMagick to some folder
3. Extract MySQL to some folder
4. Install Inno Setup and ISTool.
5. Open Inno Setup / ISTool and make an .iss file
6. OpenAdd the first entry to iss file:
[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{4C04F356-5D30-42DA-81F2-78AD49AD47A5}
AppName=Sample Application
AppVerName=1.0.0
AppPublisher=Sample Application
AppPublisherURL=http://www.example.com
AppSupportURL=http://www.example.com
AppUpdatesURL=http://www.example.com
DefaultDirName=c:\installation\
DisableDirPage=yes
DefaultGroupName=Sample Application
DisableProgramGroupPage=yes
LicenseFile=license.txt
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes
[Languages]
Name: english; MessagesFile: compiler:Default.isl
[Icons]
Name: {group}\{cm:UninstallProgram,Sample}; Filename: {uninstallexe}
Name: {group}\Setup; Filename: {app}\setup.bat
Name: {group}\Start; Filename: {app}\start.bat

I don't recommend using program files for DefaultDirName, since ruby and mysql probably will throw errors if installed on folder named with a space.

Notice that I also make 2 file called setup.bat and start.bat
setup.bat
@echo off
cd C:\installation\rails_apps\some_app_name
set RAILS_ENV=production
rake db:migrate
start.bat
@echo off
cd C:\installation\rails_apps\some_app_name
set RAILS_ENV=production
ruby script/server
7. Adding Directories and Files
You can add directories like this:
[Dirs]
Name: {app}\ruby
[Sources]
Source: ruby\bin\ruby.exe; DestDir: {app}\ruby\bin

{{app}} stands for installation folder

For files, the first path is your current file path. You can use full path like c:\ or relative path.

Add the extracted ruby directory, mysql, and imagemagick, and application source to the installation file. You might want to sanitize the files first by removing unused files such as gem documentation files.
You can add all the file by hand, but adding 1000+ directories and gazillion files isn't worth it. You can drag and drop directories from windows explorer to ISTool. So downloading ISTool actually necessary.

Don't forget to include setenv.exe to the installation files.

8. Add this on iss file:
[Run]
Filename: {app}\SetEnv.exe; Parameters: "-a PATH %""{app}\ruby\bin"""; Flags: runminimized; StatusMsg: Adding ruby PATH
Filename: {app}\SetEnv.exe; Parameters: "-a PATH %""{app}\mysql\bin"""; Flags: runminimized; StatusMsg: Adding mysql PATH
Filename: {app}\SetEnv.exe; Parameters: "-a PATH %""{app}\ImageMagick"""; Flags: runminimized; StatusMsg: Adding imagemagick PATH
Filename: {app}\SetEnv.exe; Parameters: "-a MAGICK_HOME ""{app}\ImageMagick"""; Flags: runminimized; StatusMsg: Adding magickhome PATH
Filename: {app}\mysql\bin\mysqld.exe; Parameters: --install; Flags: runminimized; StatusMsg: mysql service installation
Filename: {sys}\net.exe; Parameters: start mysql; Flags: runminimized; StatusMsg: Starting mysql service
Filename: {app}\mysql\bin\mysqladmin.exe; Parameters: -u root password masterkey; StatusMsg: changing mysql root password; Flags: runhidden
[UninstallRun]
Filename: {sys}\net.exe; Parameters: stop mysql
Filename: {app}\mysql\bin\mysqld.exe; Parameters: --remove
Filename: {app}\SetEnv.exe; Parameters: "-d PATH %""{app}\ruby\bin"""; Flags: runminimized
Filename: {app}\SetEnv.exe; Parameters: "-d PATH %""{app}\mysql\bin"""; Flags: runminimized
Filename: {app}\SetEnv.exe; Parameters: "-d PATH %""{app}\ImageMagick"""; Flags: runminimized
Filename: {app}\SetEnv.exe; Parameters: "-d MAGICK_HOME ""{app}\ImageMagick"""; Flags: runminimized

{{sys}} stands for system32 folder.
run means programs that runned on installation.
uninstallrun means prorams that runned on uninstallation
Actually you can set environment variables such as PATH using registry, but using setenv really makes things easier.

Now you can compile the installation script on Inno Setup or ISTool.
After you get the setup.exe, you can try installing on clean machine.

1 comments:

Vinoth J said...

I'm a newbie when it comes to Ruby on Rails. I'm trying to develop simple applications in ROR but couldn't find a way to deploy the application on another windows machine. Luckily, I found your blog and I'm gonna try your steps. I'll get back to you if I need any assistance. Thank you!

Post a Comment