rubycfn 0.4.10 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -1
  3. data/Gemfile.lock +1 -1
  4. data/README.md +43 -67
  5. data/bin/rubycfn +17 -73
  6. data/lib/cli_methods.rb +2 -2
  7. data/lib/rubycfn/version.rb +1 -1
  8. data/templates/.env +2 -0
  9. data/templates/.env.acceptance +1 -0
  10. data/templates/.env.dependencies.rspec +6 -0
  11. data/templates/.env.development +1 -0
  12. data/templates/.env.production +1 -0
  13. data/templates/.env.rspec +1 -0
  14. data/templates/.env.test +1 -0
  15. data/templates/{.gitignore.erb → .gitignore} +3 -0
  16. data/templates/{.rubocop.yml.erb → .rubocop.yml} +14 -1
  17. data/templates/{Gemfile.erb → Gemfile} +0 -1
  18. data/templates/README.md +57 -0
  19. data/templates/{Rakefile.erb → Rakefile} +15 -8
  20. data/templates/bootstrap/dependency_stack.rb +49 -0
  21. data/templates/config.yaml +65 -0
  22. data/templates/lib/aws_helper/aws_sdk.rb +30 -0
  23. data/templates/{compiler.rb.erb → lib/aws_helper/compiler.rb} +15 -9
  24. data/templates/{dependencies.rb.erb → lib/aws_helper/dependencies.rb} +5 -3
  25. data/templates/{deploy.rb.erb → lib/aws_helper/deploy.rb} +6 -4
  26. data/templates/lib/aws_helper/helpers.rb +3 -0
  27. data/templates/{main_aws_helper.rb.erb → lib/aws_helper/main.rb} +0 -0
  28. data/templates/{upload_stack.rb.erb → lib/aws_helper/upload_stack.rb} +15 -6
  29. data/templates/lib/core/applications.rb +479 -0
  30. data/templates/lib/core/assume_role.rb +40 -0
  31. data/templates/lib/core/classes.rb +25 -0
  32. data/templates/{core_compile.rb.erb → lib/core/compile.rb} +1 -0
  33. data/templates/lib/core/dependencies.rb +22 -0
  34. data/templates/{core_deploy.rb.erb → lib/core/deploy.rb} +20 -10
  35. data/templates/lib/core/git.rb +15 -0
  36. data/templates/lib/core/init.rb +173 -0
  37. data/templates/{core_upload.rb.erb → lib/core/upload.rb} +0 -0
  38. data/templates/{main.rb.erb → lib/main.rb} +8 -6
  39. data/templates/lib/shared_concerns/global_variables.rb +56 -0
  40. data/templates/{helper_methods.rb.erb → lib/shared_concerns/helper_functions.rb} +0 -0
  41. data/templates/lib/shared_concerns/helper_methods.rb +3 -0
  42. data/templates/{shared_methods.rb.erb → lib/shared_concerns/shared_methods.rb} +9 -0
  43. data/templates/lib/stacks/acm_stack/certificate_manager.rb +79 -0
  44. data/templates/{new_stack.rb.erb → lib/stacks/acm_stack/main.rb} +3 -4
  45. data/templates/lib/stacks/ecs_stack/ecs_cluster.rb +344 -0
  46. data/templates/lib/stacks/ecs_stack/lifecycle_hook.rb +188 -0
  47. data/templates/lib/stacks/ecs_stack/load_balancer.rb +68 -0
  48. data/templates/{ecs_stack.rb.erb → lib/stacks/ecs_stack/main.rb} +2 -1
  49. data/templates/{project_stack.rb.erb → lib/stacks/parent_stack/main.rb} +2 -2
  50. data/templates/lib/stacks/parent_stack/parent.rb +18 -0
  51. data/templates/lib/stacks/vpc_stack/infra_vpc.rb +193 -0
  52. data/templates/{vpc_stack.rb.erb → lib/stacks/vpc_stack/main.rb} +1 -2
  53. data/templates/{parent_stack_spec.rb.erb → spec/lib/parent_spec.rb} +2 -5
  54. data/templates/{spec_helper.rb.erb → spec/spec_helper.rb} +2 -2
  55. metadata +54 -44
  56. data/format.vim +0 -3
  57. data/templates/.env.erb +0 -4
  58. data/templates/.env.production.erb +0 -6
  59. data/templates/.env.rspec.erb +0 -6
  60. data/templates/.env.test.erb +0 -6
  61. data/templates/.gitlab-ci.yml.erb +0 -75
  62. data/templates/aws_sdk.rb.erb +0 -18
  63. data/templates/core_diff.rb.erb +0 -59
  64. data/templates/ecs_stack_concern.rb.erb +0 -20
  65. data/templates/global_variables.rb.erb +0 -16
  66. data/templates/helpers.rb.erb +0 -7
  67. data/templates/new_concern.rb.erb +0 -10
  68. data/templates/project_concern.rb.erb +0 -26
  69. data/templates/subnets.rb.erb +0 -18
  70. data/templates/vpc_concerns.rb.erb +0 -87
  71. data/templates/vpc_spec.rb.erb +0 -39
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fda3f7f377b0a4e9ee10986452ef45a2a29dc5fccc83cead2b72d3cf4905deb7
4
- data.tar.gz: 99ad6240a85bc7e2286e36295c0838dc6abd739acd6a23a047a5865fe54d9488
3
+ metadata.gz: 98d65cbb897496a9645eab2271bc04e8a7080e2cbf247537e5e5eb65e78f6fbe
4
+ data.tar.gz: 3da58edcf1ac8f9a58846e8e3ca459090f1590af531640b94fafc137ac949712
5
5
  SHA512:
6
- metadata.gz: fa76e06abe1e03750ff2f6b4e9a95bfc7c39694a5670dbe417f7f7ffb516366a27bbc8ed0f6eeae0e92d7e1dae323205c428c3646a90cb009ab541f309478cb1
7
- data.tar.gz: b4f1ff39ff403c951bee540644035189f908b9a1c65a398576b87f388fc24c7c96a4c4d3e270608f639b1e80206911ede557e9184c1274d1e3570004402430ac
6
+ metadata.gz: 3eed6c4a96dfafb68fa8a4e67058ec1951caea92bd5d6337f55a9d7638735874da321b5ac1c40dc3384a6207d942b0aa9aef463841213adf492d045941ec57a1
7
+ data.tar.gz: fda4c8d3d8436b2f4554fe15add7172d0f903792cd06086a7d8caf59e43e2fa38be4287714c303e30bb22ab78f5fcfc968232e75f8c3372a30aabbaaa2da5970
data/CHANGELOG.md CHANGED
@@ -2,7 +2,12 @@
2
2
  All notable changes to Rubycfn will be documented in this file.
3
3
  This project uses [Semantic Versioning](http://semver.org/).
4
4
 
5
- ## 0.4.11 (Next Release)
5
+ ## 0.5.1 (Next Release)
6
+
7
+ ## 0.5.0
8
+
9
+ * Restructuring project -- [@dennisvink][@dennisvink]
10
+ * Disabled scaffolding -- [@dennisvink][@dennisvink]
6
11
 
7
12
  ## 0.4.10
8
13
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubycfn (0.4.10)
4
+ rubycfn (0.5.0)
5
5
  activesupport (~> 5.1.5)
6
6
  dotenv (~> 2.4.0)
7
7
  json (~> 2.1.0)
data/README.md CHANGED
@@ -61,7 +61,7 @@ __________ ____ __________________.___._________ _____________________
61
61
  | _/ | /| | _// | |/ \ \/ | __) | | _/
62
62
  | | \ | / | | \\____ |\ \____| \ | | \
63
63
  |____|_ /______/ |______ // ______| \______ /\___ / |______ /
64
- \/ \/ \/ \/ \/ \/ [v0.4.10]
64
+ \/ \/ \/ \/ \/ \/ [v0.5.0]
65
65
  Project name? example
66
66
  Account ID? 1234567890
67
67
  Select region EU (Frankfurt)
@@ -75,6 +75,9 @@ Installing project dependencies:
75
75
  Updating project dependencies:
76
76
  `bundle update`
77
77
 
78
+ Deploying dependency stack to AWS:
79
+ `rake init`
80
+
78
81
  Compiling Rubycfn project:
79
82
  `rake compile`
80
83
 
@@ -87,9 +90,6 @@ Running tests and compiling:
87
90
  Uploading built stacks to s3:
88
91
  `rake upload`
89
92
 
90
- Checking difference between local and remote stack:
91
- `rake diff`
92
-
93
93
  Deploying stack to AWS:
94
94
  `rake apply`
95
95
 
@@ -98,21 +98,23 @@ Deploying stack to AWS:
98
98
  A new Rubycfn project has the following structure:
99
99
 
100
100
  ```
101
- total 112
102
- drwxr-xr-x 14 dennis staff 448 Jul 15 20:43 .
103
- drwxr-xr-x 17 dennis staff 544 Jul 15 20:43 ..
104
- -rw-r--r-- 1 dennis staff 92 Jul 15 20:43 .env
105
- -rw-r--r-- 1 dennis staff 325 Jul 15 20:43 .env.production
106
- -rw-r--r-- 1 dennis staff 207 Jul 15 20:43 .env.rspec
107
- -rw-r--r-- 1 dennis staff 298 Jul 15 20:43 .env.test
108
- drwxr-xr-x 10 dennis staff 320 Jul 15 20:43 .git
109
- -rw-r--r-- 1 dennis staff 1344 Jul 15 20:43 .rubocop.yml
110
- -rw-r--r-- 1 dennis staff 502 Jul 15 20:43 Gemfile
111
- -rw-r--r-- 1 dennis staff 27158 Jul 15 20:43 Gemfile.lock
112
- -rw-r--r-- 1 dennis staff 998 Jul 15 20:43 Rakefile
113
- drwxr-xr-x 2 dennis staff 64 Jul 15 20:43 build
114
- drwxr-xr-x 7 dennis staff 224 Jul 15 20:43 lib
115
- drwxr-xr-x 4 dennis staff 128 Jul 15 20:43 spec
101
+ drwxr-xr-x 3 dennis staff 96 Mar 4 02:43 bootstrap
102
+ drwxr-xr-x 7 dennis staff 224 Mar 4 02:43 lib
103
+ drwxr-xr-x 4 dennis staff 128 Mar 4 02:43 spec
104
+ -rw-r--r-- 1 dennis staff 49 Mar 4 02:43 .env
105
+ -rw-r--r-- 1 dennis staff 31 Mar 4 02:43 .env.acceptance
106
+ -rw-r--r-- 1 dennis staff 279 Mar 4 02:43 .env.dependencies.rspec
107
+ -rw-r--r-- 1 dennis staff 32 Mar 4 02:43 .env.development
108
+ -rw-r--r-- 1 dennis staff 31 Mar 4 02:43 .env.production
109
+ -rw-r--r-- 1 dennis staff 33 Mar 4 02:43 .env.rspec
110
+ -rw-r--r-- 1 dennis staff 25 Mar 4 02:43 .env.test
111
+ -rw-r--r-- 1 dennis staff 1110 Mar 4 02:43 .gitignore
112
+ -rw-r--r-- 1 dennis staff 1524 Mar 4 02:43 .rubocop.yml
113
+ -rw-r--r-- 1 dennis staff 477 Mar 4 02:43 Gemfile
114
+ -rw-r--r-- 1 dennis staff 31603 Mar 4 02:43 Gemfile.lock
115
+ -rw-r--r-- 1 dennis staff 292 Mar 4 02:43 README.md
116
+ -rw-r--r-- 1 dennis staff 1267 Mar 4 02:43 Rakefile
117
+ -rw-r--r-- 1 dennis staff 1337 Mar 4 02:43 config.yaml
116
118
  ```
117
119
 
118
120
  Lets first discuss the files in the root folder.
@@ -134,15 +136,13 @@ The `.env` file contains environment variables that are available, regardless of
134
136
  the environment you're building for. For example:
135
137
 
136
138
  ```
137
- AWS_ACCOUNT_ID="1234567890"
138
139
  AWS_REGION="eu-west-1"
139
- ENVIRONMENT="rspec"
140
- PROJECT_NAME="sample"
140
+ ENVIRONMENT="development"
141
141
  ```
142
142
 
143
143
  #### .env.production and .env.test
144
144
 
145
- The `.env.production` and `.env.test` files contain environment variables that
145
+ The `.env.production` and `.env.x` files contain environment variables that
146
146
  are specific to production or test respectively. For example `.env.test` can
147
147
  contain something like this:
148
148
 
@@ -150,20 +150,6 @@ contain something like this:
150
150
  # ENV vars for test environment
151
151
  CLOUD_TRAIL_MONITOR_SNS_RECIPIENTS="changeme@example.com,changemetoo@example.com"
152
152
  ROOT_MONITOR_SNS_RECIPIENTS="changeme@example.com,changemetoo@example.com"
153
- VPC_CIDR_BLOCK="10.100.0.0/16"
154
- ARTIFACT_BUCKET="my-awesome-cloudformation-artifact-bucket"
155
- STACK_NAME="test"
156
- ```
157
-
158
- While .env.production can look something like this:
159
-
160
- ```
161
- # ENV vars for production environment
162
- CLOUD_TRAIL_MONITOR_SNS_RECIPIENTS="changeme@example.com,changemetoo@example.com"
163
- ROOT_MONITOR_SNS_RECIPIENTS="changeme@example.com,changemetoo@example.com"
164
- VPC_CIDR_BLOCK="10.200.0.0/16"
165
- ARTIFACT_BUCKET="my-awesome-cloudformation-artifact-bucket-for-production"
166
- STACK_NAME="production"
167
153
  ```
168
154
 
169
155
  You can reuse these environment variables in your project code.
@@ -178,7 +164,7 @@ so that you can test the resulting CloudFormation templates properly.
178
164
  There is one file that is not generated by default but does need mentioning:
179
165
  the `.env.private` file. This is a special file that allows you to override
180
166
  environment variables. An environment variable set in .env.private always takes
181
- precedence over environment variables set in other .env* files.
167
+ precedence over environment variables set in other .env files.
182
168
 
183
169
  #### .rubocop.yml
184
170
 
@@ -188,12 +174,12 @@ violations.
188
174
 
189
175
  ### Rubycfn project directories
190
176
 
191
- As shown before, a Rubycfn project contains three directories:
177
+ As shown before, a Rubycfn project contains four directories:
192
178
 
193
179
  ```
194
- drwxr-xr-x 2 dennis staff 64 Jul 15 20:43 build
195
- drwxr-xr-x 7 dennis staff 224 Jul 15 20:43 lib
196
- drwxr-xr-x 4 dennis staff 128 Jul 15 20:43 spec
180
+ drwxr-xr-x 3 dennis staff 96 Mar 4 02:43 bootstrap
181
+ drwxr-xr-x 7 dennis staff 224 Mar 4 02:43 lib
182
+ drwxr-xr-x 4 dennis staff 128 Mar 4 02:43 spec
197
183
  ```
198
184
 
199
185
  #### build
@@ -247,39 +233,33 @@ that you want to reuse cross stacks, create a shared concern.
247
233
  The `stacks` folder, by default, contains the following:
248
234
 
249
235
  ```
250
- total 24
251
- drwxr-xr-x 8 dennis staff 256 Jul 15 20:43 .
252
- drwxr-xr-x 7 dennis staff 224 Jul 15 20:43 ..
253
- drwxr-xr-x 3 dennis staff 96 Jul 15 20:43 ecs_stack
254
- -rw-r--r-- 1 dennis staff 254 Jul 15 20:43 ecs_stack.rb
255
- drwxr-xr-x 3 dennis staff 96 Jul 15 20:43 parent_stack
256
- -rw-r--r-- 1 dennis staff 259 Jul 15 20:43 parent_stack.rb
257
- drwxr-xr-x 4 dennis staff 128 Jul 15 20:43 vpc_stack
258
- -rw-r--r-- 1 dennis staff 248 Jul 15 20:43 vpc_stack.rb
236
+ drwxr-xr-x 4 dennis staff 128 Mar 4 02:43 acm_stack
237
+ drwxr-xr-x 6 dennis staff 192 Mar 4 02:43 ecs_stack
238
+ drwxr-xr-x 4 dennis staff 128 Mar 4 02:43 parent_stack
239
+ drwxr-xr-x 4 dennis staff 128 Mar 4 02:43 vpc_stack
259
240
  ```
260
241
 
261
- The default project creates three CloudFormation templates: a VPC stack, an
262
- ECS stack and a parent stack. The parent stack is a CloudFormation stack that
263
- contains all other stacks. When you deploy a Rubycfn project these other stacks
264
- show up as `nested stacks`. The parent stack acts not only as a container for
242
+ The default project creates four CloudFormation templates: a VPC stack, an
243
+ ECS stack, an ACM stack and a parent stack. The parent stack is a CloudFormation
244
+ stack that contains all other stacks. When you deploy a Rubycfn project these other
245
+ stacks show up as `nested stacks`. The parent stack acts not only as a container for
265
246
  all other stacks, but is also responsible for passing outputs from stacks as
266
247
  parameters to another. For example: The VPC Id that is created in the VPC stack
267
248
  can easily be passed to the ECS stack as a parameter. This nested stack approach
268
249
  has an additional benefit: A change of output in stack X can trigger an update
269
250
  in stack Y.
270
251
 
271
- The .rb files you see in the lib/stacks/ directory are the parent stack files.
272
- Lets have a look at `vpc_stack.rb`:
252
+ The lib/stacks/vpc_stack/ directory contains a `main.rb` file and a `vpc.rb` file.
253
+ Lets have a look at the vpc_stack/main.rb file:
273
254
 
274
255
  ```ruby
275
256
  module VpcStack
276
257
  extend ActiveSupport::Concern
277
258
  include Rubycfn
278
-
279
259
  included do
280
260
  include Concerns::GlobalVariables
281
261
  include Concerns::SharedMethods
282
- include VpcStack::Main
262
+ include VpcStack::InfraVpc
283
263
 
284
264
  description generate_stack_description("VpcStack")
285
265
  end
@@ -291,14 +271,14 @@ name ends with 'Stack' to make the compiler magic work. The code between
291
271
  `include do` and `end` loads in two of the shared concerns, and includes the
292
272
  VpcStack::Main module. Finally the description of the stack is set.
293
273
 
294
- The `lib/stacks/vpc_stack/` directory contains a `vpc.rb` file, which is the
295
- implementation of the VpcStack::Main module:
274
+ The `lib/stacks/vpc_stack/vpc.rb` file contains the implementation of the
275
+ VpcStack::InfraVpc module:
296
276
 
297
277
  ```ruby
298
278
  require_relative "subnets"
299
279
 
300
280
  module VpcStack
301
- module Main
281
+ module InfraVpc
302
282
  extend ActiveSupport::Concern
303
283
 
304
284
  included do
@@ -310,13 +290,9 @@ end
310
290
 
311
291
  The first line is identical to the parent stack file and defines this module is
312
292
  part of `VpcStack`. The second line defines the name of the module, in this case
313
- `Main`. The code beteen `included do` and `end` is the implementation of this
293
+ `InfraVpc`. The code beteen `included do` and `end` is the implementation of this
314
294
  module.
315
295
 
316
- Adding a new stack is trivial: Go to the root folder of the project and type
317
- `rubycfn stack`. This will prompt you for a stack name (do not include the 'stack' keyword)
318
- and it will generate the stack for you.
319
-
320
296
  ## AWS Intrinsic functions
321
297
 
322
298
  You can Ref by postpending the .ref method to any string or hash, e.g. :foobar.ref
data/bin/rubycfn CHANGED
@@ -13,7 +13,7 @@ if ARGV.first || (ARGF.filename != "-" or (not STDIN.tty? and not STDIN.closed?)
13
13
  if ARGV.class == Array && ARGV.first == "stack"
14
14
  case ARGV.first
15
15
  when "stack"
16
- scaffold_stack
16
+ puts "Scaffolding will be reintroduced later."
17
17
  end
18
18
  else
19
19
  require "rubycfn"
@@ -61,85 +61,29 @@ region = prompt.select(
61
61
  )
62
62
 
63
63
  render_args = {
64
- project_name: project_name,
65
64
  account_id: account_id,
66
- region: region
65
+ project_name: project_name,
66
+ region: region,
67
+ version: Rubycfn::VERSION
67
68
  }
68
69
 
69
- dotenv = render(".env", render_args, path)
70
- aws_sdk = render("aws_sdk.rb", {}, path)
71
- compiler = render("compiler.rb", {}, path)
72
- core_deploy = render("core_deploy.rb", { name: project_name }, path)
73
- core_upload = render("core_upload.rb", {}, path)
74
- core_compile = render("core_compile.rb", {}, path)
75
- core_diff = render("core_diff.rb", {}, path)
76
- dependencies = render("dependencies.rb", {}, path)
77
- deploy = render("deploy.rb", {}, path)
78
- dotenv_test = render(".env.test", { name: project_name }, path)
79
- dotenv_production = render(".env.production", { name: project_name }, path)
80
- dotenv_rspec = render(".env.rspec", { name: project_name }, path)
81
- ecs_stack = render("ecs_stack.rb", {}, path)
82
- ecs_stack_concern = render("ecs_stack_concern.rb", { name: project_name }, path)
83
- gemfile = render("Gemfile", { version: Rubycfn::VERSION }, path)
84
- gitignore = render(".gitignore", {}, path)
85
- global_variables = render("global_variables.rb", { name: project_name.downcase }, path)
86
- helpers = render("helpers.rb", {}, path)
87
- helper_methods = render("helper_methods.rb", {}, path)
88
- main = render("main.rb", {}, path)
89
- main_aws_helper = render("main_aws_helper.rb", {}, path)
90
- parent_spec = render("parent_stack_spec.rb", { name: project_name.capitalize }, path)
91
- project_concern = render("project_concern.rb", { name: project_name.capitalize }, path)
92
- project_stack = render("project_stack.rb", { name: project_name.capitalize }, path)
93
- rakefile = render("Rakefile", {}, path)
94
- rubocop = render(".rubocop.yml", {}, path)
95
- shared_methods = render("shared_methods.rb", {}, path)
96
- spec_helper = render("spec_helper.rb", {}, path)
97
- subnets = render("subnets.rb", { name: project_name }, path)
98
- upload_stack = render("upload_stack.rb", {}, path)
99
- vpc_stack = render("vpc_stack.rb", { name: project_name }, path)
100
- vpc_concern = render("vpc_concerns.rb", { name: project_name }, path)
101
- vpc_spec = render("vpc_spec.rb", { name: project_name.capitalize }, path)
70
+ FileUtils.mkdir_p project_path
102
71
 
103
- # Create directory structure
104
- rubycfn_structure(project_path).each do |dir|
105
- FileUtils.mkdir_p dir
72
+ Dir.glob("#{path}/templates/**/*", File::FNM_DOTMATCH).each do |f|
73
+ if File.directory?(f)
74
+ dir = f.gsub("#{path}/templates/","")
75
+ FileUtils.mkdir_p "#{project_path}/#{dir}"
76
+ end
106
77
  end
107
78
 
108
- File.open("#{project_path}/lib/aws_helper/aws_sdk.rb", "w") { |file| file.write(aws_sdk) }
109
- File.open("#{project_path}/lib/aws_helper/compiler.rb", "w") { |file| file.write(compiler) }
110
- File.open("#{project_path}/lib/aws_helper/dependencies.rb", "w") { |file| file.write(dependencies) }
111
- File.open("#{project_path}/lib/aws_helper/deploy.rb", "w") { |file| file.write(deploy) }
112
- File.open("#{project_path}/lib/core/deploy.rb", "w") { |file| file.write(core_deploy) }
113
- File.open("#{project_path}/lib/core/compile.rb", "w") { |file| file.write(core_compile) }
114
- File.open("#{project_path}/lib/core/diff.rb", "w") { |file| file.write(core_diff) }
115
- File.open("#{project_path}/lib/core/upload.rb", "w") { |file| file.write(core_upload) }
116
- File.open("#{project_path}/.env", "w") { |file| file.write(dotenv) }
117
- File.open("#{project_path}/.env.test", "w") { |file| file.write(dotenv_test) }
118
- File.open("#{project_path}/.env.production", "w") { |file| file.write(dotenv_production) }
119
- File.open("#{project_path}/.env.rspec", "w") { |file| file.write(dotenv_rspec) }
120
- File.open("#{project_path}/lib/stacks/ecs_stack.rb", "w") { |file| file.write(ecs_stack) }
121
- File.open("#{project_path}/lib/stacks/ecs_stack/ecs_cluster.rb", "w") { |file| file.write(ecs_stack_concern) }
122
- File.open("#{project_path}/Gemfile", "w") { |file| file.write(gemfile) }
123
- File.open("#{project_path}/.gitignore", "w") { |file| file.write(gitignore) }
124
- File.open("#{project_path}/lib/shared_concerns/global_variables.rb", "w") { |file| file.write(global_variables) }
125
- File.open("#{project_path}/lib/aws_helper/helpers.rb", "w") { |file| file.write(helpers) }
126
- File.open("#{project_path}/lib/shared_concerns/helper_methods.rb", "w") { |file| file.write(helper_methods) }
127
- File.open("#{project_path}/lib/main.rb", "w") { |file| file.write(main) }
128
- File.open("#{project_path}/lib/aws_helper/main.rb", "w") { |file| file.write(main_aws_helper) }
129
- File.open("#{project_path}/spec/lib/parent_spec.rb", "w") { |file| file.write(parent_spec) }
130
- File.open("#{project_path}/lib/stacks/parent_stack.rb", "w") { |file| file.write(project_stack) }
131
- File.open("#{project_path}/lib/stacks/parent_stack/parent.rb", "w") { |file| file.write(project_concern) }
132
- File.open("#{project_path}/Rakefile", "w") { |file| file.write(rakefile) }
133
- File.open("#{project_path}/.rubocop.yml", "w") { |file| file.write(rubocop) }
134
- File.open("#{project_path}/lib/shared_concerns/shared_methods.rb", "w") { |file| file.write(shared_methods) }
135
- File.open("#{project_path}/spec/spec_helper.rb", "w") { |file| file.write(spec_helper) }
136
- File.open("#{project_path}/lib/stacks/vpc_stack/subnets.rb", "w") { |file| file.write(subnets) }
137
- File.open("#{project_path}/lib/aws_helper/upload_stack.rb", "w") { |file| file.write(upload_stack) }
138
- File.open("#{project_path}/spec/lib/vpc_spec.rb", "w") { |file| file.write(vpc_spec) }
139
- File.open("#{project_path}/lib/stacks/vpc_stack.rb", "w") { |file| file.write(vpc_stack) }
140
- File.open("#{project_path}/lib/stacks/vpc_stack/vpc.rb", "w") { |file| file.write(vpc_concern) }
79
+ Dir.glob("#{path}/templates/**/*", File::FNM_DOTMATCH).each do |f|
80
+ unless File.directory?(f)
81
+ file = f.gsub("#{path}/templates/","")
82
+ contents = render(f, render_args)
83
+ File.open("#{project_path}/#{file}", "w") { |file| file.write(contents) }
84
+ end
85
+ end
141
86
 
142
87
  puts "Setting up Rubycfn #{project_name} project..."
143
88
  `cd #{project_name}-rubycfn && git init && bundle`
144
- `bundle`
145
89
  puts "Done!"
data/lib/cli_methods.rb CHANGED
@@ -1,5 +1,5 @@
1
- def render(file, vars, path)
2
- template = File.read("#{path}/templates/#{file}.erb")
1
+ def render(file, vars)
2
+ template = File.read(file)
3
3
  ERB.new(template).result(OpenStruct.new(vars).instance_eval { binding })
4
4
  end
5
5
 
@@ -1,4 +1,4 @@
1
1
  # Rubycfn version
2
2
  module Rubycfn
3
- VERSION = "0.4.10".freeze
3
+ VERSION = "0.5.0".freeze
4
4
  end
data/templates/.env ADDED
@@ -0,0 +1,2 @@
1
+ AWS_REGION="<%= region %>"
2
+ ENVIRONMENT="development"
@@ -0,0 +1 @@
1
+ # Acceptance-specific ENV vars
@@ -0,0 +1,6 @@
1
+ ARTIFACTBUCKET=rspec-artifactbucket-m0ck
2
+ HOSTEDZONENAME=rspec.example.com
3
+ HOSTEDZONEID=13117756P2M0CK
4
+ LOGGINGBUCKET=rspec-dependencystack-loggingbucket-mock
5
+ CLOUDFORMATIONBUCKET=rspec-dependencystack-cloudformationbucket-mock
6
+ LAMBDABUCKET=rspec-dependencystack-lambdabucket-mock
@@ -0,0 +1 @@
1
+ # Development-specific ENV vars
@@ -0,0 +1 @@
1
+ # Production-specific ENV vars
@@ -0,0 +1 @@
1
+ # ENV vars for rspec environment
@@ -0,0 +1 @@
1
+ # Test-specific ENV vars
@@ -82,3 +82,6 @@ temp/
82
82
  attic/
83
83
  /venv
84
84
  /Gemfile.lock
85
+ .env.dependencies
86
+ CloudFormationResourceSpecification.json
87
+ config.json
@@ -11,6 +11,7 @@ AllCops:
11
11
  Exclude:
12
12
  - "test/**/*.rb"
13
13
  - "spec/**/*.rb"
14
+ - "attic/**/*"
14
15
 
15
16
  Metrics/AbcSize:
16
17
  Max: 500
@@ -34,7 +35,7 @@ Style/Documentation:
34
35
  Enabled: false
35
36
 
36
37
  Metrics/LineLength:
37
- Max: 500
38
+ Max: 700
38
39
  Exclude:
39
40
  - "test/**/*"
40
41
  - "spec/**/*"
@@ -87,5 +88,17 @@ Style/IfUnlessModifier:
87
88
  Style/DateTime:
88
89
  Enabled: false
89
90
 
91
+ Style/RedundantSelf:
92
+ Enabled: false
93
+
90
94
  Layout/SpaceInsideHashLiteralBraces:
91
95
  EnforcedStyle: space
96
+
97
+ Metrics/MethodLength:
98
+ Enabled: false
99
+
100
+ Metrics/PerceivedComplexity:
101
+ Max: 20
102
+
103
+ Style/EvalWithLocation:
104
+ Enabled: false
@@ -2,7 +2,6 @@ source "https://rubygems.org" do
2
2
  gem "aws-sdk", "~> 3.0.1"
3
3
  gem "aws-sdk-s3", "~> 1.36.0"
4
4
  gem "colorize", "~> 0.8.1"
5
- gem "diffy", "~> 3.3.0"
6
5
  gem "git-revision", "~> 0.0.2"
7
6
  gem "launchy", "~> 2.4.3"
8
7
  gem "rspec", "~> 3.8"
@@ -0,0 +1,57 @@
1
+ # Infrastructure for <%= project_name %>
2
+
3
+ ```
4
+ __________ ____ __________________.___._________ _____________________
5
+ \______ \ | \______ \__ | |\_ ___ \\_ _____/\______ \
6
+ | _/ | /| | _// | |/ \ \/ | __) | | _/
7
+ | | \ | / | | \\____ |\ \____| \ | | \
8
+ |____|_ /______/ |______ // ______| \______ /\___ / |______ /
9
+ \/ \/ \/ \/ \/ \/ [<%= version %>]
10
+ ```
11
+
12
+ ## Prerequisites
13
+
14
+ - Edit .env.private and configure your AWS credentials, or export your AWS credentials.
15
+ - Type `rake init` to create the DependencyStack in your AWS account
16
+
17
+ ## Rake commands
18
+
19
+ `rake` - Compile the code into CloudFormation templates and run unit tests
20
+ `rake init` - Deploy the DependencyStack in the AWS account
21
+ `rake compile` - Compile the code into CloudFormation templates
22
+ `rake spec` - Run unit tests
23
+ `rake upload` - Upload the CloudFormation templates to s3
24
+ `rake apply` - Deploy the CloudFormation templates
25
+
26
+ ## Stack configuration
27
+
28
+ The `config.yaml` file in the root directory of this project contains most of the configuration. It contains the networking configuration for each environment, subnet configuration, DNS and ECS (Docker) containers that are deployed.
29
+
30
+ ## Adding your own resources
31
+
32
+ The lib/stacks/ directory contains all nested stacks for this project. Every nested stack has a
33
+ directory under lib/stacks/. You can add resources to any of these stacks, or create a new stack altogether. See [https://github.com/dennisvink/rubycfn/blob/master/README.md](https://github.com/dennisvink/rubycfn/blob/master/README.md) for documentation.
34
+
35
+ ## About
36
+
37
+ The code generated by Rubycfn is copyrighted by Dennis Vink (https://drvink.com/),
38
+ except for modifications made to the <%= project_name %> project after the initial
39
+ `git init` command.
40
+
41
+ For the generated code permission is hereby granted, free of charge, to any
42
+ person obtaining a copy of the generated software and associated documentation
43
+ files (the "Software"), to deal in the Software without restriction, including
44
+ without limitation the rights to use, copy, modify, merge, publish, distribute,
45
+ sublicense, and/or sell copies of the Software, and to permit persons to whom
46
+ the Software is furnished to do so, subject to the following conditions:
47
+
48
+ The above copyright notice and this permission notice shall be included in all
49
+ copies or substantial portions of the Software.
50
+
51
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
52
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
53
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
54
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
55
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
56
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
57
+ THE SOFTWARE.
@@ -12,17 +12,22 @@ RSpec::Core::RakeTask.new do |t|
12
12
  end
13
13
 
14
14
  desc "Apply CloudFormation template"
15
- task :apply do
15
+ task :apply_stack do
16
16
  require_relative "lib/main"
17
17
  require_relative "lib/core/deploy"
18
18
  end
19
19
 
20
20
  desc "Upload stacks to s3"
21
- task :upload do
21
+ task :upload_stack do
22
22
  require_relative "lib/main"
23
23
  require_relative "lib/core/upload"
24
24
  end
25
25
 
26
+ desc "Initialize AWS Account"
27
+ task :init do
28
+ require_relative "lib/core/init"
29
+ end
30
+
26
31
  desc "Clean build directory"
27
32
  task :clean do
28
33
  Dir.foreach("build/") do |f|
@@ -31,14 +36,13 @@ task :clean do
31
36
  end
32
37
  end
33
38
 
34
- desc "Diff CloudFormation template"
35
- task :diff do
36
- require_relative "lib/main"
37
- require_relative "lib/core/diff"
39
+ desc "Store dependencies of DependencyStack in .env.dependencies"
40
+ task :dependencies do
41
+ require_relative "lib/core/dependencies.rb"
38
42
  end
39
43
 
40
44
  desc "Compile CloudFormation"
41
- task :compile do
45
+ task :compile_stack do
42
46
  require_relative "lib/main"
43
47
  require_relative "lib/core/compile"
44
48
  end
@@ -47,4 +51,7 @@ RuboCop::RakeTask.new(:rubocop) do |t|
47
51
  t.options = ["--display-cop-names"]
48
52
  end
49
53
 
50
- task default: %i(spec compile)
54
+ task default: %i(dependencies compile_stack spec)
55
+ task compile: %i(dependencies compile_stack)
56
+ task upload: %i(dependencies upload_stack)
57
+ task apply: %i(dependencies apply_stack)
@@ -0,0 +1,49 @@
1
+ description "Dependency Stack"
2
+
3
+ parameter :environment,
4
+ description: "Environment name",
5
+ type: "String"
6
+
7
+ parameter :domain_name,
8
+ description: "Domain name",
9
+ type: "String"
10
+
11
+ condition :has_environment,
12
+ [["", :environment.ref].fnequals].fnnot
13
+
14
+ condition :has_domain_name,
15
+ [["", :domain_name.ref].fnequals].fnnot
16
+
17
+ %i(
18
+ artifact_bucket
19
+ cloudformation_bucket
20
+ lambda_bucket
21
+ logging_bucket
22
+ ).each do |bucket|
23
+ resource bucket,
24
+ deletion_policy: "Retain",
25
+ update_replace_policy: "Retain",
26
+ type: "AWS::S3::Bucket"
27
+
28
+ output bucket,
29
+ value: bucket.ref
30
+ end
31
+
32
+ resource :hosted_zone,
33
+ condition: "HasDomainName",
34
+ type: "AWS::Route53::HostedZone" do |r|
35
+ r.property(:hosted_zone_config) do
36
+ {
37
+ "Comment": ["Hosted zone for ", ["HasEnvironment", [:environment.ref, "."].fnjoin, ""].fnif, :domain_name.ref].fnjoin
38
+ }
39
+ end
40
+ r.property(:name) { [["HasEnvironment", [:environment.ref, "."].fnjoin, ""].fnif, :domain_name.ref].fnjoin }
41
+ end
42
+
43
+ output :hosted_zone_id,
44
+ condition: "HasDomainName",
45
+ value: :hosted_zone.ref
46
+
47
+ output :hosted_zone_name,
48
+ condition: "HasDomainName",
49
+ value: [["HasEnvironment", [:environment.ref, "."].fnjoin, ""].fnif, :domain_name.ref].fnjoin