Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Capistrano using /u/apps/ in the current_path, even though I've set :deploy_to

Tags:

capistrano

For some reason Capistrano is failing on just about every operation, because it seems to think my current_path should be in /u/apps/. I've set all the variables that (AFAIK) should be set, and eliminated all other similar default paths, but this one persists.

Here are the values returned by relevant variables:

current_dir: current
releases_path: /var/www/vhosts/dev.www.example.com/html/releases
shared_path: /var/www/vhosts/dev.www.example.com/html/shared
current_path: /u/apps/www.example.com/current

I'm setting :deploy_to, so shouldn't current_path be computed based on that!?

set :deploy_to, "/var/www/vhosts/dev.www.example.com/"
like image 915
iconoclast Avatar asked Sep 10 '12 18:09

iconoclast


3 Answers

The kind of kludgey solution is just to manually

set :current_path, ""

The better solution, which can be found explained in this e-mail thread by Jamis Buck himself, is to use lazy evaluation when you set another variable that depends on current_path. In my case, I had a setting something like this

set :some_path_var, "#{current_path}/some/path/"

that I had to change to something like this:

set(:some_path_var) { "#{current_path}/some/path/" }

By passing in a block, the :some_path_var was not immediately evaluated, and did not force current_path to be evaluated based on a default value for :deploy_to

like image 85
iconoclast Avatar answered Oct 17 '22 17:10

iconoclast


So I had this issue as well and I found that this was the best solution.

Add this to your config/deploy.rb

  desc "Make sure the symlink will be from the right directory"
  task :change_correct_dir, roles: :web do
    set :current_path, File.join(deploy_to, current_dir)
  end
  before "deploy:create_symlink", "deploy:change_correct_dir"

I got the idea from looking at the source of the capistrano gem and finding

_cset(:current_path) { File.join(deploy_to, current_dir) in

lib/capistrano/recipes/deploy.rb

like image 24
Will Avatar answered Oct 17 '22 18:10

Will


This can also happen if you don't specify a task in your cap command.

cap deploy:setup

Will attempt to set up Capistrano in /u/apps

cap production deploy:setup

Will set up Capistrano in the directory specified in :deploy_to.

like image 1
Jarred Avatar answered Oct 17 '22 18:10

Jarred