Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

deploy.rb: undefined local variable or method `home` for main:Object

I know there are a lot of questions regarding this error message, but I couldn't find one where this error is happening in the same context as mine.

I'm trying to migrate a previously working Capistrano configuration from version 2 to Capistrano 3. Unfortunately, calling cap production deploy --dry-run generates the error

cap aborted!
undefined local variable or method `home' for main:Object
/myapp/config/deploy.rb:6:in `<top (required)>'

Here's the content of deploy.rb up to line 6 where the error occurs:

set :user, "myuser"
set :application, "myapp"
set :domain, "mydomain"
set :repository, "[email protected]:acme/myapp.git"
set :home, "/home/myuser"
set :deploy_to, "#{home}/#{domain}"

I don't know much about Ruby, but from what I've gathered, the colon means these are symbols, not variables, and in the Capistrano documentation they're using the same syntax to define "variables" (see paragraph 5 "Set the shared information in deploy.rb")?

The deploy script ran flawlessly on OS X with Ruby 2.0.0p247 and Capistrano 2.9.0. Now on CentOS with Ruby 1.9.3p545 and Capistrano 3.1.0, the error mentioned above occurs. I've made several changes to the Capfile to get it running with Capistrano 3, but left the deploy.rb untouched, hoping it would work.

like image 757
jgxvx Avatar asked Dec 16 '22 00:12

jgxvx


1 Answers

I don't think Capistrano will create local variables for you, but you can do so yourself:

domain = "mydomain"
home = "/home/myuser"

set :domain, domain
set :home, home
set :deploy_to, "#{home}/#{domain}"

Alternatively, you can use fetch, the counterpart to set:

set :domain, "mydomain"
set :home, "/home/myuser"
set :deploy_to, "#{fetch(:home)}/#{fetch(:domain)}"
like image 193
Patrick Oscity Avatar answered Feb 02 '23 01:02

Patrick Oscity