Capistrano部署Rails应用程序失败并说缺少宝石

时间:2016-11-05 19:30:43

标签: ruby-on-rails ruby capistrano digital-ocean

我正在使用已经成功部署过几次的数字海洋服务器。突然间,每当我运行cap production deploy它失败并告诉我有缺少的宝石,其中一些在开发组中,因此它们甚至不应该在生产中。这是我的控制台输出与缺少的宝石。还有一些似乎与资产预编译有关的失败进程。

DEBUG [c182dc11] Running [ -L /home/deploy/apps/team_hadley/releases/20161105191648/public/assets ] on 162.243.135.130
DEBUG [c182dc11] Command: [ -L /home/deploy/apps/team_hadley/releases/20161105191648/public/assets ]
DEBUG [c182dc11] Finished in 0.062 seconds with exit status 1 (failed).
DEBUG [5bd74104] Running [ -d /home/deploy/apps/team_hadley/releases/20161105191648/public/assets ] on 162.243.135.130
DEBUG [5bd74104] Command: [ -d /home/deploy/apps/team_hadley/releases/20161105191648/public/assets ]
DEBUG [5bd74104] Finished in 0.064 seconds with exit status 1 (failed).
INFO [92c16c38] Running /usr/bin/env ln -s /home/deploy/apps/team_hadley/shared/public/assets /home/deploy/apps/team_hadley/releases/20161105191648/public/assets on 162.243.135.130
DEBUG [92c16c38] Command: /usr/bin/env ln -s /home/deploy/apps/team_hadley/shared/public/assets /home/deploy/apps/team_hadley/releases/20161105191648/public/assets
INFO [92c16c38] Finished in 0.061 seconds with exit status 0 (successful).
DEBUG [7012f1eb] Running if test ! -d /home/deploy/apps/team_hadley/releases/20161105191648; then echo "Directory does not exist '/home/deploy/apps/team_hadley/releases/20161105191648'" 1>&2; false; fi on 162.243.135.130
DEBUG [7012f1eb] Command: if test ! -d /home/deploy/apps/team_hadley/releases/20161105191648; then echo "Directory does not exist '/home/deploy/apps/team_hadley/releases/20161105191648'" 1>&2; false; fi
DEBUG [7012f1eb] Finished in 0.065 seconds with exit status 0 (successful).
DEBUG [d02096e8] Running ~/.rvm/bin/rvm default do bundle check --path /home/deploy/apps/team_hadley/shared/bundle on 162.243.135.130


DEBUG [d02096e8] Command: cd /home/deploy/apps/team_hadley/releases/20161105191648 && ~/.rvm/bin/rvm default do bundle check --path /home/deploy/apps/team_hadley/shared/bundle
 DEBUG [d02096e8]       ESC[32mRVM used your Gemfile for selecting Ruby, it is all fine - Heroku does that too,
 DEBUG [d02096e8]
 DEBUG [d02096e8]       you can ignore these warnings with 'rvm rvmrc warning ignore /home/deploy/apps/team_hadley/releases/20161105191648/Gemfile'.
 DEBUG [d02096e8]
 DEBUG [d02096e8]       To ignore the warning for all files run 'rvm rvmrc warning ignore allGemfiles'.
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31mThe following gems are missingESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * nokogiri (1.6.8.1)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * globalid (0.3.7)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * net-ssh (3.2.0)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * net-scp (1.2.1)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * sshkit (1.11.3)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * airbrussh (1.1.1)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * debug_inspector (0.0.2)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * binding_of_caller (0.7.2)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * capistrano-harrow (0.5.3)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * capistrano (3.6.1)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * capistrano-bundler (1.2.0)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * capistrano-rails (1.1.8)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * capistrano-rvm (0.1.2)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * capistrano-sidekiq (0.5.4)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * capistrano3-puma (1.2.1)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * coderay (1.1.1)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * database_cleaner (1.5.3)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * responders (2.3.0)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * diff-lcs (1.2.5)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * docile (1.1.5)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * factory_girl (4.7.0)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * factory_girl_rails (4.7.0)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * jbuilder (2.6.0)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * jquery-rails (4.2.1)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * turbolinks (5.0.1)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * materialize-sass (0.97.7)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * method_source (0.8.2)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * slop (3.6.0)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * pry (0.10.4)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * sprockets (3.7.0)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * sprockets-rails (3.2.0)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * react-rails (1.9.0)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * rspec-support (3.5.0)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * rspec-core (3.5.4)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * rspec-expectations (3.5.0)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * rspec-mocks (3.5.0)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * rspec-rails (3.5.2)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * sass-rails (5.0.6)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * sdoc (0.4.2)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * shoulda-matchers (3.1.1)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * simplecov-html (0.10.0)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * simplecov (0.11.2)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * spring (2.0.0)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * sprockets-es6 (0.9.2)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * uglifier (3.0.2)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[31m * web-console (2.3.0)ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8]       ESC[33mInstall missing gems with `bundle install`ESC[0m
 DEBUG [d02096e8]
 DEBUG [d02096e8] Finished in 1.037 seconds with exit status 1 (failed).
  INFO [62fad7fd] Running ~/.rvm/bin/rvm default do bundle install --path /home/deploy/apps/team_hadley/shared/bundle --without development test --deployment --quiet on 162.243.135.130
 DEBUG [62fad7fd] Command: cd /home/deploy/apps/team_hadley/releases/20161105191648 && ~/.rvm/bin/rvm default do bundle install --path /home/deploy/apps/team_hadley/shared/bundle --without development test --deployment --quiet
 DEBUG [62fad7fd]       ESC[32mRVM used your Gemfile for selecting Ruby, it is all fine - Heroku does that too,
 DEBUG [62fad7fd]
 DEBUG [62fad7fd]       you can ignore these warnings with 'rvm rvmrc warning ignore /home/deploy/apps/team_hadley/releases/20161105191648/Gemfile'.
 DEBUG [62fad7fd]
 DEBUG [62fad7fd]       To ignore the warning for all files run 'rvm rvmrc warning ignore allGemfiles'.
 DEBUG [62fad7fd]
 DEBUG [62fad7fd]       ESC[0m
 DEBUG [62fad7fd]
 DEBUG [62fad7fd]       bash: line 1:  7571 Killed                  ~/.rvm/bin/rvm default do bundle install --path /home/deploy/apps/team_hadley/shared/bundle --without development test --deployment --quiet

这是我的Capfile:

# Load DSL and Setup Up Stages
require 'capistrano/setup'
require 'capistrano/deploy'

require 'capistrano/rails'
require 'capistrano/bundler'
require 'capistrano/rvm'
require 'capistrano/puma'

# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

我的deploy.rb文件:

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

set :repo_url,        'git@github.com:mghadley/team_hadley.git'
set :application,     'team_hadley'
set :user,            'deploy'
set :puma_threads,    [4, 16]
set :puma_workers,    0

# Don't change these unless you know what you're doing
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

## Defaults:
# set :scm,           :git
# set :branch,        :master
# set :format,        :pretty
# set :log_level,     :debug
# set :keep_releases, 5

## Linked Files & Directories (Default None):
# set :linked_files, %w{config/database.yml}
# set :linked_dirs,  %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}

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

  before :starting,     :check_revision
  after  :finishing,    :compile_assets
  after  :finishing,    :cleanup
  after  :finishing,    :restart
end

# ps aux | grep puma    # Get puma pid
# kill -s SIGUSR2 pid   # Restart puma
# kill -s SIGTERM pid   # Stop puma

最后,我的Gemfile:

source 'https://rubygems.org'
ruby '2.2.3'

gem 'rails', '4.2.5'
gem 'pg', '~> 0.15'
gem 'sass-rails', '~> 5.0' 
gem 'materialize-sass', '~> 0.97.6'
gem 'uglifier', '>= 1.3.0'

gem 'devise', '~> 4.1.1'

gem 'jquery-rails'
gem 'jquery-turbolinks'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc

gem "sprockets"
gem "sprockets-es6"
gem "react-rails"
gem "cloudinary"
gem "jquery-slick-rails"
gem "sidekiq"

group :development, :test do
  gem 'pry', '~> 0.10.3'
  gem 'rspec-rails'
  gem 'shoulda-matchers', '~> 3.1.1'
  gem 'database_cleaner', '~> 1.5.3'
  gem 'simplecov', '~> 0.11.2'
  gem 'factory_girl_rails', '~> 4.7.0'
end

group :development do
  gem 'web-console', '~> 2.0'

  gem 'spring'

  gem 'capistrano-sidekiq', require: false
  gem 'capistrano',         require: false
  gem 'capistrano-rvm',     require: false
  gem 'capistrano-rails',   require: false
  gem 'capistrano-bundler', require: false
  gem 'capistrano3-puma',   require: false
end

group :produection do
    gem 'rails_12factor'
    gem 'puma'
end

有没有人碰巧知道出了什么问题?

2 个答案:

答案 0 :(得分:2)

您看到来自bundle check的输出缺少宝石。这是预期的,因为capistrano-bundler在运行bundle check之前首先运行bundle install。您可以忽略check输出。

真正的问题是你的日志的最后一行,它说:

bash: line 1:  7571 Killed                  ~/.rvm/bin/rvm default do bundle install --path /home/deploy/apps/team_hadley/shared/bundle --without development test --deployment --quiet

如您所见,bundle install由于被操作系统杀死而失败。这几乎可以肯定是因为你已经耗尽了RAM并且OS被迫停止了这个过程。

作为解决方案,您可以将交换添加到VM或升级到具有更多RAM的VM。

要确保,请检查/var/log/syslog中的日志并查找与内存相关的错误。

答案 1 :(得分:0)

对于任何人,都有同样的问题,但不是因为内存不足:在我的情况下,我没有安装yarn并在assess:precompile执行过程中遇到“ Missing gems”错误。如果您在项目中使用yarn,请尝试:

  1. curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt键添加-
  2. 回显“ deb https://dl.yarnpkg.com/debian/稳定的主信号” | sudo tee /etc/apt/sources.list.d/yarn.list
  3. sudo apt更新
  4. sudo apt install yarn

然后尝试再次部署