Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with rvm on local tasks with different gemsets #52

Open
mminklet opened this issue Feb 4, 2015 · 10 comments
Open

Help with rvm on local tasks with different gemsets #52

mminklet opened this issue Feb 4, 2015 · 10 comments

Comments

@mminklet
Copy link

mminklet commented Feb 4, 2015

Hi, I'm not sure if this is something that can be helped here, as I am not using this gem - but I will if it turns out that it can do what I hope to do. I don't want to install or use ruby or rvm on production, I'm looking to run rvm locally in capistrano, so I can compile sass locally and copy to production. Below is my, expanded, question I posted in the capistrano issue queue, but was directed here. Thanks in advance


I have come across a couple of sort of efforts to document this, and another that is out of date: I want to run compass compile through my projects already defined rvm gemset, using capistrano (which was installed using it's own gemset), and then upload the compiled css to the production server. I would assume that capistrano wouldn't force you to fix to a ruby version and gemset as these are all different across projects, or would it?

Anyway, I am trying to get capistrano working with a drupal site, specifically with the gemsets that the project was set up with long ago.

So, we have a themes folder where we run rvm 1.9.3@omega do compass compile, and capistrano installed to 2.1.5@deploy a few folders above it. The following commands were used to install compass capistrano:

rvm 2.1.5@deploy do bundle install (capistrano above the docroot)
rvm 1.9.3@omega do bundle install (compass and other gems, inside the drupal theme folder (docroot/sites/themes/all/omega)

I am running this task in my deploy.rb, after publishing

desc "Compile locally"
task :compile_locally do
  run_locally do
    execute "cd ../#{fetch(:theme_path)} && rvm 1.9.3@omega do compass compile"
  end
end

Which outputs this command

cd ../docroot/sites/all/themes/omega && rvm 1.9.3@omega do compass compile

Which works fine from the command line, in the folder I run cap from...however I get this error message when I try and run cap production deploy

cap aborted!
SSHKit::Command::Failed: cd ../docroot/sites/all/themes/omega && rvm 1.9.3@omega do compass compile exit status: 256
cd ../docroot/sites/all/themes/omega && rvm 1.9.3@omega do compass compile stdout: Nothing written
cd ../docroot/sites/all/themes/omega && rvm 1.9.3@omega do compass compile stderr: /Users/MIchael/.rvm/gems/ruby-2.1.5@global/gems/bundler-1.7.9/lib/bundler/rubygems_integration.rb:256:in `block in replace_gem': compass is not part of the bundle. Add it to Gemfile. (Gem::LoadError)

Which suggests it is not using the right ruby version/gemset...which I can kind of understand as capistrano is using that version of ruby...however I'm a bit stuck how to get round it. I don't want to have to manually compile compass everytime.

I should point out that I am very much learning capistrano, and ruby in general, so I am happy to take on board any ideas about how to go about this properly. I didn't use this gem as it seemed to be more about running rvm remotely, which I am not looking to do.

@mpapis
Copy link
Member

mpapis commented Feb 16, 2015

Hi I will try to look into it before the end of week, in this time you can check out http://niczsoft.com/2015/02/changes-in-my-open-source-life/

@mminklet
Copy link
Author

Hi, did you link to the right article?

@mpapis
Copy link
Member

mpapis commented Feb 17, 2015

yes it's right, a little background why you have to wait

@mminklet
Copy link
Author

Ah right, yeah I'm fine with waiting. In the meantime I have been compiling manually and using the scp utilitiy in capistrano. I tried installing the capistrano gem into the same gemset as the projects compass etc, but that caused another error.

@havenwood
Copy link
Member

@MichaelMallett By default RVM integrates with Bundler with the help of the rubygems-bundler gem. This handily automatically prefixes bundle exec to commands to run in the context of the bundle when a Gemfile is present.

It seems that here you don't actually want to be running in the context of the bundle, since Compass is not in the Gemfile file. You can explicitly disable rubygems-bundler's automatic bundle exec by prefixing NOEXEC_DISABLE=1 to a command.

@mminklet
Copy link
Author

Hi, thanks for the response, but I think you may be misunderstanding me, our compass is in a gemfile.

We have a standard drupal theme, inside that is a gemfile, and we have that bundle installed to a project specific ruby gem with rvm. There's a lot of these projects with different requirements so

Outside of the root directory of the site (but inside the project) we have the deploy folder containing the capistrano script, the gemfile (and lock) containing the capistrano gem. This is installed to a gemset too, we don't want to install Capistrano 30 times on each machine into different gemsets, so this is in it's own 'deploy' gem using ruby 2.1.5. I tried adding capistrano into the theme gemfile and bundle installing again to bring them all together, but that caused other issues...and that's not really a viable solution to all our older projects.

Problem is that the projects theme uses a different gemset and ruby version to capistrano in order to compile sass, because surely that's the whole point of rvm. So when capistrano calls rvm 1.9.3@omega do compass compile in the sites theme folder, it is not actually using the correct ruby version or gemset. You can see that from the path in error message
.rvm/gems/ruby-2.1.5@global/gems/bundler-1.7.9/

Gemfile in the theme folder ([root]/sites/all/themes/omega/Gemfile using 1.9.3@omega)

source 'https://rubygems.org'

group :development do

Sass, Compass and extensions.

gem 'sass' # Sass.
gem 'sass-globbing' # Import Sass files based on globbing pattern.
gem 'compass' # Framework built on Sass.
gem 'compass-validator' # So you can compass validate.
gem 'compass-normalize' # Compass version of normalize.css.
gem 'compass-rgbapng' # Turns rgba() into .png's for backwards compatibility.
gem 'susy' # Susy grid framework.
gem 'singularitygs' # Alternative to the Susy grid framework.
gem 'toolkit' # Compass utility from the fabulous Snugug.
gem 'breakpoint' # Manages CSS media queries.
gem 'oily_png' # Faster Compass sprite generation.
gem 'css_parser' # Helps compass stats output statistics.

Guard

gem 'guard' # Guard event handler.
gem 'guard-compass' # Compile on sass/scss change.
gem 'guard-shell' # Run shell commands.
gem 'guard-livereload' # Browser reload.
gem 'yajl-ruby' # Faster JSON with LiveReload in the browser.

Dependency to prevent polling. Setup for multiple OS environments.

Optionally remove the lines not specific to your OS.

https://github.com/guard/guard#efficient-filesystem-handling

gem 'rb-inotify', '~> 0.9', :require => false # Linux
gem 'rb-fsevent', :require => false # Mac OSX
gem 'rb-fchange', :require => false # Windows

end

Gemfile in the deploy folder ([root]/deploy/Gemfile using 2.1.5@deploy)
source 'https://rubygems.org'
gem 'capistrano', '~> 3.1.0'

@havenwood
Copy link
Member

It seems that the run_locally command is detecting the pre-cd deploy/Gemfile, which prefixes bundle exec and that bundle executable is the 2.1.5 Bundler you're seeing. At least I think that's what's happening.

@mminklet
Copy link
Author

mminklet commented Mar 3, 2015

Is there any way of avoiding this?

@mpapis
Copy link
Member

mpapis commented Mar 3, 2015

check rubygems/bundler#1133

@mminklet
Copy link
Author

mminklet commented Mar 3, 2015

Is that the right issue? I don't see how they are related. Also, I am using bundler 1.7.12 and apparently whatever issue this is was fixed in 1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants