bbc-cosmos-tools 0.1.6 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/bbc/cosmos/tools/commands/base.rb +2 -2
- data/lib/bbc/cosmos/tools/commands/stack.rb +85 -67
- data/lib/bbc/cosmos/tools/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dc8be1f2f3a4a303adfe5231c6c48fa611d7fe0
|
4
|
+
data.tar.gz: 6914445689b9353b34e90c419d6dd251f4f9e26f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f86f3cdcc8fc06c485f4f6376d29c9ab786f453a5f332e828b16b904404a25d7508b221d50cec41400d7c32b3bb44351c2ab27f0490dd4367cb931f3eff253f
|
7
|
+
data.tar.gz: 68864cabba5957372a7ad1e5b526c5618ede9462455e1cd33cd7fcb218cb81ef1834c95aed8165a5876ca17893c439978b087de62c4b257d41499af279c8b40e
|
@@ -41,9 +41,9 @@ module BBC
|
|
41
41
|
components = component.nil? ? config.components_for(options[:tags]).keys : [component]
|
42
42
|
end
|
43
43
|
|
44
|
-
def api_error(response)
|
44
|
+
def api_error(response, die = true)
|
45
45
|
error_message = JSON.parse(response.body)['message']
|
46
|
-
error(error_message)
|
46
|
+
error(error_message, die)
|
47
47
|
end
|
48
48
|
|
49
49
|
def build_table(headers, data)
|
@@ -16,34 +16,39 @@ module BBC
|
|
16
16
|
@api = BBC::Cosmos::Tools::API.new(config.app['api'], options[:key_path])
|
17
17
|
end
|
18
18
|
|
19
|
-
desc "stack list [COMPONENT]", "Lists stacks for a component"
|
20
|
-
|
19
|
+
desc "stack list [COMPONENT = nil]", "Lists stacks for a component"
|
20
|
+
method_option :tags, :type => :array, :default => nil, :desc => "The tags of the components you want to deploy (i.e 'renderer')"
|
21
|
+
def list(component = nil)
|
21
22
|
|
22
23
|
say "#{banner}\n"
|
23
|
-
response = api.get sprintf(config.app['stacks'], options[:env], component)
|
24
24
|
|
25
|
-
|
25
|
+
components(options, component).each do |id|
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
stack['updated_at'],
|
32
|
-
stack['status']
|
33
|
-
]
|
34
|
-
end
|
27
|
+
response = api.get sprintf(config.app['stacks'], options[:env], id)
|
28
|
+
say get_key_value("\nComponent", id)
|
29
|
+
|
30
|
+
if response.success?
|
35
31
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
32
|
+
data = JSON.parse(response.body).map do |stack|
|
33
|
+
[
|
34
|
+
stack['name'].split('-').last,
|
35
|
+
stack['main_stack'],
|
36
|
+
stack['updated_at'],
|
37
|
+
stack['status']
|
38
|
+
]
|
39
|
+
end
|
40
|
+
|
41
|
+
print_table(
|
42
|
+
build_table(
|
43
|
+
['Name', 'Main stack', 'Updated at', 'Status'],
|
44
|
+
data
|
45
|
+
)
|
40
46
|
)
|
41
|
-
)
|
42
47
|
|
43
|
-
|
44
|
-
|
48
|
+
else
|
49
|
+
api_error(response, false)
|
50
|
+
end
|
45
51
|
end
|
46
|
-
|
47
52
|
end
|
48
53
|
|
49
54
|
method_option :variant, :type => :string, :default => 'default', :desc => "The variant to use, i.e default|scheduled"
|
@@ -58,55 +63,63 @@ module BBC
|
|
58
63
|
|
59
64
|
method_option :variant, :type => :string, :default => 'default', :desc => "The variant to use, i.e default|scheduled"
|
60
65
|
method_option :group, :type => :string, :default => nil, :desc => "The group name to override the component id"
|
66
|
+
method_option :tags, :type => :array, :default => nil, :desc => "The tags of the components you want to deploy (i.e 'renderer')"
|
61
67
|
desc "stack create [COMPONENT, MAIN_STACK = false]", "Generates and create the cloudformation template for the specific component"
|
62
|
-
def create(component, main_stack = false)
|
68
|
+
def create(component = nil, main_stack = 'false')
|
63
69
|
begin
|
64
|
-
|
70
|
+
say "#{banner}\n"
|
65
71
|
|
66
|
-
|
72
|
+
components(options, component).each do |id|
|
73
|
+
say get_key_value("\nComponent", id)
|
67
74
|
|
68
|
-
|
69
|
-
'name_suffix' => options[:stack],
|
70
|
-
'service_stack' => main_stack,
|
71
|
-
'template' => data,
|
72
|
-
'parameters' => Tools::Cloudformation::Generator.parameters(data),
|
73
|
-
}
|
75
|
+
data = cloudformation(id, options, false)
|
74
76
|
|
75
|
-
|
77
|
+
post_data = {
|
78
|
+
'name_suffix' => options[:stack],
|
79
|
+
'service_stack' => main_stack.match(/(true|t|yes|y|1)$/i) != nil,
|
80
|
+
'template' => data,
|
81
|
+
'parameters' => Tools::Cloudformation::Generator.parameters(data),
|
82
|
+
}
|
76
83
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
84
|
+
response = api.post sprintf(config.app['stack_create_endpoint'], options[:env], id), JSON.pretty_generate(post_data)
|
85
|
+
|
86
|
+
if response.success?
|
87
|
+
say "Stack creation for component '#{component}' successfully started", :green
|
88
|
+
else
|
89
|
+
api_error(response, false)
|
90
|
+
end
|
91
|
+
end
|
82
92
|
rescue Exception => e
|
83
|
-
puts e.backtrace
|
84
93
|
error e.message
|
85
94
|
end
|
86
|
-
|
87
95
|
end
|
88
96
|
|
89
97
|
method_option :variant, :type => :string, :default => 'default', :desc => "The variant to use, i.e default|scheduled"
|
90
98
|
method_option :group, :type => :string, :default => nil, :desc => "The group name to override the component id"
|
91
|
-
|
92
|
-
|
99
|
+
method_option :tags, :type => :array, :default => nil, :desc => "The tags of the components you want to deploy (i.e 'renderer')"
|
100
|
+
desc "stack update [COMPONENT = nil]", "Generates and updates the cloudformation template for the specific component"
|
101
|
+
def update(component = nil)
|
93
102
|
|
94
|
-
say "#{banner
|
103
|
+
say "#{banner}\n"
|
95
104
|
|
96
|
-
|
97
|
-
|
105
|
+
components(options, component).each do |id|
|
106
|
+
say get_key_value("\nComponent", id)
|
98
107
|
|
99
|
-
|
100
|
-
|
101
|
-
'parameters' => Tools::Cloudformation::Generator.parameters(data)
|
102
|
-
}
|
108
|
+
stack_name = "#{options[:env]}-#{id}-#{options[:stack]}"
|
109
|
+
data = cloudformation(id, options, false)
|
103
110
|
|
104
|
-
|
111
|
+
post_data = {
|
112
|
+
'template' => data,
|
113
|
+
'parameters' => Tools::Cloudformation::Generator.parameters(data)
|
114
|
+
}
|
105
115
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
116
|
+
response = api.post sprintf(config.app['stack_update_endpoint'], options[:env], id, stack_name), JSON.pretty_generate(post_data)
|
117
|
+
|
118
|
+
if response.success?
|
119
|
+
say "Stack update for component '#{id}' successfully started", :green
|
120
|
+
else
|
121
|
+
api_error(response, false)
|
122
|
+
end
|
110
123
|
end
|
111
124
|
|
112
125
|
end
|
@@ -134,31 +147,36 @@ module BBC
|
|
134
147
|
|
135
148
|
end
|
136
149
|
|
137
|
-
desc "stack events [COMPONENT]", "Shows the stack events for a component"
|
150
|
+
desc "stack events [COMPONENT = nil]", "Shows the stack events for a component"
|
138
151
|
method_option :stack, :type => :string, :default => 'main', :desc => "The name of the stack to use"
|
139
152
|
method_option :limit, :type => :numeric, :default => 5, :desc => "Limit how many records to show"
|
140
|
-
|
153
|
+
method_option :tags, :type => :array, :default => nil, :desc => "The tags of the components you want to deploy (i.e 'renderer')"
|
154
|
+
def events(component = nil)
|
141
155
|
|
142
156
|
say "#{banner}\n"
|
143
157
|
|
144
|
-
|
145
|
-
|
158
|
+
components(options, component).each do |id|
|
159
|
+
say get_key_value("\nComponent", id)
|
146
160
|
|
147
|
-
|
148
|
-
|
161
|
+
stack_name = "#{options[:env]}-#{id}-#{options[:stack]}"
|
162
|
+
response = api.get sprintf(config.app['stack_events'], options[:env], id, stack_name)
|
149
163
|
|
150
|
-
|
151
|
-
|
152
|
-
|
164
|
+
if response.success?
|
165
|
+
events = JSON.parse(response.body)
|
166
|
+
|
167
|
+
data = events.slice(0,(options[:limit])).map do |event|
|
168
|
+
event.split(" ")
|
169
|
+
end
|
153
170
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
171
|
+
print_table(
|
172
|
+
build_table(
|
173
|
+
['Event type', 'CF type', 'Name', 'Status'],
|
174
|
+
data
|
175
|
+
)
|
158
176
|
)
|
159
|
-
|
160
|
-
|
161
|
-
|
177
|
+
else
|
178
|
+
api_error(response, false)
|
179
|
+
end
|
162
180
|
end
|
163
181
|
end
|
164
182
|
|