bbc-cosmos-tools 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +83 -2
- data/bbc-cosmos-tools.gemspec +2 -0
- data/lib/bbc/cosmos/tools/commands/component.rb +5 -1
- data/lib/bbc/cosmos/tools/commands/config.rb +3 -3
- data/lib/bbc/cosmos/tools/commands/release.rb +3 -3
- data/lib/bbc/cosmos/tools/commands/stack.rb +53 -6
- data/lib/bbc/cosmos/tools/cosmos_configuration.rb +14 -1
- data/lib/bbc/cosmos/tools/version.rb +1 -1
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24f317d2a990335a077f7b7721b2111527ed6a0d
|
4
|
+
data.tar.gz: 62d85ae9ee1ef88e4b58467266bce0584ab34408
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 091548ded09eb18f11c45b2005a34a963f1674b16370455c795617be2c97e15bf06adbb9f12955f0b54c5c101b32a4b739e15df01760b7e97d40d2241a0de883
|
7
|
+
data.tar.gz: 05d0c3c58121c36278159e2c57cd9b426f5caa757240e208ebf5b9194d46c60e56b39c30d0bc1c595e0c4e70b77d14f87855975149acc251e0dbfa8b7032c010
|
data/README.md
CHANGED
@@ -159,6 +159,7 @@ bbc:
|
|
159
159
|
stacks: '/cosmos/env/%s/component/%s/stacks'
|
160
160
|
stack_delete: '/cosmos/env/%s/component/%s/stack/%s/delete'
|
161
161
|
stack_details: '/cosmos/env/%s/component/%s/stack/%s'
|
162
|
+
stack_template: '/cosmos/env/%s/component/%s/stack/%s/template'
|
162
163
|
```
|
163
164
|
|
164
165
|
> Note: `stack_details` is needed for when a stack update happens. As we don't have all the config values that Cosmos should automatically add in for us when it's created, we need to get them from Cosmos and add them to the parameter list when doing the update
|
@@ -187,6 +188,22 @@ components:
|
|
187
188
|
<<: *shared
|
188
189
|
```
|
189
190
|
|
191
|
+
##### Secure values
|
192
|
+
|
193
|
+
The cosmos API allows you to mark certain values as "secure" when adding them to the API. This means that when hitting the config REST endpoint, anything marked as secure won't show. It'll only be available when it's baked onto the instance. This is useful for stuff like API keys etc where you don't want everyone with a dev cert being able to see/use it.
|
194
|
+
|
195
|
+
To use this you need to have the following structure for a key in your config:
|
196
|
+
|
197
|
+
```yaml
|
198
|
+
components:
|
199
|
+
my_component:
|
200
|
+
api_key:
|
201
|
+
secure: true
|
202
|
+
value: "SUPER_SECRET_KEY"
|
203
|
+
foo: bar
|
204
|
+
bar: qux
|
205
|
+
```
|
206
|
+
|
190
207
|
#### Using CFNDSL
|
191
208
|
|
192
209
|
The project config is an ERB template that is renderer into a YAML file. it gets passed all resources from the resource config that can be used in the template. Below is an example of this:
|
@@ -251,7 +268,7 @@ cloudformation:
|
|
251
268
|
{parameter_a}: value
|
252
269
|
{parameter_b}: value
|
253
270
|
{parameter_c}: value
|
254
|
-
|
271
|
+
|
255
272
|
```
|
256
273
|
|
257
274
|
#### Using CFNDSL
|
@@ -378,7 +395,7 @@ There are a few example projects using this tool now:
|
|
378
395
|
|
379
396
|
### Help?
|
380
397
|
|
381
|
-
You can use the built-in `help` command to see a list of parameters and options that need to be passed into the command you wish to execute. For example, if we were unsure of the options for the `stack` command then we would execute `bbc-cosmos-tools help
|
398
|
+
You can use the built-in `help` command to see a list of parameters and options that need to be passed into the command you wish to execute. For example, if we were unsure of the options for the `stack` command then we would execute `bbc-cosmos-tools stack help` and this would display the following output:
|
382
399
|
|
383
400
|
```bash
|
384
401
|
Commands:
|
@@ -391,6 +408,70 @@ Commands:
|
|
391
408
|
bbc-cosmos-tools stack update [COMPONENT = nil] # Generates and updates the cloudformation t...
|
392
409
|
```
|
393
410
|
|
411
|
+
### SSH
|
412
|
+
|
413
|
+
You can SSH into an instance quickly by calling the component ssh command such as:
|
414
|
+
|
415
|
+
```bash
|
416
|
+
bbc-cosmos-tools component ssh news-javelin --env=live
|
417
|
+
|
418
|
+
Your IP for i-38c96895 is 10.0.233.46
|
419
|
+
```
|
420
|
+
|
421
|
+
If there are multiple instances for a component, a list will be provided to let you chose an instance ID:
|
422
|
+
|
423
|
+
```bash
|
424
|
+
bbc-cosmos-tools component ssh news-jenkins-agent --env=live
|
425
|
+
|
426
|
+
Multiple instances detected, please select one
|
427
|
+
1. i-67ad08ca
|
428
|
+
2. i-be8e9814
|
429
|
+
? 1 ### Selection
|
430
|
+
|
431
|
+
Creating Session
|
432
|
+
Creating Session
|
433
|
+
Creating Session
|
434
|
+
Creating Session
|
435
|
+
|
436
|
+
Your IP for i-67ad08ca is 10.0.234.217
|
437
|
+
```
|
438
|
+
### Other Commands
|
439
|
+
|
440
|
+
List Instances
|
441
|
+
```bash
|
442
|
+
bbc-cosmos-tools component instances news-javelin --env=live
|
443
|
+
|
444
|
+
Instance ID
|
445
|
+
i-38c96895
|
446
|
+
```
|
447
|
+
|
448
|
+
List Releases
|
449
|
+
```bash
|
450
|
+
bbc-cosmos-tools release list news-javelin
|
451
|
+
|
452
|
+
Component: news-javelin
|
453
|
+
Version Created at
|
454
|
+
0.1.6-1.el6 2015-06-30T16:10:54+01:00
|
455
|
+
```
|
456
|
+
|
457
|
+
List Deployed Releases
|
458
|
+
```bash
|
459
|
+
bbc-cosmos-tools release deployed news-javelin --env=live
|
460
|
+
|
461
|
+
Component: news-javelin
|
462
|
+
Release Deployed at Deployment id Deployed by Status
|
463
|
+
0.1.83-1.el6 2015-07-16T15:39:59+01:00 282759 PlatformToolsTeam@bbc.co.uk done
|
464
|
+
```
|
465
|
+
|
466
|
+
Redeploy a Component
|
467
|
+
```bash
|
468
|
+
bbc-cosmos-tools release redeploy news-release --env=int
|
469
|
+
|
470
|
+
news-release successfully redeployed
|
471
|
+
View deployment of news-release here https://admin.live.bbc.co.uk/cosmos/env/int/deployment/286431
|
472
|
+
```
|
473
|
+
|
474
|
+
|
394
475
|
## Contributing
|
395
476
|
|
396
477
|
1. Fork it
|
data/bbc-cosmos-tools.gemspec
CHANGED
@@ -17,7 +17,11 @@ module BBC
|
|
17
17
|
|
18
18
|
tag = options[:show_tag]
|
19
19
|
|
20
|
-
rows = instance_ids(component).map do |id|
|
20
|
+
rows = instance_ids(component).each_with_index.map do |id, i|
|
21
|
+
meta = make_request("env/#{options[:env]}/component/#{component}/instances")
|
22
|
+
ip = meta[i]["private_ip_address"]
|
23
|
+
id = "#{id} (#{ip})"
|
24
|
+
|
21
25
|
[id].tap do |row|
|
22
26
|
row << ec2.instances[id].tags[tag] if tag
|
23
27
|
end
|
@@ -16,7 +16,7 @@ module BBC
|
|
16
16
|
@cosmos_config = BBC::Cosmos::Tools::CosmosConfiguration.new(config)
|
17
17
|
end
|
18
18
|
|
19
|
-
desc "
|
19
|
+
desc "generate [COMPONENT]", "Generates config for the given component optionally in the cosmos format"
|
20
20
|
method_option :output, :type => :string, :desc => "Output type", :default => "normal"
|
21
21
|
method_option :write, :type => :boolean, :desc => "write output to file", :default => false
|
22
22
|
method_option :cosmos_format, :type => :boolean, :desc => "Toogles if the output should be in the cosmos format"
|
@@ -47,7 +47,7 @@ module BBC
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
desc "
|
50
|
+
desc "list", "Lists all components for a given project"
|
51
51
|
method_option :output, :type => :string, :desc => "Output type", :default => "normal"
|
52
52
|
def list
|
53
53
|
if options[:output] == "machine"
|
@@ -71,7 +71,7 @@ module BBC
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
desc "
|
74
|
+
desc "push [COMPONENT_ID = nil]", "Push config for a component to the cosmos API"
|
75
75
|
method_option :force, :type => :boolean, :desc => "This skips asking of you want to push the changes"
|
76
76
|
def push(component_id = nil)
|
77
77
|
components = component_id.nil? ? cosmos_config.component_keys : [component_id]
|
@@ -34,7 +34,7 @@ module BBC
|
|
34
34
|
end
|
35
35
|
|
36
36
|
method_option :tags, :type => :array, :default => nil
|
37
|
-
desc "
|
37
|
+
desc "list [COMPONENT = nil]", "Lists releases for a component"
|
38
38
|
def list(component = nil)
|
39
39
|
say banner
|
40
40
|
|
@@ -61,7 +61,7 @@ module BBC
|
|
61
61
|
error e.message
|
62
62
|
end
|
63
63
|
|
64
|
-
desc "
|
64
|
+
desc "deploy [COMPONENT = nil, RELEASE_ID = nil]", "Deploys a release to the specific enironment"
|
65
65
|
method_option :tags, :type => :array, :default => nil, :desc => "The tags of the components you want to deploy (i.e 'renderer')"
|
66
66
|
method_option :from, :type => :string, :default => "release", :desc => "The location that the deployment shold be taken from (release|int|test)"
|
67
67
|
def deploy(component = nil, release_id = nil)
|
@@ -125,7 +125,7 @@ module BBC
|
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
-
desc "
|
128
|
+
desc "deployed [COMPONENT = nil]", "Lists releases deloyed for a component in the specified environment"
|
129
129
|
method_option :tags, :type => :array, :default => nil, :desc => "The tags of the components you want to deploy (i.e 'renderer')"
|
130
130
|
def deployed(component = nil)
|
131
131
|
say banner
|
@@ -3,6 +3,8 @@ require "bbc/cosmos/tools/config"
|
|
3
3
|
require "bbc/cosmos/tools/commands/base"
|
4
4
|
require "bbc/cosmos/tools/cloudformation/generator"
|
5
5
|
require "bbc/cosmos/tools/types/factory"
|
6
|
+
require "easy_diff"
|
7
|
+
require "ansi/code"
|
6
8
|
|
7
9
|
module BBC
|
8
10
|
module Cosmos
|
@@ -26,7 +28,7 @@ module BBC
|
|
26
28
|
@api = BBC::Cosmos::Tools::API.new(config.app["api"], options[:key_path])
|
27
29
|
end
|
28
30
|
|
29
|
-
desc "
|
31
|
+
desc "list [COMPONENT = nil]", "Lists stacks for a component"
|
30
32
|
method_option :tags, :type => :array, :default => nil, :desc => "The tags of the components you want to deploy (i.e 'renderer')"
|
31
33
|
def list(component = nil)
|
32
34
|
say "#{banner}\n"
|
@@ -61,7 +63,7 @@ module BBC
|
|
61
63
|
|
62
64
|
method_option :variant, :type => :string, :default => "default", :desc => "The variant to use, i.e default|scheduled"
|
63
65
|
method_option :group, :type => :string, :default => nil, :desc => "The group name to override the component id"
|
64
|
-
desc "
|
66
|
+
desc "generate [COMPONENT]", "Generates a cloudformation template based on a type of component, the identifier and the environment"
|
65
67
|
def generate(component)
|
66
68
|
say "#{banner(component)}\n"
|
67
69
|
|
@@ -73,7 +75,7 @@ module BBC
|
|
73
75
|
method_option :variant, :type => :string, :default => "default", :desc => "The variant to use, i.e default|scheduled"
|
74
76
|
method_option :group, :type => :string, :default => nil, :desc => "The group name to override the component id"
|
75
77
|
method_option :tags, :type => :array, :default => nil, :desc => "The tags of the components you want to deploy (i.e 'renderer')"
|
76
|
-
desc "
|
78
|
+
desc "create [COMPONENT, MAIN_STACK = true]", "Generates and create the cloudformation template for the specific component"
|
77
79
|
def create(component = nil, main_stack = "true")
|
78
80
|
say "#{banner}\n"
|
79
81
|
|
@@ -107,7 +109,7 @@ module BBC
|
|
107
109
|
method_option :variant, :type => :string, :default => "default", :desc => "The variant to use, i.e default|scheduled"
|
108
110
|
method_option :group, :type => :string, :default => nil, :desc => "The group name to override the component id"
|
109
111
|
method_option :tags, :type => :array, :default => nil, :desc => "The tags of the components you want to deploy (i.e 'renderer')"
|
110
|
-
desc "
|
112
|
+
desc "update [COMPONENT = nil]", "Generates and updates the cloudformation template for the specific component"
|
111
113
|
def update(component = nil)
|
112
114
|
say "#{banner}\n"
|
113
115
|
|
@@ -147,7 +149,52 @@ module BBC
|
|
147
149
|
end
|
148
150
|
end
|
149
151
|
|
150
|
-
|
152
|
+
method_option :variant, :type => :string, :default => "default", :desc => "The variant to use, i.e default|scheduled"
|
153
|
+
method_option :group, :type => :string, :default => nil, :desc => "The group name to override the component id"
|
154
|
+
method_option :tags, :type => :array, :default => nil, :desc => "The tags of the components you want to deploy (i.e 'renderer')"
|
155
|
+
desc "stack diff [COMPONENT = nil]", "Diffs the locally generated cloudformation template with that in cosmos"
|
156
|
+
def diff(component = nil)
|
157
|
+
components(options, component).each do |id|
|
158
|
+
stack_name = "#{options[:env]}-#{id}-#{options[:stack]}"
|
159
|
+
response = api.get sprintf(config.app["stack_template"], options[:env], id, stack_name)
|
160
|
+
|
161
|
+
### Copy-pasted: extract this logic out
|
162
|
+
type = Tools::Types::Factory.create(id, options, config)
|
163
|
+
data = type.generate_data.tap do |d|
|
164
|
+
@l.call(d, id, options[:env])
|
165
|
+
end
|
166
|
+
|
167
|
+
stack_meta = stack_data(component, stack_name, options[:env])
|
168
|
+
|
169
|
+
if data["Parameters"]
|
170
|
+
data["Parameters"] = deep_merge(
|
171
|
+
stack_parameters(stack_meta["parameters"], data["Parameters"]),
|
172
|
+
data["Parameters"]
|
173
|
+
)
|
174
|
+
|
175
|
+
params = Tools::Cloudformation::Generator.parameters(data, false)
|
176
|
+
end
|
177
|
+
|
178
|
+
post_data = {
|
179
|
+
"template" => data,
|
180
|
+
"parameters" => params || {}
|
181
|
+
}
|
182
|
+
###
|
183
|
+
|
184
|
+
if response.success?
|
185
|
+
original_template = JSON.parse(response.body)
|
186
|
+
|
187
|
+
removed, added = original_template.easy_diff(data)
|
188
|
+
|
189
|
+
say JSON.pretty_generate(removed), :red
|
190
|
+
say JSON.pretty_generate(added), :green
|
191
|
+
else
|
192
|
+
api_error(response, false)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
desc "delete [COMPONENT]", "Deletes a stack"
|
151
198
|
def delete(component)
|
152
199
|
say "#{banner(component)}\n"
|
153
200
|
|
@@ -168,7 +215,7 @@ module BBC
|
|
168
215
|
end
|
169
216
|
end
|
170
217
|
|
171
|
-
desc "
|
218
|
+
desc "events [COMPONENT = nil]", "Shows the stack events for a component"
|
172
219
|
method_option :stack, :type => :string, :default => "main", :desc => "The name of the stack to use"
|
173
220
|
method_option :limit, :type => :numeric, :default => 5, :desc => "Limit how many records to show"
|
174
221
|
method_option :tags, :type => :array, :default => nil, :desc => "The tags of the components you want to deploy (i.e 'renderer')"
|
@@ -23,9 +23,22 @@ module BBC
|
|
23
23
|
|
24
24
|
def cosmos_component(id)
|
25
25
|
component(id).reduce([]) do |object, (key, value)|
|
26
|
-
object.tap
|
26
|
+
object.tap do |o|
|
27
|
+
o << {
|
28
|
+
:value => secure_key?(value) ? value["value"] : value,
|
29
|
+
:key => key,
|
30
|
+
:secure => secure_key?(value)
|
31
|
+
}
|
32
|
+
end
|
27
33
|
end
|
28
34
|
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def secure_key?(value)
|
39
|
+
value.is_a?(Hash) && value["secure"]
|
40
|
+
end
|
41
|
+
|
29
42
|
end
|
30
43
|
end
|
31
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bbc-cosmos-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Jack
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,6 +108,34 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: easy_diff
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: ansi
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
111
139
|
description: Tool for interacting with BBC Cosmos platform
|
112
140
|
email:
|
113
141
|
- stevenmajack@gmail.com
|