Capistrano:不知道如何构建任务&deploy; new_release_path'

时间:2016-12-23 19:41:07

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

我第一次部署到Digital Ocean Ubuntu Droplet。我已经配置了所有内容并遵循了所有步骤,现在我正在执行命令的步骤:cap production deploy:initial。对于此命令,我收到此错误消息:

cap aborted!
Don't know how to build task 'deploy:new_release_path' (see --tasks)
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/task_manager.rb:58:in `[]'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:361:in `[]'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/capistrano-3.7.1/lib/capistrano/dsl/task_enhancements.rb:12:in `after'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/capistrano-3.7.1/lib/capistrano/scm/git.rb:21:in `register_hooks'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/capistrano-3.7.1/lib/capistrano/configuration/plugin_installer.rb:28:in `install'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/capistrano-3.7.1/lib/capistrano/configuration.rb:155:in `install_plugin'
/Users/Christopher/ClientProjects/PawBookings/Capfile:3:in `<top (required)>'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/rake_module.rb:28:in `load'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/rake_module.rb:28:in `load_rakefile'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:687:in `raw_load_rakefile'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:96:in `block in load_rakefile'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:95:in `load_rakefile'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:79:in `block in run'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:77:in `run'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/capistrano-3.7.1/lib/capistrano/application.rb:14:in `run'
/Users/Christopher/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/capistrano-3.7.1/bin/cap:3:in `<top (required)>'
/Users/Christopher/.rbenv/versions/2.3.1/bin/cap:22:in `load'
/Users/Christopher/.rbenv/versions/2.3.1/bin/cap:22:in `<main>'

Capfile

# Load DSL and Setup Up Stages
require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git
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

# Change these
server '12.34.56.789', port: 80, roles: [:web, :app, :db], primary: true

set :repo_url,        'my_ssh_github_url'
set :application,     'app_name'
set :user,            'deploy_username'
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

配置/ nginx.conf

upstream puma {
  server unix:///home/deploy_username/apps/app_name/shared/tmp/sockets/app_name-puma.sock;
}

server {
  listen 80 default_server deferred;
  # server_name example.com;

  root /home/deploy_username/apps/app_name/current/public;
  access_log /home/deploy_username/apps/app_name/current/log/nginx.access.log;
  error_log /home/deploy_username/apps/app_name/current/log/nginx.error.log info;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @puma;
  location @puma {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_pass http://puma;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 10M;
  keepalive_timeout 10;
}

更新

我在Capfile中移动了几行代码。该过程似乎已经开始,但现在给出以下错误消息:

** Invoke production (first_time)
** Execute production
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke bundler:map_bins (first_time)
** Execute bundler:map_bins
** Invoke deploy:set_rails_env (first_time)
** Execute deploy:set_rails_env
** Invoke deploy:set_linked_dirs (first_time)
** Execute deploy:set_linked_dirs
** Invoke deploy:set_rails_env
** Invoke rvm:hook (first_time)
** Execute rvm:hook
cap aborted!
Net::SSH::Disconnect: connection closed by remote host

新的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'
require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git

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

2 个答案:

答案 0 :(得分:18)

Git插件依赖于存在的部署任务。在Capfile中,您必须在需要capistrano/deploy后安装Git插件,如下所示:

require "capistrano/deploy"
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git

答案 1 :(得分:1)

这主要是由于 ruby​​、rails 和 ubuntu 更新的版本问题。我遇到了同样的问题。

在最后一行之前在 Capfile 中添加以下行,这解决了我的问题。

install_plugin Capistrano::Puma::Daemon

参考以下教程。会对某人有帮助。因为我花了很多时间来寻找解决方案。 https://matthewhoelter.com/2020/11/10/deploying-ruby-on-rails-for-ubuntu-2004.html