Installing private ruby gem in rails project using heroku

If you have a private gem, deploying to heroku can be frustrating.. In my case, I do not have even a server so I am not looking (yet) to set up a private rubygem server. I just have another project on my machine that I would like to reuse as a gem.

Could not find gem ‘pgw’ ( >= 0, runtime)’ in any of the gem sources listed in your Gemfile

I tried Ole Morten Amundsen’s method, but it didn’t ( quite ) work (see below)

Magic directory method

  1. mkdir -p vendor/cache
  2. bundle update
  3. git add -A
  4. git commit -m"whatever"
  5. git push heroku master

All the gems public or private are installed into the vendor/cache directory.

Pros:

  1. Simple.
  2. It works.
  3. Also allows for a locked down deployment (? not completely certain on this because heroku does report “Installing …” for all the gems including the private gem)

Cons:

  1. All the gems used are installed, not just the single gem that is not available on rubyforge.
  2. Magicalness feels like a possible bug. (Note: I am using bundler 1.0.13) so it may not work in future
  3. git bloat – all the external gems and dependencies are now part of your repo.
  4. Possible issues with machine specific deployments with other gems? ( not certain about this – but flagging it as a possibility )

Ole Morten Amundsen variant

  1. gem unpack pgw --target vendor/gems
  2. edit Gemfile to explicitly list the gem version and supply the path
    gem "pgw", "0.0.3", :path =>"{#File.expand_path(__FILE__)}/../vendor/gems/"
  3. bundle install --local
  4. git add -A
  5. git commit -m"whatever"
  6. git push heroku master

The resulting Gemfile.lock will have this:


PATH
  remote: vendor/gems
  specs:
    pgw (0.0.3)

GEM
...(everything else ) ...

Pros:

  1. Feels more like the intended process
  2. Only extra code is the private gem ‘pgw’ – none of the standard ruby gems are added to the project.

Cons:

  1. More typing
  2. Have to include specific version number in the Gemfile – so harder to ensure against an accidental release with old version of gem.
  3. “unpacking” seems lame. Is there a way to keep the ‘pgw’ gem as a .gem file?

Questions

  1. Is there an easy way to move the gems to my master project other than gem unpack?
  2. should the gem be put in vendor/bundle since that is the default BUNDLE_PATH?
This entry was posted in help notes, ruby, technical. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *