问题描述
我正在尝试将 ruby on rails web 应用程序部署到临时服务器,但继续收到错误:bundle stderr: /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7。 0/rubygems.rb:275:in `find_spec_for_exe': 找不到你的 /home/deploy/apps/MYAPP/releases/20201230174246/Gemfile.lock 需要的 'bundler' (1.16.1)。 (Gem::GemNotFoundException)
我试图直接在服务器上安装 bundler,即使这样做了,它仍然会失败并出现相同的错误。完整的错误日志和下面的 deploy.rb。
完整日志:
% cap staging deploy
[Deprecation Notice] Future versions of Capistrano will not load the Git SCM
plugin by default. To silence this deprecation warning,add the following to
your Capfile after `require "capistrano/deploy"`:
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
deploy@00.000.000.000's password:
rvm 1.29.10 (latest) by Michal Papis,Piotr Kuczynski,Wayne E. Seguin [https://rvm.io]
ruby-2.7.0
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux]
00:00 git:wrapper
01 mkdir -p /home/deploy/tmp
✔ 01 deploy@00.000.000.000 0.313s
Uploading /home/deploy/tmp/git-ssh-Myapp-staging-marcuselmer.sh 100.0%
02 chmod 700 /home/deploy/tmp/git-ssh-Myapp-staging-marcuselmer.sh
✔ 02 deploy@00.000.000.000 0.276s
00:01 git:check
01 git ls-remote git@bitbucket.org:.../myApp.git HEAD
01 123abad2c0a3f9fa670259253608e11086661c6b HEAD
✔ 01 deploy@00.000.000.000 1.653s
00:02 deploy:check:directories
01 mkdir -p /home/deploy/apps/MYAPP/shared /home/deploy/apps/MYAPP/releases
✔ 01 deploy@00.000.000.000 0.278s
00:03 deploy:check:linked_dirs
01 mkdir -p /home/deploy/apps/MYAPP/shared/log /home/deploy/apps/MYAPP/shared/tmp/pids /home/deploy/apps/MYAPP/shared/tmp/cache /home/deploy/app…
✔ 01 deploy@00.000.000.000 0.319s
00:03 deploy:check:make_linked_dirs
01 mkdir -p /home/deploy/apps/MYAPP/shared/config
✔ 01 deploy@00.000.000.000 0.274s
00:04 git:clone
The repository mirror is at /home/deploy/apps/MYAPP/repo
00:05 git:update
01 git remote set-url origin git@bitbucket.org:.../myApp.git
✔ 01 deploy@00.000.000.000 0.314s
02 git remote update --prune
02 Fetching origin
02 From bitbucket.org:.../myApp
02 01e45c6b..123abad2 master -> master
✔ 02 deploy@00.000.000.000 1.901s
00:07 git:create_release
01 mkdir -p /home/deploy/apps/MYAPP/releases/20201230174246
✔ 01 deploy@00.000.000.000 0.312s
02 git archive master | /usr/bin/env tar -x -f - -C /home/deploy/apps/MYAPP/releases/20201230174246
✔ 02 deploy@00.000.000.000 0.924s
00:09 deploy:set_current_revision
01 echo "123abad2c0a3f9fa670259253608e11086661c6b" >> REVISION
✔ 01 deploy@00.000.000.000 0.269s
00:09 deploy:symlink:linked_files
01 mkdir -p /home/deploy/apps/MYAPP/releases/20201230174246/config
✔ 01 deploy@00.000.000.000 0.317s
02 ln -s /home/deploy/apps/MYAPP/shared/config/secrets.yml /home/deploy/apps/MYAPP/releases/20201230174246/config/secrets.yml
✔ 02 deploy@00.000.000.000 0.277s
00:11 deploy:symlink:linked_dirs
01 mkdir -p /home/deploy/apps/MYAPP/releases/20201230174246 /home/deploy/apps/MYAPP/releases/20201230174246/tmp /home/deploy/apps/MYAPP/releases…
✔ 01 deploy@00.000.000.000 0.307s
02 rm -rf /home/deploy/apps/MYAPP/releases/20201230174246/log
✔ 02 deploy@00.000.000.000 0.269s
03 ln -s /home/deploy/apps/MYAPP/shared/log /home/deploy/apps/MYAPP/releases/20201230174246/log
✔ 03 deploy@00.000.000.000 0.335s
04 ln -s /home/deploy/apps/MYAPP/shared/tmp/pids /home/deploy/apps/MYAPP/releases/20201230174246/tmp/pids
✔ 04 deploy@00.000.000.000 0.272s
05 rm -rf /home/deploy/apps/MYAPP/releases/20201230174246/tmp/cache
✔ 05 deploy@00.000.000.000 0.318s
06 ln -s /home/deploy/apps/MYAPP/shared/tmp/cache /home/deploy/apps/MYAPP/releases/20201230174246/tmp/cache
✔ 06 deploy@00.000.000.000 0.283s
07 ln -s /home/deploy/apps/MYAPP/shared/tmp/sockets /home/deploy/apps/MYAPP/releases/20201230174246/tmp/sockets
✔ 07 deploy@00.000.000.000 0.308s
08 ln -s /home/deploy/apps/MYAPP/shared/vendor/bundle /home/deploy/apps/MYAPP/releases/20201230174246/vendor/bundle
✔ 08 deploy@00.000.000.000 0.277s
09 ln -s /home/deploy/apps/MYAPP/shared/public/system /home/deploy/apps/MYAPP/releases/20201230174246/public/system
✔ 09 deploy@00.000.000.000 0.314s
10 ln -s /home/deploy/apps/MYAPP/shared/public/assets /home/deploy/apps/MYAPP/releases/20201230174246/public/assets
✔ 10 deploy@00.000.000.000 0.268s
00:19 bundler:install
01 ~/.rvm/bin/rvm default do bundle install --path /home/deploy/apps/MYAPP/shared/bundle --without development test --deployment --quiet
01 /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:275:in `find_spec_for_exe': Could not find 'bundler' (1.16.1) required by y…
01 To update to the latest version installed on your system,run `bundle update --bundler`.
01 To install the missing version,run `gem install bundler:1.16.1`
01 from /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:294:in `activate_bin_path'
01 from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/bundle:30:in `<main>'
01 from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `eval'
01 from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `<main>'
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy@00.000.000.000: bundle exit status: 1
bundle stdout: Nothing written
bundle stderr: /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:275:in `find_spec_for_exe': Could not find 'bundler' (1.16.1) required by your /home/deploy/apps/MYAPP/releases/20201230174246/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system,run `bundle update --bundler`.
To install the missing version,run `gem install bundler:1.16.1`
from /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:294:in `activate_bin_path'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/bundle:30:in `<main>'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `eval'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `<main>'
Caused by:
SSHKit::Command::Failed: bundle exit status: 1
bundle stdout: Nothing written
bundle stderr: /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:275:in `find_spec_for_exe': Could not find 'bundler' (1.16.1) required by your /home/deploy/apps/MYAPP/releases/20201230174246/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system,run `gem install bundler:1.16.1`
from /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:294:in `activate_bin_path'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/bundle:30:in `<main>'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `eval'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `<main>'
Tasks: TOP => deploy:updated => bundler:install
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deploy@00.000.000.000: bundle exit status: 1
bundle stdout: Nothing written
bundle stderr: /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:275:in `find_spec_for_exe': Could not find 'bundler' (1.16.1) required by your /home/deploy/apps/MYAPP/releases/20201230174246/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system,run `gem install bundler:1.16.1`
from /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:294:in `activate_bin_path'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/bundle:30:in `<main>'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `eval'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `<main>'
** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:
DEBUG [9486807a] Finished in 0.308 seconds with exit status 0 (successful).
DEBUG [5d323bc9] Running ~/.rvm/bin/rvm default do bundle check --path /home/deploy/apps/MYAPP/shared/bundle as deploy@00.000.000.000
DEBUG [5d323bc9] Command: cd /home/deploy/apps/MYAPP/releases/20201230174246 && ~/.rvm/bin/rvm default do bundle check --path /home/deploy/apps/MYAPP/shared/bundle
DEBUG [5d323bc9] /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:275:in `find_spec_for_exe': Could not find 'bundler' (1.16.1) required by your /home/deploy/apps/MYAPP/releases/20201230174246/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system,run `bundle update --bundler`.
To install the missing version,run `gem install bundler:1.16.1`
from /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:294:in `activate_bin_path'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/bundle:30:in `<main>'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `eval'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `<main>'
DEBUG [5d323bc9] Finished in 0.648 seconds with exit status 1 (failed).
INFO [38f3d295] Running ~/.rvm/bin/rvm default do bundle install --path /home/deploy/apps/MYAPP/shared/bundle --without development test --deployment --quiet as deploy@00.000.000.000
DEBUG [38f3d295] Command: cd /home/deploy/apps/MYAPP/releases/20201230174246 && ~/.rvm/bin/rvm default do bundle install --path /home/deploy/apps/MYAPP/shared/bundle --without development test --deployment --quiet
DEBUG [38f3d295] /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:275:in `find_spec_for_exe': Could not find 'bundler' (1.16.1) required by your /home/deploy/apps/MYAPP/releases/20201230174246/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system,run `gem install bundler:1.16.1`
from /home/deploy/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems.rb:294:in `activate_bin_path'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/bundle:30:in `<main>'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `eval'
from /home/deploy/.rvm/rubies/ruby-2.7.0/bin/ruby_executable_hooks:24:in `<main>'
部署.rb
# config valid only for current version of Capistrano
lock "3.10.1"
set :application,"Myapp"
set :repo_url,'git@bitbucket.org:…/myApp.git'
set :deploy_to,'/home/deploy/apps/myApp
set :linked_files,%w{config/secrets.yml}
set :linked_dirs,%w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
set :tmp_dir,"/home/deploy/tmp"
set :branch,ENV['BRANCH'] if ENV['BRANCH']
set :user,"deploy"
# Default branch is :master
# ask :branch,`git rev-parse --abbrev-ref HEAD`.chomp
# Default deploy_to directory is /var/www/my_app_name
# set :deploy_to,"/var/www/my_app_name"
# Default value for :format is :airbrussh.
# set :format,:airbrussh
# You can configure the Airbrussh format using :format_options.
# These are the defaults.
# set :format_options,command_output: true,log_file: "log/capistrano.log",color: :auto,truncate: :auto
# Default value for :pty is false
# set :pty,true
# Default value for :linked_files is []
# append :linked_files,"config/database.yml","config/secrets.yml"
# Default value for linked_dirs is []
# append :linked_dirs,"log","tmp/pids","tmp/cache","tmp/sockets","public/system"
# Default value for default_env is {}
# set :default_env,{ path: "/opt/ruby/bin:$PATH" }
# Default value for local_user is ENV['USER']
# set :local_user,-> { `git config user.name`.chomp }
# Default value for keep_releases is 5
# set :keep_releases,5
namespace :deploy do
task :start do
invoke 'bin/delayed_job:start'
end
desc 'Restart application'
task :restart do
on roles(:app),in: :sequence,wait: 5 do
execute :touch,release_path.join('tmp/restart.txt')
end
end
after :publishing,'deploy:restart'
after :finishing,'deploy:cleanup'
end
服务器信息:
Ubuntu 20.04
Bundler 已确认安装在服务器上。
我可能需要更改 bundler 的默认版本吗?
我可以看到生成了发布文件夹,但是由于失败,没有创建当前的 sym_link 并且部署失败。我是否缺少将初始上限部署到新登台服务器的服务器设置步骤?我是否需要在特定服务器位置安装 bundler 才能让 cap“找到”它?
解决方法
我能够通过这个拦截器。最终的问题是我必须登录到正确的 shell 并运行 gem install bundler:1.16.1。
为了登录 bash,我使用了以下命令: /bin/bash --login
然后运行 gem install: gem 安装包:1.16.1