使用Capistrano

时间:2015-11-23 23:39:21

标签: ruby-on-rails prawn capistrano3

我刚刚将prawn和prawn表添加到我的Gemfile中并生成了一个pdf报告。一切都在本地工作正常,但当我尝试使用Capistrano部署到生产时,我收到以下错误:

bundle stdout: An error occurred while installing prawn (2.0.2), and Bundler cannot continue.
Make sure that `gem install prawn -v '2.0.2'` succeeds before bundling.
bundle stderr: Nothing written

我可以ssh到服务器,cd到当前目录并安装gem没有任何问题,但是当我再次运行部署时,我仍然得到相同的错误。

这是我的Gemfile:

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.3'
gem 'bcrypt', '3.1.7' #for password encryption
gem 'bootstrap-sass'
gem 'will_paginate',           '3.0.7'
gem 'bootstrap-will_paginate', '0.0.10'
gem 'bootstrap-datepicker-rails'
gem 'momentjs-rails'

# Use postgresql as the database for Active Record
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# JS runtimes
gem 'execjs'
gem 'therubyracer', :platforms => :ruby

gem 'carrierwave' #for file uploads

# gem 'prawn-rails' #for generating pdf docs
gem 'prawn' #for generating pdf docs
gem 'prawn-table'

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'

  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'rspec-rails', '~> 3.0' #testing framework
  gem 'factory_girl_rails' #creates objects during tests
  gem 'faker'
  gem 'capistrano-rails'
  gem 'capistrano-rbenv', '~> 2.0', require: false
  gem 'capistrano-rails-console'
  gem 'capistrano-passenger'
  gem 'capistrano-bundler', '~> 1.1.2'
  # gem 'capistrano-rvm'
end

group :test do
  gem 'minitest-reporters', '1.0.5'
  gem 'mini_backtrace',     '0.1.3'
  gem 'guard-minitest',     '2.3.1'

  gem 'capybara' #used for testing javascript with rsepc
  gem 'selenium-webdriver'
  gem 'capybara-webkit' #capybara driver that is javascript enabled
  gem 'database_cleaner'
  #gem 'poltergeist'
  #gem 'guard-rspec'
  #gem 'launchy'
end

以下是控制台的错误:

DEBUG [ae525d2a]    An error occurred while installing prawn (2.0.2), and Bundler cannot continue.
DEBUG [ae525d2a]    Make sure that `gem install prawn -v '2.0.2'` succeeds before bundling.
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy@103.6.212.246: bundle exit status: 5
bundle stdout: An error occurred while installing prawn (2.0.2), and Bundler cannot continue.
Make sure that `gem install prawn -v '2.0.2'` succeeds before bundling.
bundle stderr: Nothing written

SSHKit::Command::Failed: bundle exit status: 5
bundle stdout: An error occurred while installing prawn (2.0.2), and Bundler cannot continue.
Make sure that `gem install prawn -v '2.0.2'` succeeds before bundling.
bundle stderr: Nothing written

Tasks: TOP => deploy:updated => bundler:install
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deploy@103.6.212.246: bundle exit status: 5
bundle stdout: An error occurred while installing prawn (2.0.2), and Bundler cannot continue.
Make sure that `gem install prawn -v '2.0.2'` succeeds before bundling.
bundle stderr: Nothing written

更新:

在部署文件中使用set :bundle_flags, '--deployment --verbose'我能够看到问题是由于服务器上的ruby版本不是至少2.0。经过进一步调查,生产服务器正在使用rvm(我被告知它是rbenv),所以通过使用capistrano-rvm gem,我能够让部署工作。我现在的问题是我不能让乘客使用更新的红宝石版!!!!

1 个答案:

答案 0 :(得分:1)

当你ssh到服务器时,你使用login, interactive shell。 但是,默认情况下,Capistrano使用non-login, non-interactive shellhttp://capistranorb.com/documentation/faq/why-does-something-work-in-my-ssh-session-but-not-in-capistrano/

所以,错误可能是因为它遗漏了一些env vars。

如果我猜,

你使用rvm吗?如果是这样,您可以在deploy.rb中添加以下行

set :default_env, { rvm_bin_path: '~/.rvm/bin' }

你能试试吗?