/rails_setup

Scripts and tasks to setup rail environment

Primary LanguageRubyMIT LicenseMIT

RailsSetup

Provides scripts and tasks to setup your rails environment

Install

./script/plugin install git://github.com/albanpeignier/rails_setup.git

  create script/rails_setup
  create script/rake_with_rails_setup

Features

Install rails gems

rails_setup install gems required by the config/boot.rb of your project.

How: rails_setup loads boot.rb and intercepts Kernel.gem LoadError on ‘rails’ gem. The required gem is silently installed.

Install database gems

rails_setup install gems required by the database adapters configured into the database.yml of your project.

How: rails_setup loads environment.rb and intercepts the error “Please install the xyz adapter”. The required gem(s) is deduced from the adapter name.

A rake task ‘gems:db:prerequisites’ is invoked before the database gem install to install system libraries if needed. For example :

namespace :gems do
  namespace :db do
    task :prerequisites do
      packages = []

      case ENV['ADAPTER_GEMS']
      when 'postgres'
        packages << 'libpq-dev'
      end

      sh "apt-get install --yes #{packages.join(',')}"
    end
  end
end

Note: the supported adapters list is really short for the moment. Contributions are welcome ;)

Install configured gems

rails_setup simply uses the Rails Gem dependencies support. A rake task gem:install_with_sudo is provided to make easier this operation for normal users.

Setup before rask tasks

rake_with_rails_setup runs rails setup before executing specified rake tasks.

Sudo support

By default, all these operations are performed by using sudo. RailsSetup.use_sudo controls this behaviour (no command line for the moment).

Example

Setup your rails environment in a single command:

./script/rails_setup

check if rails gems are needed ...
install rails 2.2.2
sudo gem install rails --version 2.2.2
Successfully installed rake-0.8.3
Successfully installed activesupport-2.2.2
Successfully installed activerecord-2.2.2
Successfully installed actionpack-2.2.2
Successfully installed actionmailer-2.2.2
Successfully installed activeresource-2.2.2
Successfully installed rails-2.2.2
7 gems installed
check if database gems are needed ...
sudo apt-get install --yes ruby-dev libpq-dev
sudo gem install postgres
Building native extensions.  This could take a while...
Successfully installed postgres-0.7.9.2008.01.28
1 gem installed
check if configured gems are needed ...
rake gems:install_with_sudo
(in /home/alban/skyline)

  Warning: You have rspec rake tasks installed in
  /home/alban/skyline/lib/tasks/rspec.rake,
  but rspec can not be found in vendor/gems, vendor/plugins or on the system.

sudo gem install rspec-rails
Successfully installed rspec-1.1.12
Successfully installed rspec-rails-1.1.12
2 gems installed

Setup your rails environment before running a rake task:

./script/rake_with_rails_setup cruise

check if rails gems are needed ...
check if configured gems are needed ...
rake gems:install_with_sudo
rake cruise

Install your configured gems with sudo:

rake gems:install_with_sudo

CruiseControl.rb integration

To use rake_with_rails_setup in Cruisecontrol.rb

Project.configure do |project|

  # ...

  project.build_command = './script/rake_with_rails_setup cruise'

end

Allow the cruisecontrol daemon to run sudo gem, in /etc/sudoers:

ccontrolrb ALL=NOPASSWD: /usr/bin/gem

See cruisecontrolrb.thoughtworks.com/

Copyright © 2009 Alban Peignier, released under the MIT license