0

我在 ruby​​ 脚本文档中关注capistrano 。

我的文件:

$ ls
deploy.rb  Gemfile  Gemfile.lock

Capistrano 版本:

$ cat Gemfile | grep -i cap
  gem "capistrano", "3.2.1"

红宝石版本:

$ bundle exec ruby --version
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux-gnu]

红宝石脚本:

require "capistrano/all"
set :application, "my_app"
set :deploy_to, "/home/my_app"
set :tmp_dir, "/tmp"
set :keep_releases, 5
SSHKit::Backend::Netssh.configure { |ssh| ssh.ssh_options = { forward_agent: true,  port: 22, user: "deploy_user", keys: "/ssh/key" } }
server "host.example.com", roles: [:myrole]
require "capistrano/setup"
require "capistrano/deploy"
cap_gem_dir = File.join Gem::Specification.find_by_name("capistrano").gem_dir, "lib", "capistrano", "tasks", "*.rake"
Dir.glob(cap_gem_dir).each { |r| import r }
Capistrano::Application.invoke("deploy") 

执行:

$ bundle exec ruby deploy.rb 
** Invoke deploy (first_time)
** Execute deploy
** Invoke deploy:starting (first_time)
** Execute deploy:starting
** Invoke deploy:check (first_time)
** Execute deploy:check
/var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task_manager.rb:62:in `[]': Don't know how to build task ':check' (RuntimeError)
    from /var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:353:in `[]'
    from /var/lib/gems/2.1.0/gems/capistrano-3.2.1/lib/capistrano/dsl.rb:15:in `invoke'
    from /var/lib/gems/2.1.0/gems/capistrano-3.2.1/lib/capistrano/tasks/deploy.rake:36:in `block (2 levels) in <top (required)>'
    from /var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:240:in `call'
    from /var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:240:in `block in execute'
    from /var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:235:in `each'
    from /var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:235:in `execute'
    from /var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
    from /usr/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
    from /var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
    from /var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:165:in `invoke'
    from /var/lib/gems/2.1.0/gems/capistrano-3.2.1/lib/capistrano/dsl.rb:15:in `invoke'
    from /var/lib/gems/2.1.0/gems/capistrano-3.2.1/lib/capistrano/tasks/deploy.rake:4:in `block (2 levels) in <top (required)>'
    from /var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:240:in `call'
    from /var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:240:in `block in execute'
    from /var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:235:in `each'
    from /var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:235:in `execute'
    from /var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
    from /usr/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
    from /var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
    from /var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:165:in `invoke'
    from /var/lib/gems/2.1.0/gems/capistrano-3.2.1/lib/capistrano/dsl.rb:15:in `invoke'
    from /var/lib/gems/2.1.0/gems/capistrano-3.2.1/lib/capistrano/tasks/framework.rake:65:in `block (2 levels) in <top (required)>'
    from /var/lib/gems/2.1.0/gems/capistrano-3.2.1/lib/capistrano/tasks/framework.rake:64:in `each'
    from /var/lib/gems/2.1.0/gems/capistrano-3.2.1/lib/capistrano/tasks/framework.rake:64:in `block in <top (required)>'
    from /var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:240:in `call'
    from /var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:240:in `block in execute'
    from /var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:235:in `each'
    from /var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:235:in `execute'
    from /var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
    from /usr/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
    from /var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
    from /var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task.rb:165:in `invoke'
    from /var/lib/gems/2.1.0/gems/capistrano-3.2.1/lib/capistrano/dsl.rb:15:in `invoke'
    from deploy.rb:13:in `<main>'

虽然我不确定,但似乎缺少命名空间--应该在Don't know how to build task ':check'哪里。':check''deploy:check'

更新:

似乎scm必须设置变量。

$ grep -nH scm /var/lib/gems/2.1.0/gems/capistrano-3.2.1/lib/capistrano/tasks/deploy.rake
/var/lib/gems/2.1.0/gems/capistrano-3.2.1/lib/capistrano/tasks/deploy.rake:9:    invoke "#{scm}:create_release"
/var/lib/gems/2.1.0/gems/capistrano-3.2.1/lib/capistrano/tasks/deploy.rake:36:    invoke "#{scm}:check"
/var/lib/gems/2.1.0/gems/capistrano-3.2.1/lib/capistrano/tasks/deploy.rake:205:    invoke "#{scm}:set_current_revision"

添加set :scm, "deploy"让它继续,但随后失败

/var/lib/gems/2.1.0/gems/rake-10.3.2/lib/rake/task_manager.rb:62:in `[]': Don't know how to build task 'deploy:create_release' (RuntimeError)

你能帮我理解错误是什么以及如何修复它吗?

谢谢。

4

1 回答 1

0

我认为您必须将scm选项设置为:git. 所以这个:set :scm, :git。至少这是Capistrano 本身默认的.

另外,您为什么不按照capistrano pure ruby​​ guidestage中的说明设置选项?

该页面明确表示该选项需要在加载文件stage之前进行 sed setupdeploy

请注意,要求顺序很重要,因为需要在加载设置和部署之前设置阶段。

除此之外,你在这里做了一件非常新颖的工作(你是我知道的第一个这样做的人)。

于 2014-10-23T10:56:03.893 回答