我在Ruby脚本文档中遵循了Capistrano。
我的文件:
$ ls
deploy.rb Gemfile Gemfile.lock
卡皮斯特拉诺版本:
$ 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)
你能帮我了解错误是什么以及如何修复它吗?
谢谢。
我认为您必须将scm
选项设置为 :git
.所以这个:set :scm, :git
.至少这是卡皮斯特拉诺本身的默认。
另外,您为什么不按照 capistrano 纯红宝石指南中的说明设置stage
选项?
该页面明确表示,在加载setup
和deploy
文件之前,需要对stage
选项进行sed。
请注意,需求顺序很重要,因为在加载安装程序和部署之前需要设置阶段。
除此之外,你在这里做了一项非常新颖的工作(你是我知道的第一个这样做的人(。