Problems with require ‘mongo_mapper’ on cloudfoundry
I’ve been playing a bit with cloudfoundry today, and I wanted to do a simple example that connected to a mongodb service from ruby. Should be simple but I had some trouble. Some of the trouble I am sure stems from the fact that my ruby skills are somewhat rusty. Other from a somewhat alpha-like experience of the cloudfoundry product, which is supposed to be in beta
I started out simple, with these ruby require lines in the top of my ruby sinatra app:
require 'sinatra' require 'json' require 'mongo' require 'mongo_mapper'
Unfortunately, that made vmc update of my app fail. Cloudfoundry couldn’t start the app, and there were no logs or crashlogs to be seen A little trial-n-error told me that it was the require of ‘mongo_mapper’, that made it fail. After some more trial-n-errors and a lot of googling, I could put together the needed bits.
This page at the cloudfoundry site has good info on what is required (and what they know won’t work) when running ruby apps on cloudfoundry. It also said, that I should be using Bundler and a Gemfile to describe my gem dependencies and package the app before deployment. So, I ended up with this Gemfile:
source "http://rubygems.org" gem 'sinatra' gem 'json' gem 'mongo' gem 'mongo_mapper'
and changed the require-lines in the sinatra application ruby file with this single line:
When using bundler we then need to do these two steps before vmc push or update (each time dependencies have changed):
bundle package bundle install
If you don’t have bundler, you can simply do:
sudo gem install bundler