Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get path to capistrano shared path from ruby

I know that I can get the location of my rails app with Rails.root:

> Rails.root
 => #<Pathname:/var/www/app-name/releases/20150507181426>

I am looking for the function to call to get capistrano's shared folder, which in this case is found here:

/var/www/app-name/shared/

I need to be able to get the path from within ruby code. Thanks in advance.

like image 718
Rick Smith Avatar asked Jan 09 '23 10:01

Rick Smith


2 Answers

You really shouldn't need to know what Capistrano's shared path is. During the deployment process it's expected that you'll create links to any directories that are shared between deployments.

The linked_dirs variable defines this:

set :linked_dirs, %w[ example ]

If set, during deployment releases/NNN/example will be linked to shared/example. You can add or alter this list as required.

Update:

If you're concerned about this symlink being removed as subsequent deployments are applied, it's worthwhile to expand this link to the full path by whatever process uses it before exercising that.

Following these links is the most reliable way to get to the proper destination.

like image 57
tadman Avatar answered Jan 17 '23 21:01

tadman


You can simply use the global capistrano variable shared_path (works on capistrano v2 and v3).

It provide you the base path of your shared stuff:

puts "#{shared_path}"
=> /DEPLOY_PATH/APP_NAME/shared

A list of possible useful global variables can be found here, I guess that most of them work well in capistrano v3 too.


UPDATE

Just note that most of them are only available under the capistrano libs (deploy.rb or the custom stages: development.rb,staging.rb, production.rb,...) or in the capistrano rake tasks (when using for example the on role(:app) do {...}callback).

like image 43
damoiser Avatar answered Jan 17 '23 20:01

damoiser