bukk530
bukk530

Reputation: 1895

Capistrano current application path

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

Answers (2)

Tayden
Tayden

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

bukk530
bukk530

Reputation: 1895

Solved using the current working directory Dir.pwd

Upvotes: 4

Related Questions