bbc-cosmos-tools 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d312899466e33b1d4a65a7335be17846bd070f73
4
- data.tar.gz: f83b250a15485d6d15ae407c4f3e2d11c89d484e
3
+ metadata.gz: 3cb7442d963df4f4ca2d403ba2f37e831616363f
4
+ data.tar.gz: add8398183ee75d4580df67175ee25c7a8835be9
5
5
  SHA512:
6
- metadata.gz: abe8c0da8cdf40c91c63df435b7e858bb304830f73a7ceac96b335b15cdb704328462a959fc35b5c7c55af53465381446211daa91be15cb27575b0fc2631ba9a
7
- data.tar.gz: d1b54bb031dc796f72a6692c491da4a3906a0b926e278f335ff3a2aefeb8714771decd417645f9b627f4f3b6cc8ca6ca2e388c356cd010e1c36dffdef993e27b
6
+ metadata.gz: 9e382b385c6ea1b38fc6a3f58fdf82a9c61650d19401f492f7df9537334006df9cd6bc64b5138a9180932043eae90a4426acd33325e97aab360305e392b61c95
7
+ data.tar.gz: 4f49a41d384d116bb140d5547552c4bace00a66cbd2b95e7533323457cea3b77a1e62a229a078310b2364a357f73be89916b7cb41169fadc2242b37586bb427d
data/README.md CHANGED
@@ -1,105 +1,164 @@
1
1
  # BBC::Cosmos::Tools
2
2
 
3
- This gem provides tooling for interacting with cosmos. Currently it supports the following:
3
+ - [Introduction](#introduction)
4
+ - [Example commands](#example-commands)
5
+ - [Project directory structure](#project-directory-structure)
6
+ - [File structure explained](#file-structure-explained)
7
+ - [Example repositories](#example-repositories)
4
8
 
5
- * Pushing component config to the cosmos API
6
- * Creating stacks for a component in cosmos
7
- * Updating stacks for a component in cosmos
9
+ ## Introduction
10
+
11
+ The [BBC Cosmos Tool](https://github.com/BBC-News/bbc-cosmos-tools) is a Ruby gem that runs on the command line and helps make generating CloudFormation specifically for the BBC Cosmos infrastructure easier.
12
+
13
+ The gem supports the following features:
14
+
15
+ - Pushing component config to the cosmos API
16
+ - Creating stacks for a component in cosmos
17
+ - Updating stacks for a component in cosmos
18
+
19
+ The gem also supports the following formats:
20
+
21
+ - [CFNDSL](https://github.com/stevenjack/cfndsl)
22
+ - YAML
23
+ - JSON
8
24
 
9
25
  ## Installation
10
26
 
11
27
  Add this line to your application's Gemfile:
12
28
 
13
- gem 'bbc-cosmos-tools'
29
+ ```
30
+ gem 'bbc-cosmos-tools'
31
+ ```
14
32
 
15
33
  And then execute:
16
34
 
17
- $ bundle
35
+ ```
36
+ $ bundle
37
+ ```
18
38
 
19
39
  Or install it yourself as:
20
40
 
21
- $ gem install bbc-cosmos-tools
41
+ ```
42
+ $ gem install bbc-cosmos-tools
43
+ ```
22
44
 
23
- ## Usage
45
+ ## Project directory structure
24
46
 
25
- The gem expects a certain folder structure for the config files:
47
+ The cli tool needs to be used inside a project that has a specific directory structure. This structure looks something like the following (if using CFNDSL):
26
48
 
27
- #### Folder structure
49
+ ```
50
+ .
51
+ ├── configs
52
+ │   ├── app.yaml
53
+ │   └── {component}.yaml.erb
54
+ ├── resources
55
+ │   ├── int
56
+ │   │   └── {component}.yaml
57
+ │   ├── live
58
+ │   │   └── {component}.yaml
59
+ │   └── test
60
+ │   │   └── {component}.yaml
61
+ └── stacks
62
+ └── {component}
63
+ └── {stack}
64
+ ├── aws
65
+ │   ├── {resource}
66
+ │   ├── {type}.rb
67
+ │   └── {resource}
68
+ │   ├── {type}.rb
69
+ └── template.rb
70
+ ```
28
71
 
29
- ```bash
30
- ├── configs
31
- │ ├── {project name}.yaml.erb
32
- │ ├── app.yam
33
- ├── resources
34
- │ ├── {int/test/stage/live}
35
- │ │ ├── {project-name}.yaml
36
- ├── stacks
37
- │ ├── {component id/group_id}
38
- │ │ ├── {stack name}
39
- │ │ │ ├── aws {CFNDSL templates}
40
- │ │ │ ├── template.rb
72
+ Where by the `{x}` items equate to the following:
73
+
74
+ - `{component}`
75
+ The name of your Cosmos component (e.g. `responsive-jmeter`)
76
+
77
+ - `{stack}`
78
+ Typically this will be `main` (as there *must* always be a `main` stack)
79
+ But be aware you can have multiple "stacks" for a component (it's just a structural convenience)
80
+
81
+ - `{resource}`
82
+ This could be (for example) a Scaling Group, IAM policy, SQS, or DynamoDB (any AWS service)
83
+
84
+ - `{type}`
85
+ This is a sub section of the resource
86
+ e.g. if the resource was `AWS::SQS::Queue` then this file would be named `queue.rb`
87
+
88
+ > Note: if you're using the YAML or JSON formats then the following structure is used (notice it's *almost* identical)
89
+
90
+ ```
91
+ .
92
+ ├── configs
93
+ │   ├── app.yaml
94
+ │   └── {component}.yaml.erb
95
+ ├── resources
96
+ │   ├── int
97
+ │   │   └── {component}.yaml
98
+ │   ├── live
99
+ │   │   └── {component}.yaml
100
+ │   └── test
101
+ │   │   └── {component}.yaml
102
+ └── stacks
103
+ └── {component}
104
+ └── {stack}.{yaml|json}
41
105
  ```
42
106
 
43
- an example of this would be:
107
+ ## File structure explained
44
108
 
45
- ```bash
46
- ├── configs
47
- │ ├── my_project.yaml.erb
48
- │ ├── app.yam
49
- ├── resources
50
- │ ├── int
51
- │ │ ├── my_project.yaml
52
- ├── stacks
53
- │ ├── my_wicked_component
54
- │ │ ├── main
55
- │ │ │ ├── aws
56
- │ │ │ │ ├── auto_scaling
57
- │ │ │ │ │ ├── group.rb
58
- │ │ │ │ │ ├── launch_config.rb
59
- │ │ │ ├── template.rb
60
- ```
61
-
62
- #### Project resources structure
109
+ The file structure required by the BBC Cosmos CLI Tool can be confusing so let’s break it down into sections so we can better understand the purpose of each directory:
63
110
 
64
- The project resources yaml file is used to describe the resources used within the project. The reason for having a single file is that you can define resources that are used in the cloudformation templates and config, so when for example an ARN changes this will be picked up across the CF templates and the config.
111
+ ### Config
65
112
 
66
- The file is spilt up into two section:
113
+ The files in this folder let you define custom configuration that will be baked into your EC2 instances.
67
114
 
68
- * The standard resource list, this is generally the ARNS for all the resources your component uses.
69
- * Cloudformation parameters (These are usually referenced from the aforementioned)
115
+ You need to use the `bbc-cosmos-tools config push` command to upload the updated configuration data (run the help command `bbc-cosmos-tools help config push` to see more options and details).
70
116
 
71
- Below is an annotated example of a resource config:
117
+ The content of this folder is usually:
118
+
119
+ - `app.yaml` (defaults)
120
+ - `{component}.yaml.erb` (custom)
121
+
122
+ So the contents of `app.yaml` can look like the following:
72
123
 
73
124
  ```yaml
125
+ bbc:
126
+ cosmos:
127
+ api: 'https://api.live.bbc.co.uk'
128
+ config_endpoint: '/cosmos/env/%s/component/%s/configuration'
129
+ stack_create_endpoint: '/cosmos/env/%s/component/%s/stacks/create'
130
+ stack_update_endpoint: '/cosmos/env/%s/component/%s/stack/%s/update'
131
+ deployments: '/cosmos/deployments/component/%s/env/%s'
132
+ release: '/cosmos/component/%s/releases'
133
+ deploy: '/cosmos/env/%s/component/%s/deploy_release'
134
+ snapshot_deploy: '/cosmos/env/%s/component/%s/deploy_snapshot'
135
+ stack_events: '/cosmos/env/%s/component/%s/stack/%s/events'
136
+ stacks: '/cosmos/env/%s/component/%s/stacks'
137
+ stack_delete: '/cosmos/env/%s/component/%s/stack/%s/delete'
138
+ ```
74
139
 
75
- sequencer:
76
- name: 'example_name'
77
- arn: 'example_arn'
140
+ Where as the contents of `{component}.yaml.erb` can look like the following:
78
141
 
79
- roles:
80
- broker:
81
- name: &roles_broker_name 'some_iam_role_name'
142
+ ```erb
143
+ components:
144
+ '{component}':
145
+ s3_bucket_id: "foo"
146
+ s3_bucket_path: "bar"
147
+ ```
82
148
 
83
- cloudformation:
84
- shared: &component_shared #<- This node is ignored, it's used as a base for other config templates
85
- ACFParameter: 'Value'
86
- AnotherCFParameter: 'Another value'
149
+ In YAML you can get fancy and make certain properties more re-usable by using `&` to create an "anchor" which you can then reference with `*`, along with `<<:` to inject content. See the following file for an example (although it’s not a very good example as there would be no need to use any of those features for such a small file, but hopefully it gives you an idea on how they are used)…
87
150
 
88
- components:
89
- 'my-example-component': #<- The name of the component in cosmos
90
- main: <- This is the name of the stack in cosmos
91
- variants: <- This is so you can have a different variant of the same config, i.e for int/test one for durning the day and one for evening/weekends.
92
- default: &my-example-component_default #<- We set this anchor so we can use this defaults in other variants
93
- <<: *component_shared #<- We import the shared component params into these so we're not duplicating
94
- ARoleParamForDefault: *roles_broker_name #<- We use the anchor for the roles set above to add them here, again stopping repitition
95
- scheduled:
96
- <<: *my-example-component_default
97
- MinSize: 0
98
- MaxSize: 0
99
-
151
+ ```erb
152
+ base: &shared
153
+ s3_bucket_id: "foo"
154
+ s3_object_path: "bar"
155
+
156
+ components:
157
+ 'responsive-jmeter':
158
+ <<: *shared
100
159
  ```
101
-
102
- #### Project Config structure
160
+
161
+ #### Using CFNDSL
103
162
 
104
163
  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:
105
164
 
@@ -131,7 +190,7 @@ the component config merged in afterwards.
131
190
  #### Application config
132
191
 
133
192
  There's also an application config that stores data used by the app, at the moment this
134
- is only the api endpoints.
193
+ is only the API endpoints.
135
194
 
136
195
  ```yaml
137
196
  bbc:
@@ -141,7 +200,151 @@ bbc:
141
200
  update_endpoint: "/some/restful/endpoint"
142
201
  ```
143
202
 
144
- The gem is a cli application, the commands are self documenting but below is a list of the commands for each set of sub commands
203
+ ### Resources
204
+
205
+ The resources directory is used to provide custom values to the `Parameters` defined within your stacks (see the Stacks directory below). There is usually three folders inside this directory that reflect the Cosmos environments:
206
+
207
+ - `int`
208
+ - `test`
209
+ - `live`
210
+
211
+ Each of those folders will have a `{component}.yaml` file where you define the values for your Parameters (if you were using AWS directly, rather than via the Cosmos abstraction layer, then this is typically where you would specify the custom values either using the AWS CLI tool or by entering the values into form fields when using the AWS Console GUI).
212
+
213
+ The format of this file looks something like the following:
214
+
215
+ ```yaml
216
+ cloudformation:
217
+ components:
218
+ '{component_folder_name}':
219
+ {stack}:
220
+ variants:
221
+ default:
222
+ {parameter_a}: value
223
+ {parameter_b}: value
224
+ {parameter_c}: value
225
+
226
+ ```
227
+
228
+ #### Using CFNDSL
229
+
230
+ The project resources yaml file is used to describe the resources used within the project. The reason for having a single file is that you can define resources that are used in the cloudformation templates and config, so when for example an ARN changes this will be picked up across the CF templates and the config.
231
+
232
+ The file is spilt up into two section:
233
+
234
+ * The standard resource list, this is generally the ARNS for all the resources your component uses.
235
+ * Cloudformation parameters (These are usually referenced from the aforementioned)
236
+
237
+ Below is an annotated example of a resource config:
238
+
239
+ ```yaml
240
+
241
+ sequencer:
242
+ name: 'example_name'
243
+ arn: 'example_arn'
244
+
245
+ roles:
246
+ broker:
247
+ name: &roles_broker_name 'some_iam_role_name'
248
+
249
+ cloudformation:
250
+ shared: &component_shared #<- This node is ignored, it's used as a base for other config templates
251
+ ACFParameter: 'Value'
252
+ AnotherCFParameter: 'Another value'
253
+
254
+ components:
255
+ 'my-example-component': #<- The name of the component in cosmos
256
+ main: <- This is the name of the stack in cosmos
257
+ variants: <- This is so you can have a different variant of the same config, i.e for int/test one for durning the day and one for evening/weekends.
258
+ default: &my-example-component_default #<- We set this anchor so we can use this defaults in other variants
259
+ <<: *component_shared #<- We import the shared component params into these so we're not duplicating
260
+ ARoleParamForDefault: *roles_broker_name #<- We use the anchor for the roles set above to add them here, again stopping repitition
261
+ scheduled:
262
+ <<: *my-example-component_default
263
+ MinSize: 0
264
+ MaxSize: 0
265
+
266
+ ```
267
+
268
+ ### Stacks
269
+
270
+ The stacks directory is the most important part of the configuration as it defines your infrastructure requirements (i.e. creates all the specified AWS resources as you’ve defined them using CloudFormation).
271
+
272
+ The folder structure resembles the following:
273
+
274
+ ```
275
+ .
276
+ ├── stacks
277
+ └── {component}
278
+ └── {stack}
279
+ ├── aws
280
+ │   ├── {resource}
281
+ │   │   ├── {type}
282
+ ```
283
+
284
+ An example of this could be:
285
+
286
+ ```
287
+ .
288
+ ├── stacks
289
+ └── responsive-jmeter
290
+ └── main
291
+ ├── aws
292
+ │   ├── sqs
293
+ │   │   ├── policy.rb
294
+ │   │   ├── queue.rb
295
+ │   ├── iam
296
+ │   │   ├── instance_profile.rb
297
+ ```
298
+
299
+ > Note: when opening up the files `policy.rb` and `queue.rb` we’ll see the `Type` syntax and that should correspond to the folder structure described above. So aws/sqs/policy.rb will have a `Type "AWS::SQS::QueuePolicy”`, and aws/iam/instance_profile.rb will have a `Type "AWS::IAM::InstanceProfile”`
300
+
301
+ ## Example commands
302
+
303
+ When you want to push up some new configuration into your instance (for your application to use) then the following command is what you need (this isn't done very often):
304
+
305
+ ```sh
306
+ bbc-cosmos-tools config push {cosmos_component_name} \
307
+ --project={resources yaml filename} \
308
+ --key-path=/custom/path/to/your/pem/certificate
309
+ ```
310
+
311
+ To update your stack:
312
+
313
+ ```sh
314
+ bbc-cosmos-tools stack update {cosmos_component_name} \
315
+ --project={resources yaml filename} \
316
+ --key-path=/custom/path/to/your/pem/certificate
317
+ ```
318
+
319
+ To generate CloudFormation that is sent to `stdout`:
320
+
321
+ ```sh
322
+ bbc-cosmos-tools stack generate {cosmos_component_name} \
323
+ --project={resources yaml filename} \
324
+ --key-path=/custom/path/to/your/pem/certificate
325
+ ```
326
+
327
+ > Note: in case you're not a CLI wizard, instead of specifying the `--key-path` option you can set a `$DEV_CERT_PATH` environment variable that the tool uses by default if it detects it. Inside your shell's configuration file (either `~/.bashrc` or `~/.zshrc`) you'll want to add `export DEV_CERT_PATH=/custom/path/to/your/pem/certificate`
328
+
329
+ ### Using YAML or JSON
330
+
331
+ Use the same commands as above but make sure to include a `--type={yaml|json}`. If it's not specified then `cfndsl` is assumed as the default (almost as if you had written `--type=cfndsl`, but it's clearer to just remove the flag in that instance).
332
+
333
+ ## Example repositories
334
+
335
+ There are a few example projects using this tool now:
336
+
337
+ - [Election Data Config](https://github.com/BBC-News/election-data-config)
338
+ - [Jmeter Config](https://github.com/BBC-News/jmeter-configs)
339
+ - [Kaleidoscope Config](https://github.com/BBC-News/kaleidoscope-config)
340
+
341
+ > Note: it's important to realise that you don't *need* to have your configuration in a separate repository. If anything it probably would be better maintained as part of your application repository (placed inside a `/config/` directory)
342
+
343
+ > The reason some of the projects choose to locate their configuration in a separate repo is because they're made up of a number of different components.
344
+
345
+ ## API reference
346
+
347
+ The gem is a cli application, and so the commands are self documenting; but below is a list of the commands for each set of sub commands
145
348
 
146
349
  ### Cosmos Config
147
350
 
@@ -163,10 +366,10 @@ bbc-cosmos-tools cf update
163
366
 
164
367
  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 stack` and this would display the following output:
165
368
 
166
- ```sh
369
+ ```bash
167
370
  Commands:
168
371
  bbc-cosmos-tools stack help [COMMAND] # Describe subcommands or one specific subco...
169
- bbc-cosmos-tools stack create [COMPONENT, MAIN_STACK = false] # Generates and create the cloudformation te...
372
+ bbc-cosmos-tools stack create [COMPONENT, MAIN_STACK = true] # Generates and create the cloudformation te...
170
373
  bbc-cosmos-tools stack delete [COMPONENT] # Deletes a stack
171
374
  bbc-cosmos-tools stack events [COMPONENT = nil] # Shows the stack events for a component
172
375
  bbc-cosmos-tools stack generate [COMPONENT] # Generates a cloudformation template based ...
@@ -69,10 +69,7 @@ module BBC
69
69
  say "#{banner(component)}\n"
70
70
 
71
71
  type = Tools::Types::Factory.create(component, options, config)
72
- data = type.generate_data.tap do |d|
73
- @l.(d, component, options[:env])
74
- end
75
-
72
+ data = type.generate_data
76
73
  say data, :white
77
74
 
78
75
  end
@@ -80,8 +77,8 @@ module BBC
80
77
  method_option :variant, :type => :string, :default => 'default', :desc => "The variant to use, i.e default|scheduled"
81
78
  method_option :group, :type => :string, :default => nil, :desc => "The group name to override the component id"
82
79
  method_option :tags, :type => :array, :default => nil, :desc => "The tags of the components you want to deploy (i.e 'renderer')"
83
- desc "stack create [COMPONENT, MAIN_STACK = false]", "Generates and create the cloudformation template for the specific component"
84
- def create(component = nil, main_stack = 'false')
80
+ desc "stack create [COMPONENT, MAIN_STACK = true]", "Generates and create the cloudformation template for the specific component"
81
+ def create(component = nil, main_stack = 'true')
85
82
  begin
86
83
  say "#{banner}\n"
87
84
 
@@ -89,10 +86,7 @@ module BBC
89
86
  say get_key_value("\nComponent", id)
90
87
 
91
88
  type = Tools::Types::Factory.create(id, options, config)
92
- data = type.generate_data.tap do |d|
93
- @l.(d, id, options[:env])
94
- end
95
-
89
+ data = type.generate_data
96
90
  post_data = {
97
91
  'name_suffix' => options[:stack],
98
92
  'service_stack' => main_stack.match(/(true|t|yes|y|1)$/i) != nil,
@@ -1,7 +1,7 @@
1
1
  module BBC
2
2
  module Cosmos
3
3
  module Tools
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.1"
5
5
  end
6
6
  end
7
7
  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.4.0
4
+ version: 0.4.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: 2014-09-24 00:00:00.000000000 Z
11
+ date: 2014-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler