diff --git a/Gemfile b/Gemfile index 29f1b5617..de2fed797 100644 --- a/Gemfile +++ b/Gemfile @@ -112,6 +112,8 @@ group :development do gem 'binding_of_caller' gem 'meta_request' gem 'localeapp' + gem 'skype' + gem 'ruby-dbus' if RUBY_PLATFORM =~ /linux/i end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index a186dc444..9418d22cb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -411,6 +411,8 @@ GEM skinny (0.2.3) eventmachine (~> 1.0.0) thin (~> 1.5.0) + skype (0.2.7) + tmp_cache soundmanager-rails (1.0.0) sprockets (2.2.2) hike (~> 1.2) @@ -433,6 +435,7 @@ GEM time_diff (0.3.0) activesupport i18n + tmp_cache (0.1.1) treetop (1.4.15) polyglot polyglot (>= 0.3.1) @@ -540,6 +543,7 @@ DEPENDENCIES sass-rails (~> 3.2.5) shotgun shoulda + skype soundmanager-rails state_machine therubyracer (~> 0.12.1) diff --git a/config/deploy.rb.sample b/config/deploy.rb.sample index f2e416ea5..66d98e9b2 100644 --- a/config/deploy.rb.sample +++ b/config/deploy.rb.sample @@ -33,6 +33,9 @@ require 'puma/capistrano' set :workers_count, 4 require './lib/recipes/resque' +require './lib/recipes/skype' +set :skype_topic, 'ABF' # Skype chat topic name + namespace :deploy do task :symlink_all, :roles => :app do run "mkdir -p #{fetch :shared_path}/config" diff --git a/lib/recipes/skype.rb b/lib/recipes/skype.rb new file mode 100644 index 000000000..c8070ba15 --- /dev/null +++ b/lib/recipes/skype.rb @@ -0,0 +1,80 @@ +require 'skype' + +Capistrano::Configuration.instance(:must_exist).load do + Skype.config app_name: 'test-message' + set :skype_send_notification, true + + namespace :skype do + task :trigger_notification do + set :skype_send_notification, true if !dry_run + end + + task :configure_for_migrations do + set :skype_with_migrations, ' (with migrations)' + end + + task :notify_deploy_started do + if skype_send_notification + + environment_string = env + if self.respond_to?(:stage) + environment_string = "#{stage} (#{env})" + end + + on_rollback do + send("Cancelled deployment of #{deployment_name} to #{environment_string}.") + send('#'*60) + end + send('#'*60) + send("Deploying #{deployment_name} to #{environment_string}#{fetch(:skype_with_migrations, '')}.") + end + end + + task :notify_deploy_finished do + if skype_send_notification + + environment_string = env + if self.respond_to?(:stage) + environment_string = "#{stage} (#{env})" + end + + send("Finished deploying #{deployment_name} to #{environment_string}#{fetch(:skype_with_migrations, '')}.") + send('#'*60) + end + end + + def send(message) + set :skype_client, Skype.chats.find { |c| c.topic == fetch(:skype_topic, '') } if fetch(:skype_client, nil).nil? + + begin + skype_client.post(message) + rescue => e + puts e.message + puts e.backtrace + end + end + + def deployment_name + if fetch(:branch, nil) + name = "#{application}/#{branch}" + name += " (revision #{real_revision[0..7]})" if real_revision + name + else + application + end + end + + def message_notification + fetch(:skype_announce, false) + end + + def env + fetch(:skype_env, fetch(:rack_env, fetch(:rails_env, "production"))) + end + end + + before "deploy", "skype:trigger_notification" + before "deploy:update_code", "skype:notify_deploy_started" + after "deploy", "skype:notify_deploy_finished" + after "deploy:migrations", "skype:notify_deploy_finished" +end