Question

I can't get Capistrano to run bundle commands and rake commands. I get debug logs like this:

DEBUG [0f557e7e]    /usr/bin/env: bundle
DEBUG [0f557e7e]    : No such file or directory

I have RVM on all ma computers (dev and production)

Here's my config:

deploy.rb

lock '3.1.0'

set :application, 'blog'
set :repo_url, 'git@github.com:xxx/yyyy.git'

set :deploy_to, '/home/joel/apps/blog'

set :deploy_via, :copy


set :rvm_ruby_version, '2.1.0p0'
set :default_env, { rvm_bin_path: '/home/joel/.rvm/bin:$PATH' }

SSHKit.config.command_map[:rake] = "#{fetch(:default_env)[:rvm_bin_path]}/rvm ruby-#{fetch(:rvm_ruby_version)} do bundle exec rake"


namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
      execute :touch, release_path.join('tmp/restart.txt')
    end
  end

  desc 'Migrate db'
  task :migrate do
    on primary :db do
      within release_path do
          execute :rake, 'db:migrate'
      end
    end
  end

  desc 'Bundle install'
  task :bundle do
    on primary :app do
      within release_path do
          execute :bundle, 'install'
      end
    end
  end


  after :publishing, :restart

  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
      # Here we can do anything such as:
      # within release_path do
      #   execute :rake, 'cache:clear'
      # end
    end
  end

end

production.rb

role :app, %w{xxx@yyy.com}
role :web, %w{xxx@yyy.com}
role :db,  %w{xxx@yyy.com}
server 'yyy.com', user: 'xxx', roles: %w{web app}, my_property: :my_value

capfile

require 'capistrano/setup'

require 'capistrano/deploy'

require 'capistrano/rvm'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'


Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }

and when I try to call

cap production deploy:bundle

if I want to call bundle:install on the production server, here's what I get :

 INFO [0f557e7e] Running /usr/bin/env bundle install on yyy.com
DEBUG [0f557e7e] Command: cd /home/joel/apps/blog/current && ( RVM_BIN_PATH=/home/joel/.rvm/bin:$PATH /usr/bin/env bundle install )
DEBUG [0f557e7e]    /usr/bin/env: bundle
DEBUG [0f557e7e]    : No such file or directory

Although, if I ssh onto the server and copy-paste that command, it works fine. (and the same thing happens with take commands, like rake db:migrate). I'm pretty sure it has something to do with the paths, so here's my

rvm info

ruby-2.1.0:

  system:
    uname:       "Linux li101-172 3.12.6-x86_64-linode36 #2 SMP Mon Jan 13 18:54:10 EST 2014 x86_64 x86_64 x86_64 GNU/Linux"
    system:      "ubuntu/12.04/x86_64"
    bash:        "/bin/bash => GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu)"
    zsh:         "/usr/bin/zsh => zsh 4.3.17 (x86_64-unknown-linux-gnu)"

  rvm:
    version:      "rvm 1.25.14 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]"
    updated:      "15 days 19 hours 42 minutes 40 seconds ago"
    path:         "/home/joel/.rvm"

  ruby:
    interpreter:  "ruby"
    version:      "2.1.0p0"
    date:         "2013-12-25"
    platform:     "x86_64-linux"
    patchlevel:   "2013-12-25 revision 44422"
    full_version: "ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]"

  homes:
    gem:          "/home/joel/.rvm/gems/ruby-2.1.0"
    ruby:         "/home/joel/.rvm/rubies/ruby-2.1.0"

  binaries:
    ruby:         "/home/joel/.rvm/rubies/ruby-2.1.0/bin/ruby"
    irb:          "/home/joel/.rvm/rubies/ruby-2.1.0/bin/irb"
    gem:          "/home/joel/.rvm/rubies/ruby-2.1.0/bin/gem"
    rake:         "/home/joel/.rvm/rubies/ruby-2.1.0/bin/rake"

  environment:
    PATH:         "/home/joel/.rvm/gems/ruby-2.1.0/bin:/home/joel/.rvm/gems/ruby-2.1.0@global/bin:/home/joel/.rvm/rubies/ruby-2.1.0/bin:/home/joel/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
    GEM_HOME:     "/home/joel/.rvm/gems/ruby-2.1.0"
    GEM_PATH:     "/home/joel/.rvm/gems/ruby-2.1.0:/home/joel/.rvm/gems/ruby-2.1.0@global"
    MY_RUBY_HOME: "/home/joel/.rvm/rubies/ruby-2.1.0"
    IRBRC:        "/home/joel/.rvm/rubies/ruby-2.1.0/.irbrc"
    RUBYOPT:      ""
    gemset:       ""

edit:

I also tried removing all paths, and using PermitUserEnvironment in ~/.ssh/environment

and changing my task to loo

  desc 'Bundle install'
  task :bundle do
    on primary :app do
      within release_path do
          execute 'source ~/.zshrc && cd ~/apps/blog/current/ && bundle install'
          execute 'source ~/.zshrc && cd ~/apps/blog/current/ && RAILS_ENV=production rake db:migrate'
          execute 'source ~/.zshrc && cd ~/apps/blog/current/ && RAILS_ENV=production rake assets:precompile'
      end
    end
  end

and it works. So the problem was really with the paths, but is there a way to use symbols to avoid using the source and cd ?

Was it helpful?

Solution

I ended up reinstalling RVM and my path problems were solved. I still don't know why it works, but it works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top