bbc-cosmos-tools 0.0.7 → 0.1.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/cloudformation/generator.rb +9 -1
- data/lib/bbc/cosmos/tools/commands/base.rb +4 -4
- data/lib/bbc/cosmos/tools/commands/cloud_formation.rb +27 -2
- data/lib/bbc/cosmos/tools/commands/config.rb +1 -1
- data/lib/bbc/cosmos/tools/commands/release.rb +4 -3
- data/lib/bbc/cosmos/tools/commands/stack.rb +61 -22
- 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: 6c25993fa89a80e8a8d885830fa98979a6dd4602
|
4
|
+
data.tar.gz: 577b33a47bca5af332eb92773388b42366e45389
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b46bd3807068a3a989aef79a1f0e6d4d1fe80fbb0472ed52fd6dc4aa17df5c744e0ec827c82d3d5a937a5ba29b0e8ed91c0038425266da0be782efd33fb5093c
|
7
|
+
data.tar.gz: 1aba13524eaed9852a5eeb16d6ee60c522d8c1fa0de64d4d49a1b02780732b6db158f3f27fb45e4557df6a32ad8192214264ead1f64d7494398809bed6f4288e
|
@@ -7,6 +7,14 @@ module BBC
|
|
7
7
|
module Cloudformation
|
8
8
|
class Generator
|
9
9
|
|
10
|
+
def self.component_exists?(component, config)
|
11
|
+
config.resources['cloudformation']['components'][component]
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.stack_exists?(component, config, stack)
|
15
|
+
config.resources['cloudformation']['components'][component][stack]
|
16
|
+
end
|
17
|
+
|
10
18
|
def self.create(component, config, options, to_json = false, &block)
|
11
19
|
|
12
20
|
template = BBC::CfnDsl::CloudFormationTemplate.new
|
@@ -17,7 +25,7 @@ module BBC
|
|
17
25
|
else
|
18
26
|
hash = JSON.parse(template.to_json)
|
19
27
|
|
20
|
-
if config
|
28
|
+
if component_exists?(component, config) && stack_exists?(component, config, options[:stack])
|
21
29
|
config.resources['cloudformation']['components'][component][options[:stack]]['variants'][options[:variant]].each do |key, value|
|
22
30
|
hash['Parameters'][key]['Default'] = value if hash['Parameters'][key]
|
23
31
|
end
|
@@ -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(
|
45
|
-
|
46
|
-
error(
|
44
|
+
def api_error(response)
|
45
|
+
error_message = JSON.parse(response.body)['message']
|
46
|
+
error(error_message)
|
47
47
|
end
|
48
48
|
|
49
49
|
def build_table(headers, data)
|
@@ -71,7 +71,7 @@ module BBC
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def error(message, die = true)
|
74
|
-
say message, :red
|
74
|
+
say "#{message}\n", :red
|
75
75
|
exit 1 if die
|
76
76
|
end
|
77
77
|
|
@@ -44,7 +44,7 @@ module BBC
|
|
44
44
|
if response.success?
|
45
45
|
say "Stack creation for component '#{component}' successfully started", :green
|
46
46
|
else
|
47
|
-
api_error
|
47
|
+
api_error response
|
48
48
|
end
|
49
49
|
|
50
50
|
end
|
@@ -68,11 +68,36 @@ module BBC
|
|
68
68
|
if response.success?
|
69
69
|
say "Stack update for component '#{component}' successfully started", :green
|
70
70
|
else
|
71
|
-
api_error
|
71
|
+
api_error response
|
72
72
|
end
|
73
73
|
|
74
74
|
end
|
75
75
|
|
76
|
+
desc "cf delete [COMPONENT]", "Deletes a stack"
|
77
|
+
def update(component)
|
78
|
+
|
79
|
+
say "#{banner(component)}\n"
|
80
|
+
|
81
|
+
reply = yes?("Are you sure you want to delete the above stack?", :yellow)
|
82
|
+
if reply || reply.nil?
|
83
|
+
|
84
|
+
stack_name = "#{options[:env]}-#{component}-#{options[:stack]}"
|
85
|
+
|
86
|
+
@api = BBC::Cosmos::Tools::Config::API.new(config.app['api'], options[:key_path])
|
87
|
+
response = @api.post sprintf(config.app['stack_delete'], options[:env], component, stack_name), JSON.pretty_generate({})
|
88
|
+
|
89
|
+
if response.success?
|
90
|
+
say "Stack delete for component '#{component}' successfully started", :green
|
91
|
+
else
|
92
|
+
api_error response
|
93
|
+
end
|
94
|
+
else
|
95
|
+
error 'Action cancelled'
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
|
76
101
|
private
|
77
102
|
|
78
103
|
def cloudformation(component, options, to_json = true)
|
@@ -41,7 +41,7 @@ module BBC
|
|
41
41
|
)
|
42
42
|
say "\n"
|
43
43
|
else
|
44
|
-
api_error
|
44
|
+
api_error response
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -62,6 +62,7 @@ module BBC
|
|
62
62
|
component_release = release_id
|
63
63
|
if release_id.nil?
|
64
64
|
response = api.get sprintf(config.app['release'], id)
|
65
|
+
api_error response unless response.success?
|
65
66
|
component_release = JSON.parse(response.body)['releases'].first['version']
|
66
67
|
end
|
67
68
|
|
@@ -77,7 +78,7 @@ module BBC
|
|
77
78
|
say "Deployment started successfully: #{config.app['api']}#{data['url']}\n", :green
|
78
79
|
|
79
80
|
else
|
80
|
-
api_error
|
81
|
+
api_error response
|
81
82
|
end
|
82
83
|
|
83
84
|
end
|
@@ -124,7 +125,7 @@ module BBC
|
|
124
125
|
say "\n"
|
125
126
|
end
|
126
127
|
else
|
127
|
-
api_error
|
128
|
+
api_error response
|
128
129
|
end
|
129
130
|
end
|
130
131
|
|
@@ -20,21 +20,27 @@ module BBC
|
|
20
20
|
say "#{banner}\n"
|
21
21
|
response = api.get sprintf(config.app['stacks'], options[:env], component)
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
if response.success?
|
24
|
+
|
25
|
+
data = JSON.parse(response.body).map do |stack|
|
26
|
+
[
|
27
|
+
stack['name'],
|
28
|
+
stack['main_stack'],
|
29
|
+
stack['updated_at'],
|
30
|
+
stack['status']
|
31
|
+
]
|
32
|
+
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
print_table(
|
35
|
+
build_table(
|
36
|
+
['Name', 'Main stack', 'Updated at', 'Status'],
|
37
|
+
data
|
38
|
+
)
|
36
39
|
)
|
37
|
-
|
40
|
+
|
41
|
+
else
|
42
|
+
api_error response
|
43
|
+
end
|
38
44
|
|
39
45
|
end
|
40
46
|
|
@@ -47,20 +53,53 @@ module BBC
|
|
47
53
|
|
48
54
|
stack_name = "#{options[:env]}-#{component}-#{options[:stack]}"
|
49
55
|
response = api.get sprintf(config.app['stack_events'], options[:env], component, stack_name)
|
50
|
-
events = JSON.parse(response.body)
|
51
56
|
|
52
|
-
|
53
|
-
|
54
|
-
end
|
57
|
+
if response.success?
|
58
|
+
events = JSON.parse(response.body)
|
55
59
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
+
data = events.slice(0,(options[:limit])).map do |event|
|
61
|
+
event.split(" ")
|
62
|
+
end
|
63
|
+
|
64
|
+
print_table(
|
65
|
+
build_table(
|
66
|
+
['Event type', 'CF type', 'Name', 'Status'],
|
67
|
+
data
|
68
|
+
)
|
60
69
|
)
|
61
|
-
|
70
|
+
else
|
71
|
+
api_error response
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
desc "stack delete [COMPONENT]", "Deletes a stack"
|
76
|
+
method_option :stack, :type => :string, :default => 'main', :desc => "The name of the stack to use"
|
77
|
+
def delete(component)
|
78
|
+
|
79
|
+
say "#{banner(component)}\n"
|
80
|
+
|
81
|
+
reply = yes?("Are you sure you want to delete the above stack?", :yellow)
|
82
|
+
if reply || reply.nil?
|
83
|
+
|
84
|
+
stack_name = "#{options[:env]}-#{component}-#{options[:stack]}"
|
85
|
+
|
86
|
+
@api = BBC::Cosmos::Tools::Config::API.new(config.app['api'], options[:key_path])
|
87
|
+
response = @api.post sprintf(config.app['stack_delete'], options[:env], component, stack_name), JSON.pretty_generate({})
|
88
|
+
|
89
|
+
if response.success?
|
90
|
+
say "Stack delete for component '#{component}' successfully started", :green
|
91
|
+
else
|
92
|
+
api_error response
|
93
|
+
end
|
94
|
+
else
|
95
|
+
error 'Action cancelled'
|
96
|
+
end
|
97
|
+
|
62
98
|
end
|
63
99
|
|
100
|
+
|
101
|
+
|
102
|
+
|
64
103
|
end
|
65
104
|
end
|
66
105
|
end
|