Rails 3 — Bundler/Capistrano Errors

前端 未结 8 1605
攒了一身酷
攒了一身酷 2020-12-07 13:39

I have a basic Rails 3 app working locally on my development box, but want to test out deploying early on to make sure everything works. I\'m using Capistrano to deploy.

相关标签:
8条回答
  • 2020-12-07 13:43

    UPDATE:

    For RVM >= 1.11.3, you should now just use the rvm-capistrano gem. For older RVM >= 1.0.1, the answer below still applies.


    ORIGINAL ANSWER:

    Okay, though I still haven't gotten a full cap deploy to work, I did fix this problem. The problem was Capistrano trying to use a different path for Bundler (and other gems) than the RVM paths.

    Check your Capistrano path by doing cap shell, then echo $PATH. You'll probably see your standard /usr/local/bin and /usr/bin, but that's not where RVM has Bundler, et al., stored.

    Edit your Capistrano config/deploy.rb file, and add the following lines, per these instructions:

    # Add RVM's lib directory to the load path.
    $:.unshift(File.expand_path('./lib', ENV['rvm_path']))
    
    # Load RVM's capistrano plugin.    
    require "rvm/capistrano"
    
    set :rvm_ruby_string, '1.9.2'
    set :rvm_type, :user  # Don't use system-wide RVM
    

    That finally got Capistrano to see Bundler and start loading gems appropriately.

    0 讨论(0)
  • 2020-12-07 13:43

    That last line should actually be

    set :rvm_type, :user
    

    that is, user must be a symbol and not a variable, otherwise you'll get

    undefined local variable or method `user'
    
    0 讨论(0)
  • 2020-12-07 13:49

    Bundler isn't found because .bash_profile is not being loaded and thus your PATH is wrong. This is probably because you have the RVM script in .bash_profile.

    The simple answer is to move the RVM script from .bash_profile to .bashrc and Capistrano should be able to find it (also verify that .bash_profile sources .bashrc).

    Capistrano uses SSH to execute commands on the server via a non-interactive shell. This shell session will source .bashrc but not .bash_profile. I added an ECHO statement to both and ran an LS via SSH. You can see in the results below that only .bashrc is sourced:

    $ ssh user@123.amazonaws.com ls
    .bashrc loaded
    git
    file1
    file2
    
    0 讨论(0)
  • 2020-12-07 14:00

    I had an identical problem using rbenv. The solution was to take the rbenv specific lines from the bottom of my .bashrc file and put them at the top. The first line of my .bashrc file was returning aborting if the shell wasn't running in interactive mode.

    0 讨论(0)
  • 2020-12-07 14:00

    I tried a number of the suggestions. Had problems with setting the paths in the deploy.rb file for the RVM environment. My final solution was to include the following:

    In the config/deploy.rb file add:

    require "bundler/capistrano"
    

    Also in config/deploy.rb, or in my case config/production.rb as I was using the multistage option for Capistrano

    after "deploy", "rvm:trust_rvmrc"
    

    This step simply ensures that we stop getting the 'do you want to trust the .rvmrc file' and it calls a task in the deploy.rb file such as:

    namespace :rvm do
       task :trust_rvmrc do
          run "rvm rvmrc trust #{release_path}"
       end
    end
    

    After putting in these slight changes I was able to run cap production deploy which checked out the code; executed the asset pipeline deployment, linked up the release folder to current, executed bundle install and cleaned up.

    0 讨论(0)
  • 2020-12-07 14:04

    It was my understanding that the bundle command is not found because the PATH variable, defined in the user's ~/.bash_profile, isn't loaded by Capistrano.

    To get around this I have created a task :bundle_gems.

    task :bundle_gems do
        run "cd #{deploy_to}/current && export PATH=/usr/local/pgsql/bin:/opt/ruby-enterprise-X.X.X/bin:$PATH && bundle install vendor/gems"
    end
    

    Note that I also include the path to PostgreSQL binaries - installation of the pg gem was failing because they could not be found, even when bundle could be found.

    This seems like a messy approach, though. Presumably there is a more 'global' place to define paths to binaries that I don't know about.

    Update 23/12

    To add a directory to $PATH for all users: https://serverfault.com/questions/102932/adding-a-directory-to-path-in-centos

    However this still won't be loaded because it is a non-interactive non-login shell.

    One suggestion was to add the paths to /etc/bashrc: How do I set $PATH such that `ssh user@host command` works?

    However this also didn't work for me. I believe its because SSH doesn't load /etc/bashrc either.

    Another suggestion was to edit ~/.ssh/environment: http://www.ruby-forum.com/topic/79248. However this seems almost as messy as specifying the paths in deploy.rb.

    0 讨论(0)
提交回复
热议问题