Capistrano - name of the car

I have this task that uploads production logs to my local machine. It works great if you have one machine, but if you have several files, they will be overwritten.

namespace :log do desc "Get production log files" task :get_prod, :roles => :app do download("/home/user/myapp/shared/log/production.log", "log/production.log") end end 

I would like to add some kind of identifier to the file name so that it is unique, but I'm not sure what to use? Is there a capistrano variable that I can use?

+4
source share
1 answer

Yes there is a special variable that you can use. This variable ("$ CAPISTRANO: HOST $") should be placed in the destination file name. Capistrano will interpolate it with the name of the host from which it is currently transferring files. *

Your code will now look like this:

 namespace :log do desc "Get production log files" task :get_prod, :roles => :app do download("#{shared_path}/log/production.log", "log/production.$CAPISTRANO:HOST$.log") end end 

Note that I also used the shared_path variable to make the code more DRY. It’s good practice to save the configuration in one place.


* The source code for string interpolation is in the line lib / capistrano / transfer.rb 194 (in Capistrano 2.5.19):

 ... def normalize(argument, session) if argument.is_a?(String) argument.gsub(/\$CAPISTRANO:HOST\$/, session.xserver.host) elsif argument.respond_to?(:read) ... 

General advice: if you try to find something primarily on the Internet, and when you do not find it there quite quickly, look at the source code (it does not bite and lets you know how you work with the tool).

+4
source

Source: https://habr.com/ru/post/1339736/


All Articles