0

i followed capistrano in ruby script documentation.

my files:

$ ls
deploy.rb  Gemfile  Gemfile.lock

capistrano version:

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

ruby version:

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

ruby script:

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") 

execution:

$ 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>'

although i am not sure, it seems that the namespace is missing -- Don't know how to build task ':check' -- where ':check' should be 'deploy:check'.

update:

seems that scm variable must be set.

$ 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"

adding set :scm, "deploy" let it continue, but then it fails

/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)

can you please help me understand what is the error and how it might be fixed?

thanks.

Mr.
  • 9,429
  • 13
  • 58
  • 82

1 Answers1

0

I think you have to set the scm option to :git. So this: set :scm, :git. At least that is the default Capistrano itself has.

Also, why didn't you set the stage option as described in capistrano pure ruby guide?

The page explicitly says the stage option needs to be sed before setup and deploy files are loaded.

Note that the require order is important as the stage needs to be set before you load setup and deploy.

Apart from that, you're doing a pretty novel work here (you're the first one I know that's doing this).

  • firstly, thanks for the reply. secondly, setting `scm` to `:git` does not solve the issue, see my `grep` update above. also, adding `set :stage, :production` has no effect since `Capistrano::Application.invoke("production")` is not invoked. though, i set it, it fails due to the `scm`. any other ideas? btw, you could have test your suggestion, you have whatever you need. – Mr. Oct 23 '14 at 11:50