2013-10-26 59 views
14

我在使用Capistrano v3部署我的應用程序時遇到問題。當我運行「$帽生產部署」我看到一個錯誤......Capistrano v3無法找到Bundler

INFO [825ad68d] Running /usr/bin/env bundle --gemfile /home/username/www/myapp/releases/20131026181031/Gemfile --path /home/username/www/myapp/shared/bundle --deployment --quiet --binstubs /home/username/www/myapp/shared/bin --without development test on myhostname.com 
DEBUG [825ad68d] Command: cd /home/username/www/myapp/releases/20131026181031 && (RAILS_ENV=production /usr/bin/env bundle --gemfile /home/username/www/myapp/releases/20131026181031/Gemfile --path /home/username/www/myapp/shared/bundle --deployment --quiet --binstubs /home/username/www/myapp/shared/bin --without development test) 
DEBUG [825ad68d] /usr/bin/env: 
DEBUG [825ad68d] bundle 
DEBUG [825ad68d] : No such file or directory 

但是,當我在我的服務器我不上運行的最後一個命令

cd /home/username/www/myapp/releases/20131026181031 && (RAILS_ENV=production /usr/bin/env bundle --gemfile /home/username/www/myapp/releases/20131026181031/Gemfile --path /home/username/www/myapp/shared/bundle --deployment --quiet --binstubs /home/username/www/myapp/shared/bin --without development test) 

...通過ssh沒有看到任何錯誤。

這裏是我的服務器環境:

  • 的Ubuntu 13.04
  • RVM 1.23.5
  • RubyGems的25年1月8日
  • 捆紮機1.3.5
  • 紅寶石1.9.3p448
  • Capistrano的(3.0.0)
  • capistrano-bundler(1.0.0)
  • Capistrano的護欄(1.0.0)

這裏是我的一塊Gemfile中的,其中包括Capistrano酒店的寶石

... 
group :development do 
    ... 
    # Deploy with Capistrano 
    gem 'capistrano', '~> 3.0.0' 
    gem 'capistrano-rails' 
    gem 'capistrano-bundler' 
end 
... 

請參考下面Capistrano酒店的配置:

Capfile

require 'capistrano/setup' 
require 'capistrano/deploy' 
require 'capistrano/bundler' 
require 'capistrano/rails/assets' 
require 'capistrano/rails/migrations' 

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

配置/ deploy.rb

set :application, 'myapp' 
set :repo_url, "/home/username/repository/#{fetch(:application)}.git" 
set :deploy_to, "/home/usename/www/#{fetch(:application)}" 
set :scm, :git 
set :branch, "master" 
set :format, :pretty 
set :use_sudo, false 

set :linked_files, %w{config/database.yml} 
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} 

set :keep_releases, 5 

SSHKit.config.command_map[:rake] = "bundle exec rake" 
SSHKit.config.command_map[:rails] = "bundle exec rails" 

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 

    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 

    after :finishing, 'deploy:cleanup' 
end 

配置/部署/ production.rb

set :stage, :production 

set :bundle_gemfile, -> { release_path.join('Gemfile') } 
set :bundle_dir, -> { shared_path.join('bundle') } 
set :bundle_flags, '--deployment --quiet' 
set :bundle_without, %w{development test}.join(' ') 
set :bundle_binstubs, -> { shared_path.join('bin') } 
set :bundle_roles, :all 

role :app, %w{myhostname.com} 
role :web, %w{myhostname.com} 
role :db, %w{myhostname.com} 

server 'myhostname.com', user: 'username', roles: %w{web app}, my_property: :my_value 

fetch(:default_env).merge!(rails_env: :production) 

請幫助我。

解決

我通過以下步驟解決我的問題:

添加Capistrano的,RVM爲的Gemfile

... 
group :development do 
    ... 
    gem 'capistrano', '~> 3.0.0' 
    gem 'capistrano-rails' 
    gem 'capistrano-bundler' 
    gem 'capistrano-rvm' 
end 
... 

添加此行到Capfile

require 'capistrano/rvm' 

將這些行添加到deploy.rb文件中。

set :rvm_ruby_version, '1.9.3-p448' 
set :default_env, { rvm_bin_path: '~/.rvm/bin' } 
SSHKit.config.command_map[:rake] = "#{fetch(:default_env)[:rvm_bin_path]}/rvm ruby-#{fetch(:rvm_ruby_version)} do bundle exec rake" 
+1

可能重複的不從capistrano](http://stackoverflow.com/questions/19363077/bundle-install-doesnt-work-from-capistrano) –

+0

在Gemfile中添加gem'capistrano-rvm'後,運行bundle,然後添加require'capistrano/'Capfile'中的rvm' –

回答

7

看來你不得不添加capistrano-rvm 。它會照顧你的ruby​​bundler路徑。

bundle install doesn't work from capistrano

+0

我加了capistrano-rvm,它解決了問題,但出現了另一個問題。我認爲這個和前一個是類似的(見下面): 'DEBUG [3686e995]命令:cd/home/username/www/myapp/releases/20131027130646 &&(RVM_BIN_PATH =〜/ .rvm/bin RAILS_ENV =〜/ .rvm/bin/rvm ruby​​-1.9.3-p448做rake資產:預編譯) DEBUG [3686e995] \t /home/username/.rvm/gems/[email protected]/gems/bundler-1.3 0.5/LIB /捆綁/ spec_set.rb:92:在Materialise的」 DEBUG [3686e995]塊: DEBUG [3686e995]中找不到任何來源 DEBUG [3686e995] I18N-0.6.1( DEBUG [3686e995] \t Bundler :: GemNotFound' – ekondr

+0

@ekondr正如你所看到的,你沒有指定'''RAILS_ENV'''嘗試添加'''set:rails_env,「production」'''而不是''''' fetch(:default_env).merge!(rails_env::production)'' ' – freemanoid

+0

我已經添加了'set:rails_env,「production」'而不是'fetch(:default_env).merge!(rails_env :: production)',但沒有任何改變。 – ekondr

0

......通過我的服務器上的SSH我沒有看到任何錯誤。

您看到的問題可能是由於缺少rbenv,chruby或rvm。這是一個非常常見的一種,它的記錄在這裏如何解決,驗證和/或解決(你的情況下,兩者的工作原理)這裏:

+1

我沒有看到有關如何解決該鏈接的任何說明。雖然這個問題很好的解釋。 – Altonymous

0

如果使用系統RVM(PATH =在/ usr /本地/ RVM /斌/ RVM),設置Capistrano的打捆如下

set :rvm_type, :system 
set :rvm_ruby_version, 'ruby-<version>@<gemset>' 
的[包安裝
相關問題