I've added capistrano-recipes to my Gemfile
group :development do
...
gem 'capistrano-recipes',require: false
end
Added to my deploy script:
require 'capistrano-recipes'
The result of bundle list:
bundle list | grep capistrano
* capistrano (2.15.5)
* capistrano-ext (1.2.1)
* capistrano-platform-resources (0.1.3)
* capistrano-rbenv (1.0.5)
* capistrano-recipes (0.8.0)
But when I'm running command like cap -T I got error:
/usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/capistrano-2.15.5/lib/capistrano/configuration/loading.rb:152:in `require': cannot load such file -- capistrano-recipes (LoadError)
from /usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/capistrano-2.15.5/lib/capistrano/configuration/loading.rb:152:in `require'
from ./config/deploy.rb:12:in `load'
What might be a problem here? Thanks
From the README, this is what you should put in your deploy script:
require 'capistrano_recipes'
Note that it uses an underscore, and not a hyphen.
Either install the gem globally
gem install capistrano-recipes
cap -T
or just:
bundle exec cap -T
Related
Let's experiment with a random gem, it doesn't matter which.
# Gemfile
gem "hashie"
Let's install our bundle in a (semi) non-standard place, so that ruby can't find it:
bundle install --path=vendor/bundle
ruby -e 'require "hashie"'
# cannot load such file -- hashie (LoadError)
As expected, if we add bundle exec to the above, then ruby -e can find our gem:
bundle exec ruby -e 'puts require "hashie"'
# true
But, even with bundle exec, ruby -r cannot find our gem!
bundle exec ruby -r hashie -e 'puts "win"'
# cannot load such file -- hashie (LoadError)
The only way I have found to combine bundle exec and ruby -r is:
bundle exec ruby -r 'bundler/setup' -r hashie -e 'puts "win"'
# win
The documentation for bundle exec does not mention ruby -r, so I ask here, is this the correct way?
-r 'bundler/setup'
is acceptable. It means to "require all of the gems in my Gemfile".
'hashie' could not load its dependencies that is why "LoadError" occurred.
reference: bundler_setup
Let me preface this with this all runs locally and succeeds.
Source code repo
Travis log for job #4.1
Error:
$ rake
rake aborted!
LoadError: cannot load such file -- rspec/core/rake_task
/home/travis/build/alienfast/gulp-pipeline-rails/Rakefile:4:in `<top (required)>'
/home/travis/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `eval'
/home/travis/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `<main>'
(See full trace by running task with --trace)
.travis.yml
language: ruby
rvm:
- 2.2.2
- ruby-head
matrix:
allow_failures:
- rvm: ruby-head
cache: bundler
before_script:
# install Gulp 4 CLI tools globally from 4.0 GitHub branch
- npm install gulpjs/gulp-cli#4.0 -g
script: rake
Gemfile
gemspec
# travis-ci quirk?
group :development, :test do
gem 'rake'
gem 'rspec'
gem 'rspec-rails'
gem 'capybara'
gem 'capybara-webkit'
end
Fix attempts:
Locally, I have emptied my rvm gemset, deleted locks, and replicated the travis build - still works
I tried moving the necessary test gems from the gemspec to the Gemfile
So I'm pretty confused, I have other projects that don't have this problem and I don't see anything obvious. Is there any reason to get LoadError: cannot load such file -- rspec/core/rake_task?
Have you tried using bundle exec rake -t As noted here LoadError: cannot load such file -- rspec/core/rake_task
I'd like to use gems specified from Gemfile that I uploaded. However, I keep getting
/usr/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- capybara (LoadError) from /usr/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' from app.rb:3:in `<main>'
Seems like the code cannot find the required gems. This is my .worker file:
runtime "ruby"
stack "ruby-2.1"
exec "app.rb"
gemfile "Gemfile"
full_remote_build true
My Gemfile:
source "https://rubygems.org"
gem "capybara"
gem "capybara-webkit"
I uploaded my work using this command:
zip -r my_work.zip . ; iron worker upload --zip my_work.zip --name my_work iron/ruby ruby app.rb ; iron worker queue --wait my_work
Thanks in advance.
There's a couple things here:
1) you are using full_remote_build with a .worker file, but then uploading the zip. Those two things don't go together, it's one or the other.
2) Be sure you are vendoring the gems so they are included when you zip them. To vendor: docker run --rm -v "$PWD":/worker -w /worker iron/ruby:dev bundle install --standalone --clean. Then at the top of your script, add: require_relative 'bundle/bundler/setup'.
See the documentation here for more details: https://github.com/iron-io/dockerworker/tree/master/ruby
created a demo gem
built it :
gem build control.gemspec
Successfully built RubyGem
Name: process_controller
Version: 0.0.1
File: process_controller-0.0.1.gem
installed it:
gem install --local process_controller-0.0.1.gem
Successfully installed process_controller-0.0.1
1 gem installed
but I can't seem to require it :
irb (from the installed directory)
2.1.5 :001 > require 'process_controller'
LoadError: cannot load such file -- process_controller
from /Users/partuck/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/partuck/.rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from (irb):1
from /Users/partuck/.rvm/rubies/ruby-2.1.5/bin/irb:11:in `<main>'
also tried
require 'control' # since it's in the control directory
bundle show output:
bundle show
Gems included by the bundle:
* bundler (1.7.9)
* process_controller (0.0.1)
here is a screen shot of the directory structure
http://cl.ly/image/2t1s331e273u
turns out you can't require the gem, you have to require the main file name.
in my case its:
require 'control'
thanks a lot #matt
My objective is to setup a cron entry to run a rake task on my Opsworks rails application layer.
I have followed the AWS doco on this subject found here
My Chef Job:
cron_env = {"PATH" => "/usr/local/bin:$PATH"}
cron "warm up the cache" do
environment cron_env
hour "5"
minute "10"
command "cd /srv/www/myapp/current && RAILS_ENV=production bundle exec rake cache:warm_api"
end
The crontab on the instance:
user#myinstance:~$ sudo crontab -l -u root
# Chef Name: warm up the cache
PATH=/usr/local/bin:$PATH
10 5 * * * cd /srv/www/myapp/current && RAILS_ENV=production bundle exec rake cache:warm_api
My ruby -v in /usr/local/bin:
user#myinstance:~$ /usr/local/bin/ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
THE PROBLEM:
During execution, my cron fails to use the correct ruby.
/usr/local/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/definition.rb:385:in `validate_ruby!': Your Ruby version is 1.9.3, but your Gemfile specified 2.1.2 (Bundler::RubyVersionMismatch)
from /usr/local/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler.rb:117:in `setup'
from /usr/local/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/setup.rb:17:in `<top (required)>'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require
This turned out to be temporary glitch in Opsworks.