Bug 1049411 - OpenShift Ruby Cartridge confused on which gem version to load
Summary: OpenShift Ruby Cartridge confused on which gem version to load
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: OpenShift Online
Classification: Red Hat
Component: Image
Version: 1.x
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: ---
: ---
Assignee: Michal Fojtik
QA Contact: libra bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-01-07 14:45 UTC by Jason Ng PT
Modified: 2014-06-25 10:40 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2014-01-30 00:55:02 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Jason Ng PT 2014-01-07 14:45:11 UTC
Description of problem:
Ruby Cartridge get confused on which gem version to use when a pre_build action_hook is added.

Version-Release number of selected component (if applicable): Ruby 1.9 Cartridge with Postgresql 9.2 with the activerecord 4.0 gem

How reproducible: Reproducible with steps below.

Steps to Reproduce:
1. Deploy a Ruby application (Sinatra) into OpenShift with activerecord 4.0 gem included in Gemfile. (using Stringer: github.com/swanson/stringer with OpenShift instructions) (Note: to remove the gem pry-byebug as it relies on Ruby 2.0)
2. Add a pre_build action_hook script below.
---
pushd ${OPENSHIFT_REPO_DIR} > /dev/null
bundle install
popd > /dev/null
---
3. Deploy the application again.

Actual results: The error shown below will be encountered during deployment. 
remote: /opt/rh/ruby193/root/usr/share/gems/gems/openshift-origin-common-1.18.1/lib/openshift-origin-common/models/model.rb:13:in `<class:Model>': uninitialized constant ActiveModel::Observing (NameError)
remote: 	from /opt/rh/ruby193/root/usr/share/gems/gems/openshift-origin-common-1.18.1/lib/openshift-origin-common/models/model.rb:6:in `<module:OpenShift>'
remote: 	from /opt/rh/ruby193/root/usr/share/gems/gems/openshift-origin-common-1.18.1/lib/openshift-origin-common/models/model.rb:5:in `<top (required)>'
remote: 	from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:55:in `require'
remote: 	from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:55:in `require'
remote: 	from /opt/rh/ruby193/root/usr/share/gems/gems/openshift-origin-common-1.18.1/lib/openshift-origin-common.rb:22:in `<top (required)>'
remote: 	from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:55:in `require'
remote: 	from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:55:in `require'
remote: 	from /opt/rh/ruby193/root/usr/share/gems/gems/openshift-origin-node-1.18.3/lib/openshift-origin-node/model/frontend_proxy.rb:20:in `<top (required)>'
remote: 	from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:55:in `require'
remote: 	from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:55:in `require'
remote: 	from /opt/rh/ruby193/root/usr/share/gems/gems/openshift-origin-node-1.18.3/lib/openshift-origin-node/model/application_container.rb:18:in `<top (required)>'
remote: 	from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:60:in `require'
remote: 	from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:60:in `rescue in require'
remote: 	from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:35:in `require'
remote: 	from /usr/bin/gear:21:in `<main>'


Expected results: Deployment to be successful.


Additional info: 
Bug encountered when trying to upgrade the app from activerecord 3.2 to 4.0 which uses activemodel 4.0 gem.

Pls let me know if more information is needed.

Comment 1 Michal Fojtik 2014-01-07 16:49:16 UTC
Hi Jason,

I tried to reproduce this, using the OpenShift instructions (https://github.com/swanson/stringer/blob/master/docs/OpenShift.md) and I was able to successfully deploy the Stringer app.

I think you need to add the bundler step into 'deploy' hook instead of pre_build.
Let me know if that helps.

Also I have removed the whole 'development,test' group from Gemfile to make the bundle install --deployment pass.

Comment 2 Jason Ng PT 2014-01-07 17:05:06 UTC
Hi Michal,

Thanks for looking at this. 

Yes, when the 'development,test' group from Gemfile is removed, the bundle install will pass as the gem 'pry-byebug' is the one throwing errors since it requires MRI 2.0.0. Once we remove that gem, the deployment should go through successfully.

Maybe some further background by referring to this issue (https://github.com/swanson/stringer/pull/294). We were trying to do a 'bundle install --without development test' in the OpenShift Ruby to exclude the development, test group in the bundle install. So we will try to minimise the amount of code change the user has to do when deploying to OpenShift.

And I understand that this command has to be in pre_build, else the normal default 'bundle install --deployment' will run first? I tried to put in deploy or build but the default 'bundle install --deployment' run first. Thus the last try was to put into pre_build. 

Not too sure if I am doing it the right way, so pls point me to the correct method to exclude the group in Gemfile if I am wrong. Thanks :)

Comment 3 Michal Fojtik 2014-01-08 09:52:47 UTC
Hi Jason,

I created a pull request yesterday that allow users to pass '--without' option to bundler in OpenShift (https://github.com/openshift/origin-server/pull/4426). This will allow to set BUNDLE_WITHOUT environment variable and prevent devel/test group to be installed.

I think this will address this issue and the pre_build hook will be not longer needed.

Comment 4 Jason Ng PT 2014-01-08 14:44:52 UTC
Awesome, thanks Michal!

So how do we proceed from here? Do I close this bug? Or keep it open for updates?

Thanks again!

Comment 5 Michal Fojtik 2014-01-09 11:22:44 UTC
Jason,

I would keep this BZ open until the code is actually pushed and available in OpenShift Online.


Dan: Marking this as not a release blocker, since this is more like a new feature than bug.

Comment 6 Jason Ng PT 2014-01-09 12:30:51 UTC
Ok thanks again Michal.

Comment 7 chunchen 2014-01-14 11:09:04 UTC
It's fixed, verified on devenv_4219, please refer to the following results:

1. Create a non-scaled app
rhc app create crb18 ruby-1.8

2. Add Gemfile
cd crb18;
cat Gemfile:

source 'https://rubygems.org'
gem 'sinatra'
 
group :development do
gem 'rspec'
end

3. Run bundle install
bundle install --without development

4. Set BUNDLE_WITHOUT env variable
rhc env set BUNDLE_WITHOUT="development" -a crb18

5. Perform a git push
$ git add . && git commit -amp && git push

[master cd967d6] xxx
 2 files changed, 34 insertions(+)
 create mode 100644 Gemfile
 create mode 100644 Gemfile.lock
[chunchen@F17-CCY crb18]$ rhc env set BUNDLE_WITHOUT=development 
Setting environment variable(s) ... done
[chunchen@F17-CCY crb18]$ git push
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 615 bytes, done.
Total 4 (delta 1), reused 0 (delta 0)
remote: Stopping Ruby cartridge
remote: [Tue Jan 14 05:44:05 2014] [warn] PassEnv variable SHELL was undefined
remote: [Tue Jan 14 05:44:05 2014] [warn] PassEnv variable USER was undefined
remote: [Tue Jan 14 05:44:05 2014] [warn] PassEnv variable LOGNAME was undefined
remote: Building git ref 'master', commit cd967d6
remote: Building Ruby cartridge
remote: Bundling RubyGems based on Gemfile/Gemfile.lock to repo/vendor/bundle with 'bundle install --deployment --without "development"'
remote: Fetching gem metadata from https://rubygems.org/..........
remote: Fetching gem metadata from https://rubygems.org/..
remote: Installing rack (1.5.2) 
remote: Installing rack-protection (1.5.1) 
remote: Installing tilt (1.4.1) 
remote: Installing sinatra (1.4.4) 
remote: Using bundler (1.3.5) 
remote: Your bundle is complete!
remote: Gems in the group development were not installed.
remote: It was installed into ./vendor/bundle
remote: Preparing build for deployment
remote: Deployment id is b2de17bb
remote: Activating deployment
remote: Starting Ruby cartridge
remote: Result: success
remote: Activation status: success
remote: Deployment completed with status: success
To ssh://52d51385d83976a7b600013e.rhcloud.com/~/git/crb18.git/
   f2c94b3..cd967d6  master -> master

Comment 8 Arash S. 2014-06-25 10:40:10 UTC
Hi there,

this Issue is marked as closed, though I am currently facing the same problem described here: https://bugzilla.redhat.com/show_bug.cgi?id=1039022#c3

Cheers,
A.


Note You need to log in before you can comment on or make changes to this bug.