Skip to content

Instantly share code, notes, and snippets.

@heycarsten
Last active August 21, 2017 19:05
Show Gist options
  • Save heycarsten/5119959 to your computer and use it in GitHub Desktop.
Save heycarsten/5119959 to your computer and use it in GitHub Desktop.
Dramatically clean up and jazzify your Capistrano output.

Jazzy Capistrano Output

screenshot

Place the contents below in a file at config/deploy/ext/jazzy.rb:

# coding: utf-8
unless ENV['UNJAZZY']
  STDOUT.sync
  logger.level = Capistrano::Logger::IMPORTANT

  # Spinner Jazz via: http://jondavidjohn.com/blog/2012/04/cleaning-up-capistrano-deployment-output
  @jazzy_spinner_running = false
  @jazzy_spinner_chars = ['|', '/', '-', '\\'].map { |ch| "\b\e[36m#{ch}\e[0m" }
  @jazzy_spinner = Thread.new do
    loop do
      unless @jazzy_spinner_running
        Thread.stop
      end
      print @jazzy_spinner_chars[0]
      sleep(0.05)
      @jazzy_spinner_chars.push(@jazzy_spinner_chars.shift)
    end
  end

  def start_jazzy_spinner
    print ' '
    @jazzy_spinner_running = true
    @jazzy_spinner.wakeup
  end

  def stop_jazzy_spinner
    @jazzy_spinner_running = false
    print "\b"
  end

  def jazzy_notify(task_name, msg)
    before(task_name) do
      trail = ('.' * (48 - msg.length))
      print("\e[1m-->\e[0m #{msg} #{trail} ")
      start_jazzy_spinner
    end

    after(task_name) do
      stop_jazzy_spinner
      puts("\e[32m✔\e[0m")
    end
  end

  jazzy_notify 'deploy:update_code',       'Updating codebase'
  jazzy_notify 'deploy:assets:precompile', 'Compiling assets'
  jazzy_notify 'deploy:create_symlink',    'Switching to new release'
  jazzy_notify 'deploy:migrate',           'Migrating database'
  jazzy_notify 'deploy:restart',           'Restarting application'

  # You can also include your own stuff
  jazzy_notify 'config:symlink', 'Updating symlinks'
end

Now to get this working, add the following line to your Capfile:

load 'config/deploy/ext/jazzy'

Place it just above this line:

load 'config/deploy'

You can also disable jazzy output by calling Capistrano with the environment variable UNJAZZY set to anything truthy.

UNJAZZY=1 cap deploy

For background on this, check out: http://jondavidjohn.com/blog/2012/04/cleaning-up-capistrano-deployment-output

I hope you enjoy!

@AliHichem
Copy link

You rock man !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment