Module: RatDeployer::Notifier
- Defined in:
- lib/rat_deployer/notifier.rb
Overview
RatDeployer::Notifier handles notifications to slack
Class Method Summary collapse
- .deploy_properties ⇒ Object
- .notify(msg) ⇒ Object
- .notify_deploy(title) ⇒ Object
- .notify_deploy_end ⇒ Object
- .notify_deploy_start ⇒ Object
- .slack_notifier ⇒ Object
- .webhook_url ⇒ Object
Class Method Details
.deploy_properties ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rat_deployer/notifier.rb', line 60 def self.deploy_properties require 'socket' compose_config = RatDeployer::Cli.new.compose('config', silent: true) docker_config = YAML.safe_load(compose_config) images = docker_config['services'].map { |_s, c| c['image'] }.uniq.sort { env: RatDeployer::Config.env, user: ENV.fetch('USER'), hostname: Socket.gethostname, started_at: Time.now.to_s, images: images } end |
.notify(msg) ⇒ Object
18 19 20 21 22 |
# File 'lib/rat_deployer/notifier.rb', line 18 def self.notify(msg) return unless webhook_url return unless webhook_url slack_notifier.ping msg end |
.notify_deploy(title) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rat_deployer/notifier.rb', line 24 def self.notify_deploy(title) return unless webhook_url props = deploy_properties slack_notifier.post( text: title, attachments: [{ title: 'Deploy details', fields: props.map do |k, v| { title: k.to_s.titleize, value: k == :images ? v.join(' · ') : v, short: k != :images } end }] ) end |
.notify_deploy_end ⇒ Object
13 14 15 16 |
# File 'lib/rat_deployer/notifier.rb', line 13 def self.notify_deploy_end return unless webhook_url notify_deploy "Ended deploy on #{RatDeployer::Config.env}" end |
.notify_deploy_start ⇒ Object
8 9 10 11 |
# File 'lib/rat_deployer/notifier.rb', line 8 def self.notify_deploy_start return unless webhook_url notify_deploy "Starting deploy on #{RatDeployer::Config.env}" end |
.slack_notifier ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rat_deployer/notifier.rb', line 43 def self.slack_notifier return unless webhook_url @slack_notifier ||= begin Slack::Notifier.new( webhook_url, channel: '#alerts', username: 'rat-deployer' ) end end |
.webhook_url ⇒ Object
56 57 58 |
# File 'lib/rat_deployer/notifier.rb', line 56 def self.webhook_url @webhook_url ||= RatDeployer::Config.all['slack_webhook_url'] end |