Capistrano + RVM + Rake task - ruby

I have a project which
uses rvm ruby 1.9.2 (set in .rvmrc in project dir).
deploying with capistrano.
has a rake task I want to run remotely from my local machine by capistrano.
I've created a .sh file to run my task:
cd /var/www/pluslook/current
/home/kirill/.rvm/scripts/rvm use 1.9.2#pluslook
/home/kirill/.rvm/gems/ruby-1.9.2-p180#pluslook/bin/rake parse:feed RAILS_ENV="production" --trace
But when I'm trying to run this task i have an error:
Using /home/kirill/.rvm/gems/ruby-1.9.2-p180 with gemset pluslook
Could not find linecache19-0.5.12 in any of the sources
Run `bundle install` to install missing gems.
I've installed all my gems in project's current directory so it looks like rake task is running from another directory. When I'm trying to run task from capistrano, It shows me the same error.
Thank you and sorry for my English:)

do you have 'require "bundler/capistrano"' in config/deploy.rb
did you run "bundle install" before commit latest code changes?

Related

How do I debug a Ruby Gem in a different directory in the context of a bundle in IntelliJ IDEA

I am using IntelliJ IDEA to develop a Ruby gem.
To run the gem from the command line without installing it first I am using:
bundle exec my_gem
This works fine.
I can also create a Gem Command run configuration within IntelliJ IDEA and that works.
What I actually want to do is to run this gem in another directory.
Using bundler:
bundle exec --gemfile /path/to/my_gem my_gem
However from IntelliJ IDEA can't get this to work as there is no way to specify the path to the Gemfile. It fails saying:
Could not locate Gemfile or .bundle/ directory
Anyone know a solution to this?

Jenkins and running rake tasks

I'm having some issues running a rake task from within Jenkins (within a docker container) as part of a build process (I have the Rake plugin installed). I am getting the error
java.io.IOException: Cannot run program "rake" (in directory "/var/jenkins/workspace/HendricksFeaturesCopy"): error=2, No such file or directory
Which i don't understand as when i pwd $ECHO before the rake task is invoked i get.
/var/jenkins/workspace/HendricksFeaturesCopy
So i'm in the correct place and rake is installed as its located here
/usr/local/rvm/rubies/ruby-2.3.0/bin/rake
My Rakefile looks like
import 'lib/tasks/yard-docs.rake'
lib/tasks/yard-docs.rake
require 'yard'
namespace :yard_docs do
desc 'Generate Yard Documentation'
task :generate do
# Generate Yard Documentation
end
end
Does anyone know how to rectify this or what I am missing?
UPDATE
After doing echo $PATH
/usr/local/rvm/gems/ruby-2.3.0/bin:/usr/local/rvm/gems/ruby-2.3.0#global/bin:/usr/local/rvm/rubies/ruby-2.3.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/rvm/bin
So this means the correct gemset is being used and when I have done rvm #global do gem list
rake (10.4.2)
So, rake is available right ?
Make sure /usr/local/rvm/rubies/ruby-2.3.0/bin/ is in your $PATH.
PATH=/usr/local/rvm/rubies/ruby-2.3.0/bin/:$PATH
Alternatively, symlink /usr/local/rvm/rubies/ruby-2.3.0/bin/rake to /usr/local/bin/
ln -s /usr/local/rvm/rubies/ruby-2.3.0/bin/rake /usr/local/bin/

Heroku: where did my gems go?

I have been deploying a Rails 3.2 application to heroku for several weeks now. I have also been executing rake tasks on the Cedar stack where my application is located.
One day after a deploy I noticed that rake was no longer working. I get, for example, the following:
$:~/dev/my_project$ heroku run rake -T
Running `rake -T` attached to terminal... up, run.7566
bundler: command not found: rake
Install missing gem executables with `bundle install`
Trying to run commands with bundle exec yields the same results.
What I've tried:
heroku run bundle install. This works and informs me that gems were installed into ./vendor/bundle. However, heroku run ls ./vendor/bundle yields only the following:
$:~/dev/my_project$ heroku run ls ./vendor/bundle/
Runningls ./vendor/bundle/attached to terminal... up, run.3458
bin ruby
bundle package. Although the deployment works it does not help my problem.
fiddling around with the rubygems-bundler gem (although I think this is now part of core bundler). This does not seem to have any effect.
On Heroku, gems are installed within the vendor/bundle/ruby/<version>/gems directory. I just checked my Heroku instance and confirmed this.
You are going to want to use bundle exec rake task because the gems are not in the users PATH.

rake install does not work for octopress

I am trying to setup rake via this doc.
http://octopress.org/docs/setup/
But I get some errors.
ikhthiandor#ikhthiandor-Satellite-L450:/opt/octopress$ rake install
## Copying classic theme into ./source and ./sass
mkdir -p source
rake aborted!
Permission denied - source
Tasks: TOP => install
(See full trace by running task with --trace)
With sudo I get this output.
ikhthiandor#ikhthiandor-Satellite-L450:/opt/octopress$ sudo rake install
rake aborted!
no such file to load -- bundler/setup
(See full trace by running task with --trace)
Here is a list of files in the directory.
ikhthiandor#ikhthiandor-Satellite-L450:/opt/octopress$ ls -a
. config.ru .git Rakefile .slugignore
.. _config.yml .gitignore .rbenv-version .themes
CHANGELOG.markdown Gemfile plugins README.markdown
config.rb Gemfile.lock .powrc .rvmrc
How can I solve the problem?
Ikhthiandor: Looks like you are a beginner in the ruby/rails world.
By running the rake install command, you are installing the default octopress theme using the rake tool. Not trying to setup rake as you mention in the question.
The first error ( Permission denied - source when trying mkdir -p source - as you correctly guessed - is because the user doesn't have permissions to create that directory.
The second error ( no such file to load -- bundler/setup ) is because the previous install dependencies steps are not performed correctly (for the user running this command).
The install dependencies steps to be completed successfully are:
1. gem install bundler
2. rbenv rehash # If you use rbenv, rehash to be able to run the bundle command
3. bundle install
I am guessing you ran these steps successfully as 'ikhthiandor' user, so the bundler gem is not available for the 'sudo' user.
You can fix this by either of the following options:
changing permissions on /opt/octopress folder so that 'ikhthiandor' user has rights to create sub-folders/files within.
Run all the commands in the Octopress Setup doc as 'sudo'
Best practice would be to use either rvm or rbenv to manage custom installations of ruby environments per user (and not do everything as super user).
If you are indeed a fresher in the ruby-rails world, and want to step up your knowledge of the tools and the best practices in the ruby/rails world, I suggest browsing through the first few chapters of the Ruby on Rails Tutorial book that is available for free on-line.
HTH

Capistrano: run_locally in separate project

I'm using capistrano for deployment. I'm trying to define a task which will:
cd other-rails-app && bundle exec rake sometask
But it's complaining about Rake not being part of the bundle (which is obviously not true in the project where I am trying to run this task). I think it must be altering the environment somehow before executing the command and assuming bundler is already loaded (which is true in the capistrano task, but it's the wrong Gemfile).
How do I run a command locally with capistrano with a clean environment?
I figured out the problem. When you run capistrano, the BUNDLE_GEMFILE environment variable gets set to the Gemfile of the current project. So when you run bundle exec rake, Bundler looks first to the Gemfile set in the environment. The solution is to "reset" this Gemfile variable. I created a script for running my rake task in the root of my other project.
So instead of doing:
run_locally "cd other-rails-app && bundle exec rake mytask"
I do this:
run_locally "cd other-rails-app && ./mytask.rb"
In the mytask.rb file I do this:
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] = File.expand_path('Gemfile', File.dirname(__FILE__))
require 'bundler/setup'
%x{rake mytask}

Resources