Rail Application Installer
I’ve mostly finished extracting Typo’s installer into its own Rails project and .gem
. The installer makes it trivial to build an installable .gem
for any Rails project, so the install process looks like this:
$ gem install my-project
$ my-project install /some/path
The installer source lives in Google Code. That includes a mailing list and bug tracker. I’ll upload my .gem
to RubyForge later today, along with some documentation. For now, the rdoc is available.
Here’s what you’ll need to do to add the installer to your existing Rails app:
- Create a
.gem
that depends onrails-app-installer
,rails
, and all other.gem
s that you need to have installed. - Add an
executable
entry to your gemspec. If your app is calledmy-app
, then addexecutable = ['my-app']
. - Finally, create
bin/my-app
, using one of the examples in therails-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.
Update: The gem is out. gem install rails-app-installer
.