Rails 6 Capistrano 部署失败,即使应用程序在手动启动时工作正常
Rails 6 Capistrano deploy is failing even though application works fine when it is started manually
因此,当我将此应用程序部署到 Heroku 时,它可以正常工作
我正在尝试将其部署到 VM(数字海洋上的普通 ubuntu 液滴)
已按预期设置 Capistrano。
我无法弄清楚这个错误可能来自哪里
SSHKit::Runner::ExecuteError: Exception while executing as deploy@<IP ADDRRESS>: rake exit status: 1
rake stdout: Nothing written
rake stderr: Nothing written
Capistrano部署日志如下:
00:21 deploy:assets:precompile
01 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile
#<Thread:0x00007ff9d8ba40f8 /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
13: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
12: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:31:in `run'
11: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:31:in `instance_exec'
10: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/capistrano-rails-1.6.1/lib/capistrano/tasks/assets.rake:67:in `block (4 levels) in <top (required)>'
9: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:92:in `within'
8: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/capistrano-rails-1.6.1/lib/capistrano/tasks/assets.rake:68:in `block (5 levels) in <top (required)>'
7: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:100:in `with'
6: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/capistrano-rails-1.6.1/lib/capistrano/tasks/assets.rake:69:in `block (6 levels) in <top (required)>'
5: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:80:in `execute'
4: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:148:in `create_command_and_execute'
3: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:148:in `tap'
2: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:148:in `block in create_command_and_execute'
1: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/netssh.rb:170:in `execute_command'
/Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/command.rb:97:in `exit_status=': rake exit status: 1 (SSHKit::Command::Failed)
rake stdout: Nothing written
rake stderr: Nothing written
1: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as deploy@<IP ADDRRESS>: rake exit status: 1 (SSHKit::Runner::ExecuteError)
rake stdout: Nothing written
rake stderr: Nothing written
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy@<IP ADDRRESS>: rake exit status: 1
rake stdout: Nothing written
rake stderr: Nothing written
Caused by:
SSHKit::Command::Failed: rake exit status: 1
rake stdout: Nothing written
rake stderr: Nothing written
Tasks: TOP => deploy:assets:precompile
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deploy@<IP ADDRRESS>: rake exit status: 1
rake stdout: Nothing written
rake stderr: Nothing written
** DEPLOY FAILED
尝试运行手动执行最后一条命令(如调试日志所示)
cd /home/deploy/mark_antony/releases/20201201034511 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.7.1" RAILS_ENV="production" RAILS_GROUPS="" ; $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile )
这非常好用。
当我尝试 运行 在服务器上手动构建此版本时,它也有效
需要一些帮助
这是我的 deploy.rb
:
# config valid for current version and patch releases of Capistrano
lock "~> 3.14.1"
set :application, "mark_antony"
set :repo_url, "git@gitlab.com:browneinstitute/mark.git"
# Default branch is :master
set :deploy_to, "/home/deploy/#{fetch :application}"
append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', '.bundle', 'public/system', 'public/uploads'
set :keep_releases, 5
append :linked_files, "config/master.key"
旁注:我手动创建了一个新的 current
符号链接到以这种方式创建的发布目录,以查看 nginx 是否能够为该网页提供服务。
它能够
也许您需要重新添加 ssh,试试这个
ssh-add
,然后在您的控制台中再次尝试部署。
问题似乎是您 deploy.rb
中缺少一些关键配置,否则您将无法连接到 Droplet。
# config valid for current version and patch releases of Capistrano
lock "~> 3.14.1"
server 'YOUR_DROPLET_IP',
roles: [:web, :app, :db],
set :user, 'deploy'
set :application, "mark_antony"
set :repo_url, "git@gitlab.com:browneinstitute/mark.git"
# Default branch is :master
set :deploy_to, "/home/deploy/#{fetch :application}"
append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', '.bundle', 'public/system', 'public/uploads'
set :keep_releases, 5
# This might not be needed. If needed make sure to provide the correct path to your ssh key
set :ssh_options, {
forward_agent: true,
user: fetch(:user),
keys: %w(~/.ssh/id_rsa)
}
append :linked_files, "config/master.key"
所以我认为这在预编译资产上总是失败,答案在这里:
帮助解决了这个问题,除了我必须为路径添加一个稍微不同的值
# add in deploy.rb
set :default_env, {
PATH: '$HOME/.nvm/versions/node/v14.15.1/bin/:$PATH',
NODE_ENVIRONMENT: 'production'
}
这是因为虚拟机上的 运行 $ which yarn
返回了以下内容:
/home/deploy/.nvm/versions/node/v14.15.1/bin/yarn
因此,当我将此应用程序部署到 Heroku 时,它可以正常工作
我正在尝试将其部署到 VM(数字海洋上的普通 ubuntu 液滴)
已按预期设置 Capistrano。 我无法弄清楚这个错误可能来自哪里
SSHKit::Runner::ExecuteError: Exception while executing as deploy@<IP ADDRRESS>: rake exit status: 1
rake stdout: Nothing written
rake stderr: Nothing written
Capistrano部署日志如下:
00:21 deploy:assets:precompile
01 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile
#<Thread:0x00007ff9d8ba40f8 /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
13: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
12: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:31:in `run'
11: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:31:in `instance_exec'
10: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/capistrano-rails-1.6.1/lib/capistrano/tasks/assets.rake:67:in `block (4 levels) in <top (required)>'
9: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:92:in `within'
8: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/capistrano-rails-1.6.1/lib/capistrano/tasks/assets.rake:68:in `block (5 levels) in <top (required)>'
7: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:100:in `with'
6: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/capistrano-rails-1.6.1/lib/capistrano/tasks/assets.rake:69:in `block (6 levels) in <top (required)>'
5: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:80:in `execute'
4: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:148:in `create_command_and_execute'
3: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:148:in `tap'
2: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:148:in `block in create_command_and_execute'
1: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/netssh.rb:170:in `execute_command'
/Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/command.rb:97:in `exit_status=': rake exit status: 1 (SSHKit::Command::Failed)
rake stdout: Nothing written
rake stderr: Nothing written
1: from /Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/Users/josh.kurien/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as deploy@<IP ADDRRESS>: rake exit status: 1 (SSHKit::Runner::ExecuteError)
rake stdout: Nothing written
rake stderr: Nothing written
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy@<IP ADDRRESS>: rake exit status: 1
rake stdout: Nothing written
rake stderr: Nothing written
Caused by:
SSHKit::Command::Failed: rake exit status: 1
rake stdout: Nothing written
rake stderr: Nothing written
Tasks: TOP => deploy:assets:precompile
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deploy@<IP ADDRRESS>: rake exit status: 1
rake stdout: Nothing written
rake stderr: Nothing written
** DEPLOY FAILED
尝试运行手动执行最后一条命令(如调试日志所示)
cd /home/deploy/mark_antony/releases/20201201034511 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.7.1" RAILS_ENV="production" RAILS_GROUPS="" ; $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile )
这非常好用。 当我尝试 运行 在服务器上手动构建此版本时,它也有效
需要一些帮助
这是我的 deploy.rb
:
# config valid for current version and patch releases of Capistrano
lock "~> 3.14.1"
set :application, "mark_antony"
set :repo_url, "git@gitlab.com:browneinstitute/mark.git"
# Default branch is :master
set :deploy_to, "/home/deploy/#{fetch :application}"
append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', '.bundle', 'public/system', 'public/uploads'
set :keep_releases, 5
append :linked_files, "config/master.key"
旁注:我手动创建了一个新的 current
符号链接到以这种方式创建的发布目录,以查看 nginx 是否能够为该网页提供服务。
它能够
也许您需要重新添加 ssh,试试这个
ssh-add
,然后在您的控制台中再次尝试部署。
问题似乎是您 deploy.rb
中缺少一些关键配置,否则您将无法连接到 Droplet。
# config valid for current version and patch releases of Capistrano
lock "~> 3.14.1"
server 'YOUR_DROPLET_IP',
roles: [:web, :app, :db],
set :user, 'deploy'
set :application, "mark_antony"
set :repo_url, "git@gitlab.com:browneinstitute/mark.git"
# Default branch is :master
set :deploy_to, "/home/deploy/#{fetch :application}"
append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', '.bundle', 'public/system', 'public/uploads'
set :keep_releases, 5
# This might not be needed. If needed make sure to provide the correct path to your ssh key
set :ssh_options, {
forward_agent: true,
user: fetch(:user),
keys: %w(~/.ssh/id_rsa)
}
append :linked_files, "config/master.key"
所以我认为这在预编译资产上总是失败,答案在这里:
帮助解决了这个问题,除了我必须为路径添加一个稍微不同的值
# add in deploy.rb
set :default_env, {
PATH: '$HOME/.nvm/versions/node/v14.15.1/bin/:$PATH',
NODE_ENVIRONMENT: 'production'
}
这是因为虚拟机上的 运行 $ which yarn
返回了以下内容:
/home/deploy/.nvm/versions/node/v14.15.1/bin/yarn