
A Standard for Bootstrapping Rails - sant0sk1
http://adam.blog.heroku.com/past/2008/8/4/a_standard_for_bootstrapping_rails/
======
mhartl
Rails bootstrapping is even more complicated than it looks. As Adam noted, at
Insoshi we _used_ to use

    
    
      $ rake install
    

The source of this is

    
    
      require 'active_record'
      require 'active_record/fixtures'
    
      desc "Install Insoshi"
      task :install => :environment do |t|
        Rake::Task["db:migrate"].invoke
        Preference.create!
      end
    
    

But in edge Insoshi, which uses Rails 2.1, we switched to a simple script in
order to accommodate the new way to handle gem dependencies:

    
    
      $ script/install
    

It looks like this:

    
    
      #!/usr/bin/env ruby
    
      # Create some files and directories so they won't be created as root.
      # This doesn't do the actual installation, since that needs to be done as root.
      system("rake gems:install")
      # Install the gem dependencies (if any).
      system("sudo rake gems:install")
      # Run the main install task.
      system("rake install")
    

You can see that it calls the installation Rake task at the end. Why not just
put the gems:install task in the Rake task? This seems like it should work:

    
    
      require 'active_record'
      require 'active_record/fixtures'
    
      desc "Install Insoshi"
      task :install => :environment do |t|
        Rake::Task["gems:install"].invoke
        system("sudo rake gems:install")
        Rake::Task["db:migrate"].invoke
        Preference.create!
      end
    

Unfortunately, running all the Rake tasks together like this fails, since the
install task relies on the gem dependencies being met, but they _aren't_ met
at the time the environment gets loaded. (If there is a way to _force_ an
environment reload inside Rake, that would work, but I don't know how to do
that.)

So, to ensure the greatest flexibility, maybe standard installation
_shouldn't_ be a Rake task. I admit that feels a bit weird, but unless we can
crack the environment reload problem I don't see any other way.

~~~
thwarted
Why not make script/install a shell script?

~~~
mhartl
It is.

