如何使用Capistrano与Nokogiri部署Rails应用程序

时间:2017-06-13 04:36:20

标签: ruby-on-rails ruby capistrano nokogiri

这些是我的软件版本:

  • Ruby:2.2.1
  • Rails:4.2.0
  • Capistrano:3.8.1
  • Puma: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, "git@github.com: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

我在远程服务器上安装了ruby 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)

1 个答案:

答案 0 :(得分:1)

有时一次又一次地尝试,我终于找到了原因。

这只是为什么无法安装nokogiri

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

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

nokogiri gem取决于这些库:libxml2-devlibxslt-dev(可能)。