lita-codedeploy-status 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b8de33754c8e8f0b1b1ebdeaced2c254da96b303
4
+ data.tar.gz: 753eceaf57a1ff4a819c7e429fcafd6feb33f237
5
+ SHA512:
6
+ metadata.gz: 937f0eb5d037580f7a9122111ae4dfe8279b7f53a2c4e1723a79af4c96b995b13aa9391c0e8c2bba8081372c68916c32c2496e13e0c90b6bd7e19ef9712ffe5d
7
+ data.tar.gz: 0482da96c848281a2516908c8f387379703052bc264c755148c99c6693f2260a6e0a1a0d58c378b7cbddb2400d6abc72e57ebaf47793d38722f9542273c1c810
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
19
+ lita_config.rb
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'aws-sdk', '~> 2'
4
+ gem 'time-lord'
5
+
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # lita-codedeploy-status
2
+
3
+ Show AWS CodeDeploy status
4
+
5
+ ## Installation
6
+
7
+ Add lita-codedeploy-status to your Lita instance's Gemfile:
8
+
9
+ ``` ruby
10
+ gem "lita-codedeploy-status"
11
+ ```
12
+
13
+ ## Configuration
14
+
15
+ It is assumed your ENV has the proper environment variables for the aws-sdk gem to function. Typically this
16
+ includes:
17
+ ```
18
+ AWS_REGION
19
+ AWS_ACCESS_KEY_ID
20
+ AWS_SECRET_ACCESS_KEY
21
+ ```
22
+
23
+ These can be overridden using the following config variables:
24
+
25
+ ```ruby
26
+ config.handlers.codedeploy_status.aws_region = 'us-east-1'
27
+ config.handlers.codedeploy_status.aws_access_key = 'XYZ'
28
+ config.handlers.codedeploy_status.aws_secret_access_key = 'ABC'
29
+ ```
30
+
31
+ The minumum required configuration is to declare your branches and which application_name/deployment_group_name they
32
+ point to:
33
+
34
+
35
+ ```ruby
36
+ config.handlers.codedeploy_status.branches = {
37
+ 'master' => {application_name: 'App_Name', deployment_group_name: 'Production_Deployment_Group', default: true},
38
+ 'staging' => {application_name: 'App_Name', deployment_group_name: 'Staging_Deployment_Group'},
39
+ }
40
+ ```
41
+
42
+ ## Usage
43
+
44
+ ```codedeploy-status BRANCH``` - Show/poll for current CodeDeploy status for the application_name/deployment_group_name associated with the specified branch
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,160 @@
1
+ require 'aws-sdk'
2
+ require 'time-lord'
3
+
4
+ module Lita
5
+ module Handlers
6
+ class CodedeployStatus < Handler
7
+ config :aws_region, default: ENV['AWS_REGION'] || 'us-east-1'
8
+ config :aws_access_key
9
+ config :aws_secret_access_key
10
+ config :branches, required: true, type: Hash
11
+
12
+ route(/^codedeploy-status\s*(.*?)$/, :codedeploy_status, help: {"codedeploy-status BRANCH" => "Display CodeDeploy status for most recent deployment of BRANCH"})
13
+
14
+
15
+ def codedeploy_status(response)
16
+ @helper = Module.new do
17
+ def time_ago(t)
18
+ if t
19
+ "(#{TimeLord::Period.new(t, ::Time.now).in_words})"
20
+ end
21
+ end
22
+
23
+ def short_instance_id(instance_id)
24
+ instance_id.split('/')[1]
25
+ end
26
+ end
27
+
28
+ branch_name = response.matches[0][0]
29
+ if branch_name && branch_name != ''
30
+ branch = config.branches[branch_name]
31
+ else
32
+ config.branches.each do |k,v|
33
+ if v[:default]
34
+ branch_name = k
35
+ branch = v
36
+ end
37
+ end
38
+ end
39
+
40
+
41
+ unless deployment_done
42
+ response.reply("Deployment watch in progress - please wait until it is done before starting a new one.")
43
+ return
44
+ end
45
+
46
+ unless branch
47
+ response.reply("Could not find branch info for branch #{branch_name}.")
48
+ return
49
+ end
50
+
51
+ branch[:name] = branch_name
52
+
53
+ log.debug "Starting deployment watch for branch #{branch[:name]}: application_name #{branch[:application_name]}, deployment_group_name #{branch[:deployment_group_name]}"
54
+
55
+ begin
56
+ @deployment_id = latest_deployment_id(branch[:application_name], branch[:deployment_group_name])
57
+ @deployment_instances = get_deployment_instances
58
+
59
+ watch_deployment(branch, response)
60
+ rescue => e
61
+ response.reply("Error: #{e.message}")
62
+ end
63
+ end
64
+
65
+ def watch_deployment(branch, response)
66
+ do_watch_deployment(branch, response)
67
+ unless deployment_done
68
+ every(10) do |timer|
69
+ do_watch_deployment(branch, response, timer)
70
+ end
71
+ end
72
+ end
73
+
74
+ def do_watch_deployment(branch, response, timer=nil)
75
+ begin
76
+ update_deployment_info
77
+
78
+ if deployment_done
79
+ render_output(branch, response)
80
+ timer.stop if timer
81
+ else
82
+ if deployment_updated
83
+ render_output(branch, response)
84
+ end
85
+ end
86
+ rescue => e
87
+ response.reply("Error: #{e.message}")
88
+ end
89
+ end
90
+
91
+ def render_output(branch, response)
92
+ response.reply(render_template_with_helpers("codedeploy_status", [@helper], config: config,
93
+ branch: branch,
94
+ deployment_id: @deployment_id,
95
+ deployment: @deployment,
96
+ deployment_instances: @deployment_instances,
97
+ deployment_instance_status: @deployment_instance_status))
98
+ end
99
+
100
+ def codedeploy_api
101
+ @aws_api ||= codedeploy_api_init
102
+ end
103
+
104
+ def codedeploy_api_init
105
+ if config.aws_access_key && config.aws_secret_access_key
106
+ Aws.config[:credentials] = Aws::Credentials.new(config.aws_access_key, config.aws_secret_access_key)
107
+ end
108
+ if config.aws_region
109
+ Aws.config[:region] = config.aws_region
110
+ end
111
+ Aws::CodeDeploy::Client.new
112
+ end
113
+
114
+ def latest_deployment_id(application_name, deployment_group_name)
115
+ codedeploy_api.list_deployments(application_name: application_name, deployment_group_name: deployment_group_name).deployments.first
116
+ end
117
+
118
+ def get_deployment_instances
119
+ codedeploy_api.list_deployment_instances(deployment_id: @deployment_id).instances_list
120
+ end
121
+
122
+ def deployment_status
123
+ codedeploy_api.get_deployment(deployment_id: @deployment_id)
124
+ end
125
+
126
+ def deployment_instance_status(instance_id)
127
+ codedeploy_api.get_deployment_instance(deployment_id: @deployment_id, instance_id: instance_id)
128
+ end
129
+
130
+ def deployment_done
131
+ @deployment == nil || @deployment.deployment_info.complete_time != nil
132
+ end
133
+
134
+ def deployment_updated
135
+ @previous_instance_id != @current_instance_id ||
136
+ @previous_instance_update != @current_instance_update
137
+ end
138
+
139
+ def update_deployment_info
140
+ @deployment = deployment_status
141
+ @deployment_instance_status = @deployment_instances.collect {|instance_id| deployment_instance_status(instance_id)}
142
+
143
+ raise 'Unable to get deployment info' unless @deployment && @deployment_instance_status
144
+
145
+ @previous_instance_id = @current_instance_id
146
+ @previous_instance_update = @current_instance_update
147
+
148
+ @deployment_instance_status.each do |status|
149
+ if status.instance_summary.status == 'InProgress'
150
+ @current_instance_id = status.instance_summary.instance_id
151
+ @current_instance_update = status.instance_summary.last_updated_at
152
+ end
153
+ end
154
+ end
155
+
156
+
157
+ Lita.register_handler(self)
158
+ end
159
+ end
160
+ end
@@ -0,0 +1,12 @@
1
+ require "lita"
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join("..", "..", "locales", "*.yml"), __FILE__
5
+ )]
6
+
7
+ require "lita/handlers/codedeploy_status"
8
+
9
+ Lita::Handlers::CodedeployStatus.template_root File.expand_path(
10
+ File.join("..", "..", "templates"),
11
+ __FILE__
12
+ )
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-codedeploy-status"
3
+ spec.version = "0.1.0"
4
+ spec.authors = ["Mike Machado"]
5
+ spec.email = ["mike@machadolab.com"]
6
+ spec.description = "Show AWS CodeDeploy status"
7
+ spec.summary = "Show AWS CodeDeploy status"
8
+ spec.homepage = "https://github.com/LeadDyno/lita-codedeploy-status"
9
+ spec.license = "MIT"
10
+ spec.metadata = { "lita_plugin_type" => "handler" }
11
+
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_runtime_dependency "lita", ">= 4.7"
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "pry-byebug"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rack-test"
23
+ spec.add_development_dependency "rspec", ">= 3.0.0"
24
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,4 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ codedeploy_status:
@@ -0,0 +1,4 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::CodedeployStatus, lita_handler: true do
4
+ end
@@ -0,0 +1,6 @@
1
+ require "lita-codedeploy-status"
2
+ require "lita/rspec"
3
+
4
+ # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
5
+ # was generated with Lita 4, the compatibility mode should be left disabled.
6
+ Lita.version_3_compatibility_mode = false
File without changes
@@ -0,0 +1,12 @@
1
+ <%= @deployment.deployment_info.complete_time == nil ? 'Deploying' : 'Deployed' %> <%= @branch_name %>/<%= @deployment_id %> - <%= @deployment.deployment_info.status %> <%= time_ago(@deployment.deployment_info.create_time) %>
2
+
3
+ <% @deployment_instance_status.each do |dis| %>
4
+ <%= short_instance_id(dis.instance_summary.instance_id) %> <%= dis.instance_summary.status %> <%= time_ago(dis.instance_summary.last_updated_at) %>
5
+ <% dis.instance_summary.lifecycle_events.each do |le| %>
6
+ <% if le.start_time != nil && le.end_time == nil %>
7
+ started <%= le.lifecycle_event_name %> <%= time_ago(le.start_time) %>
8
+ <% end %>
9
+ <% end %>
10
+ <% end %>
11
+
12
+ https://console.aws.amazon.com/codedeploy/home?region=<%= @config.aws_region %>#/deployments/<%= @deployment_id %>
@@ -0,0 +1,14 @@
1
+ <%= @deployment.deployment_info.complete_time == nil ? 'Deploying' : 'Deployed' %> <%= @branch[:name] %>/<%= @deployment_id %> - <%= @deployment.deployment_info.status %> <%= time_ago(@deployment.deployment_info.create_time) %>
2
+
3
+ <% @deployment_instance_status.each do |dis| %>
4
+ <%= short_instance_id(dis.instance_summary.instance_id) %> <%= dis.instance_summary.status %> <%= time_ago(dis.instance_summary.last_updated_at) %>
5
+ <% dis.instance_summary.lifecycle_events.each do |le| %>
6
+ <% if le.start_time != nil && le.end_time == nil %>
7
+ started <%= le.lifecycle_event_name %> <%= time_ago(le.start_time) %>
8
+ <% end %>
9
+ <% end %>
10
+ <% end %>
11
+ <%= @deployment.deployment_info.complete_time != nil ? ['(dance)','(badass)','(cake)','(excellent)','(giggity)','(indeed)','(nice)','(ohmy)','(dosequis)','(rockon)','(salute)','(yey)','(fonzie)'].sample : '' %>
12
+
13
+
14
+ https://console.aws.amazon.com/codedeploy/home?region=<%= @config.aws_region %>#/deployments/<%= @deployment_id %>
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-codedeploy-status
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Machado
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 3.0.0
97
+ description: Show AWS CodeDeploy status
98
+ email:
99
+ - mike@machadolab.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - README.md
107
+ - Rakefile
108
+ - lib/lita-codedeploy-status.rb
109
+ - lib/lita/handlers/codedeploy_status.rb
110
+ - lita-codedeploy-status.gemspec
111
+ - locales/en.yml
112
+ - spec/lita/handlers/codedeploy_status_spec.rb
113
+ - spec/spec_helper.rb
114
+ - templates/.gitkeep
115
+ - templates/codedeploy_status.erb
116
+ - templates/codedeploy_status.hipchat.erb
117
+ homepage: https://github.com/LeadDyno/lita-codedeploy-status
118
+ licenses:
119
+ - MIT
120
+ metadata:
121
+ lita_plugin_type: handler
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.4.8
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Show AWS CodeDeploy status
142
+ test_files:
143
+ - spec/lita/handlers/codedeploy_status_spec.rb
144
+ - spec/spec_helper.rb