Tareas útiles en capistrano

Ver los logs

namespace :logs do
  desc "tail rails logs"
  task :tail_rails do
    on roles(:app) do
      execute "tail -f #{shared_path}/log/#{fetch(:rails_env)}.log"
    end
  end

  task :tail, :file do |t, args|
    if args[:file]
      on roles(:app) do
        execute "tail -f #{shared_path}/log/#{args[:file]}.log"
      end
    else
      puts "please specify a logfile e.g: 'rake logs:tail[logfile]"
      puts "will tail 'shared_path/log/logfile.log'"
      puts "remember if you use zsh you'll need to format it as:"
      puts "rake 'logs:tail[logfile]' (single quotes)"
    end
  end
end

Ejecutar tareas rake

Añade la gema capistrano-rake en el grupo development.

# Gemfile
gem 'capistrano-rake', require: false, group: :development

Y añade un require en el Capfile

# Capfile
require 'capistrano/rake'

Ejemplo:

$ cap stage invoke:rake TASK=some:rake_task

Subir y bajar ficheros

namespace :deploy do
  desc "Upload a file."
  # Example
  # cap staging deploy:upload FILE=foo.rb
  # cap staging deploy:upload FILE=foo.rb DESTINATION=tmp
  #
  task :upload do
    on roles(:app) do
      upload!("#{ENV['FILE']}", "#{current_path}/#{ENV['DESTINATION'] || ENV['FILE']}")
    end
  end

  task :download do
    on roles(:app) do
      download!("#{current_path}/#{ENV['FILE']}", "#{ENV['DESTINATION'] || '.'}")
    end
  end
end

Comentarios