Capistrano 3 execute within a directory
Smells like a Cap 3 bug.
I suggest just guaranteeing you are where you want to be from the shell perspective:
execute "cd '#{release_path}'; #{fetch(:composer_command)} install"
Running task before deploy:symlink:shared capistrano 3
I had left this as a comment to my question, but at the moment, it's the only answer I can find, so I'm promoting it to an answer;
OK, so I've determined a possible way to do it, but it seems horrible. Even for an absolute beginner like me:
newreleasedir = capture('ls -t /sites/releases | head -1')
then
execute "cd /sites/releases/#{newreleasedir} && composer install"
Someone please tell me that's horrible and how I should be doing it :)
How to execute a command on the server with Capistrano?
You want to use script/runner. It starts an instance of the app to execute the method you want to call. Its slow though as it has to load all of your rails app.
~/user/mysite.com/current/script/runner -e production FeedEntry.update_all 2>&1
You can run that from the capistrano task.
Capistrano doesn't obey within release_path
There's useful information in another answer here but briefly it seems the problem arises when there are spaces in the command you want to run.
I followed bricker's suggestion, e.g.
within release_path do
execute *%w[ ln -nfs /home/blog/config/database.yml ./database.yml ]
end
Checking directory existence in Capistrano task fails
All Ruby methods that you use in your Capistrano tasks run on your local machine.
For example:
File.directory?
File.symlink?
These are always evaluated on your local filesystem. Capistrano never runs Ruby code on the remote server. These methods always return false
for you because they are trying to find e.g. "#{release_path}/public"
on your local computer, which of course does not exist.
To run code on the server, the tools available to you are Capistrano's test
and execute
methods. These take in a command string that is executed remotely via SSH.
If you want to test if a remote path is a directory, you cannot use Ruby; you have to use something that can be run in a remote shell. Here is one way to test if a path is a directory, for example:
is_directory = test("[ -d #{release_path}/public ]")
Likewise, to test if a path is a symlink:
is_symbolic_link = test("[ -h #{release_path}/public ]")
Related Topics
Rails 3: Call Functions Inside Controllers
How to Remove Repeated Spaces in a String
What Is a Robust Installation Process for Nokogiri (On Ubuntu)
How to Assert Certain Method Is Called with Ruby Minitest Framework
Passing @Object into a Rails Partial Render
Rubocop Error 'Class Definition Is Too Long Ruby'
Webkit_Server Hangs Periodically When Run from Capybara in Ruby
Collectionproxy VS Associationrelation
How to Look Up Elevation Data by Lat/Lng
How to Iterate Through an Array Starting from the Last Element? (Ruby)
How to Check for Stdin Input in a Ruby Script
Watir. Scroll to a Certain Point of the Page