无法使用capistrano部署rails应用程序,找不到bundle

时间:2017-12-08 05:53:42

标签: ruby-on-rails bundler puma capistrano3

我正在尝试使用capistrano部署我的rails应用程序但是它给了我“bundle stdout:/home/deploy/.rvm/scripts/set:第19行:exec:bundle:not found”错误。我在服务器上安装了bundler gem,但仍然无法找到捆绑包。

Capfile内容:

require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/bundler'
require 'capistrano/rvm'
require 'capistrano/rails/assets' # for asset handling add
require 'capistrano/rails/migrations' # for running migrations
require 'capistrano/puma'
require 'capistrano/rake'

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

Deploy.rb内容:

lock '3.10.0'

set :application, 'app_name'
set :repo_url, 'my-repo-url' # Edit this to match your repository
set :branch, :branch_name
set :deploy_to, '/home/deploy/app_name'
set :pty, true
set :linked_files, %w{config/database.yml config/application.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads}
set :keep_releases, 3
set :rvm_type, :user
set :rvm_ruby_version, 'ruby-2.3.1' # Edit this if you are using MRI Ruby

set :puma_rackup, -> { File.join(current_path, 'config.ru') }
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
set :puma_bind, "unix://#{shared_path}/tmp/sockets/puma.sock"    #accept array for multi-bind
set :puma_conf, "#{shared_path}/puma.rb"
set :puma_access_log, "#{shared_path}/log/puma_error.log"
set :puma_error_log, "#{shared_path}/log/puma_access.log"
set :puma_role, :app
set :puma_threads, [0, 16]
set :puma_workers, 0
set :puma_worker_timeout, nil
set :puma_init_active_record, true
set :puma_preload_app, false
set :puma_prune_bundler, true

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

  after  :finishing,    :compile_assets
  after  :finishing,    :cleanup
  after  :finishing,    :restart
end

Production.rb内容:

server 'My-IP', user: 'deploy', roles: %w{web app db}
set :puma_env, fetch(:rack_env, fetch(:rails_env, 'production'))

1 个答案:

答案 0 :(得分:1)

使用capistranorvm部署Rails应用时,您必须小心,capistrano将切换ruby版本,并且它可能与您看到的版本不同。

您可以ssh到远程服务器并自行检查

ssh deploy@My-IP
ruby -v        # It's probably not 2.3.1
which bundle
rvm use 2.3.1  # This is the actual version will be used by capistrano
which bundle

如果您无法在ruby-2.3.1中看到安装的软件包,可以通过

手动安装它
rvm use 2.3.1
gem install bundler

之后,capistrano部署应该按预期工作。