Reputation: 1895
While deploying with Capistrano 3 I need to get the current local application path from a task, does Capistrano provides any static variable containing this information?
Upvotes: 4
Views: 1227
Reputation: 311
I recently had a similar issue where I was downloading a remote file with Capistrano and wanted to place it relative to the task file on my development machine. My rake task looked something like this:
# lib/capistrano/tasks/awesome_tasks.rake
namespace :awesome_tasks do
task :do_something_awesome do
# Set path to local folder containing the task
path = Pathname.new(File.join(__dir__)) # => "parent_folders/app_root/lib/capistrano/tasks"
# Do something with path...
end
end
If you need the path to your application's root directory, you could do something like this:
# lib/capistrano/tasks/awesome_tasks.rake
namespace :awesome_tasks do
task :do_something_awesome do
# Set path to the root of the application.
# Use #realpath to exclude the extra dots (optional)
path = Pathname.new(File.join(__dir__, '../../..')).realpath # => "parent_folders/app_root"
# Do something with path...
end
end
Upvotes: 0