ops_tasks 0.4.4 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/ops_tasks +6 -0
- data/lib/ops_tasks/deployment.rb +43 -9
- data/lib/ops_tasks/rake_helper.rb +11 -0
- data/lib/ops_tasks/scale.rb +48 -0
- data/lib/ops_tasks/version.rb +1 -1
- data/lib/ops_tasks.rb +1 -0
- data/lib/tasks/ops_tasks.rake +14 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e39f0ee2347288b56686c499be7f2b052f7d18c
|
4
|
+
data.tar.gz: c7f98c34b1fef91db220d7227c584ea0d08fcce7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1b664f7a3b5d2017de059e7725885b5fbfc124a8e803767a8eb355b7ddbda316c6e004b958d2ed9072d3fa185d711e71d7fbc45c4830fb8949214441fbdd6db
|
7
|
+
data.tar.gz: 152d54214e45fdfde17fe958c524bb9fb87ea959f741361f892bdf43ceaf8d90f440bb696b82a65515da59eb4af2dc05218a3499666fe7304b044af2afc40444
|
data/bin/ops_tasks
CHANGED
@@ -25,6 +25,12 @@ elsif ARGV[0] == 'add'
|
|
25
25
|
`echo "#{ARGV[1]}_layer_id=" >> .env`
|
26
26
|
`echo "#{ARGV[1]}_project_name=" >> .env`
|
27
27
|
`echo "#{ARGV[1]}_slack_channel=" >> .env`
|
28
|
+
elsif ARGV[0] == 'create_instance'
|
29
|
+
scale = OpsTasks::RakeHelper.create_scale
|
30
|
+
instance_id = scale.create_instance(ARGV[1] == 'true')
|
31
|
+
return false if ARGV[1] == 'true'
|
32
|
+
scale.start_instance(instance_id)
|
33
|
+
scale.wait_for_completion(instance_id)
|
28
34
|
elsif ARGV.size.zero?
|
29
35
|
puts "ops_tasks [deploy|update_cookbooks|setup|configure|init] <args>"
|
30
36
|
else
|
data/lib/ops_tasks/deployment.rb
CHANGED
@@ -10,6 +10,7 @@ module OpsTasks
|
|
10
10
|
@stack_id = args[:stack_id]
|
11
11
|
@slack_channel = args[:room]
|
12
12
|
@project = args[:project]
|
13
|
+
@run_in_background = args[:background]
|
13
14
|
end
|
14
15
|
|
15
16
|
def instance_ids
|
@@ -70,23 +71,56 @@ module OpsTasks
|
|
70
71
|
return id
|
71
72
|
end
|
72
73
|
|
74
|
+
def log_url(deployment_id)
|
75
|
+
@client.describe_commands(
|
76
|
+
:deployment_ids => [deployment_id]
|
77
|
+
)[:log_url]
|
78
|
+
end
|
79
|
+
|
80
|
+
|
73
81
|
def notifications_disabled?
|
74
82
|
ENV["#{@project}_room_notifications"] == 'false'
|
75
83
|
end
|
76
84
|
|
77
|
-
def status(deployment_id)
|
78
|
-
|
85
|
+
# def status(deployment_id)
|
86
|
+
# @client.describe_deployments(:deployment_ids => [deployment_id])[:deployments].first[:status]
|
87
|
+
# end
|
88
|
+
|
89
|
+
def announce_status(task, deployment_id)
|
90
|
+
return false if notifications_disabled?
|
91
|
+
status = assess_status(deployment_id)
|
92
|
+
"Chef".says("#{@project} #{task} #{status}").to_channel(@slack_channel)
|
93
|
+
end
|
94
|
+
|
95
|
+
def assess_status(deployment_id)
|
96
|
+
@client.describe_deployments(
|
97
|
+
:deployment_ids => [deployment_id]
|
98
|
+
)[:deployments].first[:status]
|
99
|
+
end
|
100
|
+
|
101
|
+
def deployment_failed?(id)
|
102
|
+
assess_status(id) == 'failed'
|
103
|
+
end
|
104
|
+
|
105
|
+
def announce_log(id)
|
106
|
+
"Chef".
|
107
|
+
says("<a href='#{log_url(id)}'>failure log</a>").
|
108
|
+
to_channel(@slack_channel)
|
109
|
+
puts log_url(id)
|
110
|
+
end
|
111
|
+
|
112
|
+
def poll_api_for_status(deployment_id, running_status = 'running')
|
113
|
+
sleep 1 until assess_status(deployment_id) != running_status
|
114
|
+
puts assess_status(deployment_id)
|
79
115
|
end
|
80
116
|
|
81
117
|
def wait_for_completion(deployment_id, task="deployment")
|
82
118
|
print "#{@project}: Running... "
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
puts status
|
89
|
-
"Chef".says("#{@project} #{task} #{status}").to_channel(@slack_channel) unless notifications_disabled?
|
119
|
+
announce_status(task, deployment_id)
|
120
|
+
poll_api_for_status(deployment_id)
|
121
|
+
announce_status(task, deployment_id)
|
122
|
+
announce_log(deployment_id) if deployment_failed?(deployment_id)
|
123
|
+
Process.daemon if @run_in_background
|
90
124
|
end
|
91
125
|
end
|
92
126
|
end
|
@@ -46,5 +46,16 @@ module OpsTasks
|
|
46
46
|
room: ENV["#{server_type}_slack_channel"]
|
47
47
|
)
|
48
48
|
end
|
49
|
+
|
50
|
+
def self.create_scale
|
51
|
+
server_type = select_server_type
|
52
|
+
return OpsTasks::Scale.new(
|
53
|
+
layer_id: ENV["#{server_type}_layer_id"],
|
54
|
+
stack_id: ENV["#{server_type}_stack_id"],
|
55
|
+
instance_type: ENV["#{server_type}_instance_type"],
|
56
|
+
project: ENV["#{server_type}_project_name"],
|
57
|
+
room: ENV["#{server_type}_slack_channel"]
|
58
|
+
)
|
59
|
+
end
|
49
60
|
end
|
50
61
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module OpsTasks
|
2
|
+
class Scale < OpsTasks::Deployment
|
3
|
+
def initialize(args)
|
4
|
+
@instance_type = args[:instance_type]
|
5
|
+
super
|
6
|
+
end
|
7
|
+
|
8
|
+
def create_instance(auto_scale = false)
|
9
|
+
args = { :stack_id => @stack_id,
|
10
|
+
:layer_ids => [@layer_id],
|
11
|
+
:instance_type => @instance_type }
|
12
|
+
args[:auto_scale] = 'load' if auto_scale
|
13
|
+
@client.create_instance(args)[:instance_id]
|
14
|
+
end
|
15
|
+
|
16
|
+
def start_instance(instance_id)
|
17
|
+
@client.start_instance(
|
18
|
+
:instance_id => instance_id
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def assess_status(instance_id)
|
23
|
+
@client.describe_instances(
|
24
|
+
:instance_ids => [instance_id]
|
25
|
+
)[:instances].first[:status]
|
26
|
+
end
|
27
|
+
|
28
|
+
def deployment_failed?(instance_id)
|
29
|
+
@client.describe_instances(
|
30
|
+
:instance_ids => [instance_id]
|
31
|
+
)[:instances].first[:status] == 'failed'
|
32
|
+
end
|
33
|
+
|
34
|
+
def poll_api_for_status(deployment_id)
|
35
|
+
sleep 1 until assess_status(deployment_id) == 'online'
|
36
|
+
puts assess_status(deployment_id)
|
37
|
+
end
|
38
|
+
|
39
|
+
def wait_for_completion(instance_id, task="create instance")
|
40
|
+
print "#{@project}: Running... "
|
41
|
+
announce_status(task, instance_id)
|
42
|
+
poll_api_for_status(instance_id)
|
43
|
+
announce_status(task, instance_id)
|
44
|
+
announce_log(instance_id) if deployment_failed?(instance_id)
|
45
|
+
Process.daemon if @run_in_background
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/ops_tasks/version.rb
CHANGED
data/lib/ops_tasks.rb
CHANGED
data/lib/tasks/ops_tasks.rake
CHANGED
@@ -31,4 +31,18 @@ namespace :ops_tasks do
|
|
31
31
|
deploy_id = deployment.configure
|
32
32
|
deployment.wait_for_completion(deploy_id, "configure")
|
33
33
|
end
|
34
|
+
|
35
|
+
desc "create new instance"
|
36
|
+
task :create_instance => :environment do
|
37
|
+
scale = OpsTasks::RakeHelper.create_scale
|
38
|
+
instance_id = scale.create_instance
|
39
|
+
scale.start_instance(instance_id)
|
40
|
+
scale.wait_for_completion(instance_id)
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "create new load-based instance"
|
44
|
+
task :create_load_based_instance => :environment do
|
45
|
+
scale = OpsTasks::RakeHelper.create_scale
|
46
|
+
instance_id = scale.create_instance(true)
|
47
|
+
end
|
34
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ops_tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Prokesch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/ops_tasks/deployment.rb
|
103
103
|
- lib/ops_tasks/railtie.rb
|
104
104
|
- lib/ops_tasks/rake_helper.rb
|
105
|
+
- lib/ops_tasks/scale.rb
|
105
106
|
- lib/ops_tasks/version.rb
|
106
107
|
- lib/tasks/ops_tasks.rake
|
107
108
|
- ops_tasks.gemspec
|