[Rails] [ANN] GEM-based rails application installer

Scott Laird scott at sigkill.org
Fri Jul 28 22:51:26 GMT 2006


I just uploaded the first version of my .gem-based Rails application installer
to Rubyforge (http://rubyforge.org/projects/rails-installer/; gem install
rails-app-installer). This is extracted from Typo 4.0, and it's intended to
make it easy to build user-friendly installers for Rails applications.

This isn't intended to compete with Capistrano; it's much lighter-weight, and
aimed towards normal users installing applications, not production deployments
of internally-developed software.

Here's what users need to do to install an app via this installer:

   $ sudo gem install my-app
   $ my-app install /some/path

or, without root:

   $ gem install -i ~/gems my-app
   $ ~/gems/bin/my-app install /some/path

This will build a working Typo install in /some/path, using Mongrel and
SQLite3 by default. These can both be changed via configuration settings; see
recent articles on http://scottstuff.net for details.

Here's what you'll need to do to add the installer to your existing Rails app:

1.  Create a `.gem` that depends on `rails-app-installer`, `rails`, and all
    other `.gem`s that you need to have installed.
2.  Add an `executable` entry to your gemspec.  If your app is called
   `my-app`, then add `executable = ['my-app']`.
3.  Copy the 'rails_app_installer.yml' file from the rails-app-installer .gem
    into a directory called 'installer' in your application.
4.  Finally, create `bin/my-app`, using one of the examples in the
    `rails-app-installer` SVN tree as an example.

Here's a short example `bin/my-app`:

      #!/usr/bin/env ruby

      require 'rubygems'
      require 'rails-installer'

      class AppInstaller < RailsInstaller
        application_name 'my_app'
        support_location 'my website'
        rails_version '1.1.4'
      end

      # Installer program
      directory = ARGV[1]

      app = AppInstaller.new(directory)
      app.message_proc = Proc.new do |msg|
        STDERR.puts " #{msg}"
      end
      app.execute_command(*ARGV)

That's all that's needed--as long as the installer gem is installed, this will
give you a full installer that supports installs, upgrades, db backups and
restores, and all of the other things that the Typo installer currently
provides. Adding application-specific installer subcommands is easy. Here's
the `sweep_cache` implementation from Typo's installer:

      class SweepCache < RailsInstaller::Command
        help "Sweep Typo's cache"

        def self.command(installer, *args)
          installer.sweep_cache
        end
      end

That's all that's needed to implement the `typo sweep_cache /some/path`
installer command. Er, except for adding a 'sweep_cache' method to
AppInstaller, but that's up to you :-).


More information about the Rails mailing list