【问题标题】:Unable to deploy rails application using capistrano, bundle not found无法使用 capistrano 部署 Rails 应用程序,找不到捆绑包
【发布时间】:2017-12-08 05:53:42
【问题描述】:

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

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'))

【问题讨论】:

    标签: ruby-on-rails bundler puma capistrano3


    【解决方案1】:

    在使用 capistranorvm 部署 Rails 应用程序时,您必须小心 capistrano 会切换 ruby​​ 版本,它可能与您看到的 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 that will be used by capistrano
    which bundle
    

    如果您看不到 ruby-2.3.1 中安装的包,您可以手动安装它

    rvm use 2.3.1
    gem install bundler
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-30
      • 1970-01-01
      • 1970-01-01
      • 2011-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-30
      相关资源
      最近更新 更多