2017-06-13 84 views
0

引入nokogiri这是我的软件版本:如何部署Rails应用程序使用Capistrano的

  • 红宝石:2.2.1
  • 的Rails:4.2.0
  • Capistrano的:3.8.1
  • 彪马: 3.9.1

这是我Capfile:

require "capistrano/setup" 
require "capistrano/deploy" 
require "capistrano/scm/git" 
install_plugin Capistrano::SCM::Git 
require "capistrano/rvm" 
require "capistrano/bundler" 
require "capistrano/rails/assets" 
require "capistrano/rails/migrations" 
require "capistrano/puma" 
install_plugin Capistrano::Puma 

配置/ deploy.rb:

server '192.168.0.1', port: 22, roles: [:web, :app, :db], primary: true 

set :application, "testapp" 
set :repo_url, "[email protected]:username/testapp.git" 
set :user,   'deploy' 
set :puma_threads, [4, 16] 
set :puma_workers, 0 

set :pty,    true 
set :use_sudo,  false 
set :stage,   :production 
set :deploy_via,  :remote_cache 
set :deploy_to,  "/home/#{fetch(:user)}/apps/#{fetch(:application)}" 
set :puma_bind,  "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock" 
set :puma_state,  "#{shared_path}/tmp/pids/puma.state" 
set :puma_pid,  "#{shared_path}/tmp/pids/puma.pid" 
set :puma_access_log, "#{release_path}/log/puma.error.log" 
set :puma_error_log, "#{release_path}/log/puma.access.log" 
set :ssh_options,  { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) } 
set :puma_preload_app, true 
set :puma_worker_timeout, nil 
set :puma_init_active_record, true # Change to false when not using ActiveRecord 

namespace :puma do 
    desc 'Create Directories for Puma Pids and Socket' 
    task :make_dirs do 
    on roles(:app) do 
     execute "mkdir #{shared_path}/tmp/sockets -p" 
     execute "mkdir #{shared_path}/tmp/pids -p" 
    end 
    end 

    before :start, :make_dirs 
end 

namespace :deploy do 
    desc "Make sure local git is in sync with remote." 
    task :check_revision do 
    on roles(:app) do 
     unless `git rev-parse HEAD` == `git rev-parse origin/master` 
    puts "WARNING: HEAD is not the same as origin/master" 
    puts "Run `git push` to sync changes." 
    exit 
     end 
    end 
    end 

    desc 'Initial Deploy' 
    task :initial do 
    on roles(:app) do 
     before 'deploy:restart', 'puma:start' 
     invoke 'deploy' 
    end 
    end 

    desc 'Restart application' 
    task :restart do 
    on roles(:app), in: :sequence, wait: 5 do 
     invoke 'puma:restart' 
    end 
    end 

当我跑cap production deploy:initial,我得到了这些错误:

Results logged to 
/home/deploy/apps/testapp/shared/bundle/ruby/2.2.0/extensions/x86_64-linux/2.2.0/nokogiri-1.8.0/gem_make.out 

An error occurred while installing nokogiri (1.8.0), and Bundler cannot 
continue. 
Make sure that `gem install nokogiri -v '1.8.0'` succeeds before bundling. 

In Gemfile: 
    rails was resolved to 4.2.0, which depends on 
    actionmailer was resolved to 4.2.0, which depends on 
     actionpack was resolved to 4.2.0, which depends on 
    actionview was resolved to 4.2.0, which depends on 
     rails-dom-testing was resolved to 1.0.8, which depends on 
     nokogiri 
bundle stderr: Nothing written 


** DEPLOY FAILED 
** Refer to log/capistrano.log for details. Here are the last 20 lines: 




extconf failed, exit code 1 



Gem files will remain installed in 

/home/deploy/apps/testapp/shared/bundle/ruby/2.2.0/gems/nokogiri-1.8.0 for 

inspection. 

Results logged to 

/home/deploy/apps/testapp/shared/bundle/ruby/2.2.0/extensions/x86_64-linux/2.2.0/nokogiri-1.8.0/gem_make.out 



An error occurred while installing nokogiri (1.8.0), and Bundler cannot 

continue. 

Make sure that `gem install nokogiri -v '1.8.0'` succeeds before bundling. 



In Gemfile: 

    rails was resolved to 4.2.0, which depends on 

    actionmailer was resolved to 4.2.0, which depends on 

DEBUG [419bf769]    actionpack was resolved to 4.2.0, which depends on 

    actionview was resolved to 4.2.0, which depends on 

     rails-dom-testing was resolved to 1.0.8, which depends on 

     nokogiri 

我安装我的远程服务器上的红宝石2.2.1。为什么在这里使用2.2.0

我也删除了Gemfile.lock文件并再次运行bundle。该文件是这样的:

... 

loofah (2.0.3) 
    nokogiri (>= 1.5.9) 
mail (2.6.6) 
    mime-types (>= 1.16, < 4) 
mime-types (3.1) 
    mime-types-data (~> 3.2015) 
mime-types-data (3.2016.0521) 
mini_portile2 (2.2.0) 
minitest (5.10.2) 
multi_json (1.12.1) 
net-scp (1.2.1) 
    net-ssh (>= 2.6.5) 
net-ssh (4.1.0) 
nokogiri (1.8.0) 
    mini_portile2 (~> 2.2.0) 
puma (3.9.1) 
rack (1.6.8) 
rack-test (0.6.3) 
    rack (>= 1.0) 
rails (4.2.0) 
    actionmailer (= 4.2.0) 
    actionpack (= 4.2.0) 
    actionview (= 4.2.0) 
    activejob (= 4.2.0) 
    activemodel (= 4.2.0) 
    activerecord (= 4.2.0) 
    activesupport (= 4.2.0) 
    bundler (>= 1.3.0, < 2.0) 
    railties (= 4.2.0) 
    sprockets-rails 
rails-deprecated_sanitizer (1.0.3) 
    activesupport (>= 4.2.0.alpha) 
rails-dom-testing (1.0.8) 
    activesupport (>= 4.2.0.beta, < 5.0) 
    nokogiri (~> 1.6) 
    rails-deprecated_sanitizer (>= 1.0.1) 

... 


PLATFORMS 
    ruby 

DEPENDENCIES 
    byebug 
    capistrano 
    capistrano-bundler 
    capistrano-rails 
    capistrano-rvm 
    capistrano3-puma 
    coffee-rails (~> 4.1.0) 
    jbuilder (~> 2.0) 
    jquery-rails 
    puma 
    rails (= 4.2.0) 
    sass-rails (~> 5.0) 
    sdoc (~> 0.4.0) 
    spring 
    sqlite3 
    turbolinks 
    uglifier (>= 1.3.0) 
    web-console (~> 2.0) 
+0

什么是您的Gemfile中的Ruby版本? – Thanh

+0

我现在知道原因。远程服务器没有安装必要的库:'sudo apt-get install zlib1g-dev libssl-dev libreadline-dev libyaml-dev libxml2-dev libxslt-dev' –

+1

使用该信息创建答案,并对其进行适当格式化。 SO会让你在超时时间后选择答案。 –

回答

1

经过一次又一次的尝试之后,我终于找到了原因。

这只是为什么不能安装nokogiri

在目标服务器上,应该先安装这些必要的软件包:

sudo apt-get install zlib1g-dev libssl-dev libreadline-dev libyaml-dev libxml2-dev libxslt-dev 

nokogiri宝石依赖这些库:libxml2-devlibxslt-dev(也许)。

相关问题