简体   繁体   English

Capistrano 3 - 了解任务

[英]Capistrano 3 - Understand tasks

i'm trying to understand how capistrano 3.1 is working, but because of its lack of documentation (its capistrano, so...), im running below my understanding. 我试图理解capistrano 3.1是如何工作的,但由于缺乏文档(它的capistrano,所以...),我的运行低于我的理解。

Let me explain. 让我解释。

Here's a snippet taken from capistrano/rails gem 这是一个取自capistrano / rails gem的片段

namespace :deploy do

  desc 'Runs rake db:migrate if migrations are set'
  task :migrate => [:set_rails_env] do
    on primary fetch(:migration_role) do
      within release_path do
        with rails_env: fetch(:rails_env) do
          execute :rake, "db:migrate"
        end
      end
    end
  end

  #[...]
end

when execute cap integration deploy:migrate , it sends the following command: cd /srv/app/releases/20131106101722 && ( RAILS_ENV=integration /tmp/app/rvm-auto.sh . rake assets:precompile ) 当执行cap integration deploy:migrate ,它会发送以下命令: cd /srv/app/releases/20131106101722 && ( RAILS_ENV=integration /tmp/app/rvm-auto.sh . rake assets:precompile )

I changed a little bit the (non-working) code provided for delayed_job into that 我将为delayed_job提供的(非工作)代码改为一点

namespace :delayed_job do
  def args
    fetch(:delayed_job_args, '')
  end

  def delayed_job_roles
    fetch(:delayed_job_server_role, :app)
  end

  def delayed_job_bin
    fetch(:delayed_job_bin, :'bin/delayed_job')
  end

  desc 'Restart the delayed_job process'
  task :restart do
    on roles(delayed_job_roles) do
      within release_path do
        with rails_env: fetch(:rails_env) do
          execute delayed_job_bin, 'restart', args
        end
      end
    end
  end
end

And i get the following command cd /srv/winddle/current && ( RAILS_ENV=integration bin/delayed_job restart ) 我得到以下命令cd /srv/winddle/current && ( RAILS_ENV=integration bin/delayed_job restart )

Obviously, it misses the bundle exec command. 显然,它错过了bundle exec命令。 I dive deeply into capistrano/bundler and capistrano/rails to look for some kind of hook that would add bundle exec automatically to any of these commands (or force the register of ssh kits commands) but couldnt find any. 我深入了解capistrano / bundler和capistrano / rails,寻找某种钩子,它会自动将bundle exec添加到这些命令中(或者强制ssh kit命令的注册)但却无法找到。

The only solution i found is to use execute :bundle, :exec, delayed_job_bin, :start, args which is not acceptable of course. 我找到的唯一解决方案是使用execute :bundle, :exec, delayed_job_bin, :start, args当然是不可接受的。

Anyone proper solution / explanation is welcomed. 欢迎任何适当的解决方案/解释。 Regards 问候

I'm literally just starting out with Capistrano and also struggling against a lack of documentation, so sorry if this post misses the mark. 我实际上刚刚开始使用Capistrano并且还在努力避免缺少文档,所以很抱歉如果这篇文章错过了这个标记。

v3 relies a lot on sshkit , so reading the documentation for that should be a big help. v3很依赖sshkit ,所以阅读文档应该是一个很大的帮助。 The readme gives an example that may solve your problem. 自述文件提供了一个可以解决您的问题的示例。

SSHKit.config.command_map.prefix[:rake].push("bundle exec")
puts SSHKit.config.command_map[:rake]
# => bundle exec rake

I also found an alternative solution in a Semaphore blog post . 我还在Semaphore博客文章中找到了另一种解决方案。

SSHKit.config.command_map[:rake]  = "bundle exec rake"
SSHKit.config.command_map[:rails] = "bundle exec rails"

Add the following line in deploy.rb , then use the code provided by delayed_job other than changing script to bin , which I see you already did: deploy.rb添加以下行,然后使用delayed_job提供的代码,而不是将script更改为bin ,我看到你已经这样做了:

set :bundle_bins, fetch(:bundle_bins, []).push('bin/delayed_job')

For users of RVM, add this instead: 对于RVM用户,请添加以下内容:

set :rvm_map_bins, fetch(:rvm_map_bins, []).push('bin/delayed_job')

Source: https://github.com/capistrano/bundler#usage . 资料来源: https//github.com/capistrano/bundler#usage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM