Adding Gems

Will Farrington edited this page Aug 19, 2010 · 1 revision

Moonshine works with rails to get your gem dependency. In addition, it handles installing native dependencies (ie nokogiri requires libxml).

Not using bundler

Adding a new gem to a Rails application managed by Moonshine is a three step process.

1. Add gem to environment.rb

...
config.gem "my_cool_gem"
...

2. Update your config/gems.yml

rake moonshine:gems

This will regenerate your config/gems.yml to reflect the gems in your environment.rb. Be sure to add this to your git repo by doing:

git add config/gems.yml && git commit -m "Added config/gems.yml generated by moonshine"

3. Deploy your application

The next time you deploy your application Moonshine will ensure all gems specified in config/gems.yml are installed on your server.

Using bundler

If you have a Gemfile in your app, then bundle install is run for you automatically during deploy. It will also take care of system dependencies of these gems.

Currently, the bundler support will not install system dependencies, pending a rubygems 1.3.6 release. In the interim, you will need to manually specify these in your application_manifest.rb. For nokogiri, for example, you’d need this:

def application_packages
  package 'libxml2-dev', :before => exec('bundle install')
  package 'libxslt1-dev', :before => exec('bundle install')
end
recipe :application_packages

Native dependencies

Moonshine maintains a mapping of gems to native packages. You can find this in lib/moonshine/manifest/rails/apt_gems.yml.

If you to define extra mappings, you can update this locally in your config/moonshine.yml:

:apt_gems:
  :awesomegem:
    - awesome
    - libawesome-dev

If moonshine is missing mappings for publicly available gems, please open an issue