caphub icon indicating copy to clipboard operation
caphub copied to clipboard

cap -T throw error

Open oayoub84 opened this issue 9 years ago • 4 comments

Hi, after installing caphub and initializing the project, i've created the production.rb file in deploy/namespace/frontoffice/production.rb.

But the cap -T throw me an error:

cap aborted! NoMethodError: undefined method gsub' for #<Proc:0x007fa56b3f9900> /usr/local/lib/ruby/gems/2.2.0/gems/capistrano-3.5.0/lib/capistrano/defaults.rb:2:inblock in <top (required)>' /usr/local/lib/ruby/gems/2.2.0/gems/capistrano-3.5.0/lib/capistrano/configuration/variables.rb:126:in call' /usr/local/lib/ruby/gems/2.2.0/gems/capistrano-3.5.0/lib/capistrano/configuration/variables.rb:126:inblock in invoke_validations' /usr/local/lib/ruby/gems/2.2.0/gems/capistrano-3.5.0/lib/capistrano/configuration/variables.rb:125:in each' /usr/local/lib/ruby/gems/2.2.0/gems/capistrano-3.5.0/lib/capistrano/configuration/variables.rb:125:ininvoke_validations' /usr/local/lib/ruby/gems/2.2.0/gems/capistrano-3.5.0/lib/capistrano/configuration/variables.rb:34:in set' /Users/USERNAME/www/deploy/config/deploy.rb:9:in<top (required)>' /usr/local/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/rake_module.rb:28:in load' /usr/local/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/rake_module.rb:28:inload_rakefile' /usr/local/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/default_loader.rb:10:in load' /usr/local/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:764:inload_imports' /usr/local/lib/ruby/gems/2.2.0/gems/capistrano-3.5.0/lib/capistrano/application.rb:96:in load_imports' /usr/local/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:694:inraw_load_rakefile' /usr/local/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:96:in block in load_rakefile' /usr/local/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:178:instandard_exception_handling' /usr/local/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:95:in load_rakefile' /usr/local/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:79:inblock in run' /usr/local/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:178:in standard_exception_handling' /usr/local/lib/ruby/gems/2.2.0/gems/rake-11.2.2/lib/rake/application.rb:77:inrun' /usr/local/lib/ruby/gems/2.2.0/gems/capistrano-3.5.0/lib/capistrano/application.rb:14:in run' /usr/local/lib/ruby/gems/2.2.0/gems/capistrano-3.5.0/bin/cap:3:in<top (required)>' /usr/local/bin/cap:23:in load' /usr/local/bin/cap:23:in

'

oayoub84 avatar Jul 11 '16 14:07 oayoub84

Could you show your file layout?

$ tree
$ ls -R

ayanko avatar Jul 11 '16 16:07 ayanko

. ├── Capfile ├── Gemfile ├── Gemfile.lock ├── config │   ├── deploy │   │   └── example.com │   │   └── frontoffice │   │   └── production.rb │   └── deploy.rb └── tasks

Capfile Gemfile Gemfile.lock config tasks

./config: deploy deploy.rb

./config/deploy: example.com

./config/deploy/example.com: frontoffice

./config/deploy/example.com/frontoffice: production.rb

./tasks:

oayoub84 avatar Jul 11 '16 22:07 oayoub84

This is because of stupid default validation for :application variable in capistrano 3.5 that does NOT consider the fact that variable can be a lambda. https://github.com/capistrano/capistrano/blob/v3.5.0/lib/capistrano/defaults.rb#L1-L9

I suggest two solutions

Solution1. Remove stupid validation

config/deploy.rb

env.variables.send(:validators).delete(:application)
set :application, -> { fetch(:stage).split(':').reverse[1] }

Solution2. Use "static" application variable name

Remove dynamic application variable from config/deploy.rb and define it explicitly in each your stage. E.g.:

config/deploy/frontoffice.rb

set :application, 'frontoffice'

config/deploy/example_com.rb

set :application, 'example_com'

This is not DRY.

ayanko avatar Jul 14 '16 21:07 ayanko

Thanks @ayanko - solution 1 solved it for me.

taylorwilliams avatar Jan 19 '17 15:01 taylorwilliams