rubycfn 0.3.2 → 0.3.3

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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -1
  3. data/Gemfile.lock +1 -1
  4. data/README.md +13 -40
  5. data/bin/rubycfn +56 -20
  6. data/lib/cli_methods.rb +5 -1
  7. data/lib/rubycfn/version.rb +1 -1
  8. data/lib/rubycfn.rb +0 -1
  9. data/templates/.env.erb +0 -1
  10. data/templates/.env.production.erb +6 -0
  11. data/templates/.env.rspec.erb +6 -0
  12. data/templates/.env.test.erb +5 -1
  13. data/templates/.gitignore.erb +82 -0
  14. data/templates/.gitlab-ci.yml.erb +75 -0
  15. data/templates/.rubocop.yml.erb +91 -0
  16. data/templates/Gemfile.erb +13 -5
  17. data/templates/Rakefile.erb +34 -1
  18. data/templates/aws_sdk.rb.erb +18 -0
  19. data/templates/compiler.rb.erb +61 -0
  20. data/templates/core_compile.rb.erb +6 -0
  21. data/templates/core_deploy.rb.erb +115 -0
  22. data/templates/core_diff.rb.erb +59 -0
  23. data/templates/core_upload.rb.erb +3 -0
  24. data/templates/dependencies.rb.erb +23 -0
  25. data/templates/deploy.rb.erb +53 -0
  26. data/templates/ecs_stack.rb.erb +12 -0
  27. data/templates/ecs_stack_concern.rb.erb +20 -0
  28. data/templates/global_variables.rb.erb +4 -0
  29. data/templates/helper_methods.rb.erb +3 -0
  30. data/templates/helpers.rb.erb +7 -0
  31. data/templates/main.rb.erb +4 -4
  32. data/templates/main_aws_helper.rb.erb +16 -0
  33. data/templates/parent_stack_spec.rb.erb +38 -0
  34. data/templates/project_concern.rb.erb +16 -50
  35. data/templates/project_stack.rb.erb +5 -2
  36. data/templates/shared_methods.rb.erb +38 -0
  37. data/templates/spec_helper.rb.erb +3 -1
  38. data/templates/subnets.rb.erb +18 -0
  39. data/templates/upload_stack.rb.erb +27 -0
  40. data/templates/vpc_concerns.rb.erb +87 -0
  41. data/templates/vpc_spec.rb.erb +40 -0
  42. data/templates/vpc_stack.rb.erb +12 -0
  43. metadata +30 -13
  44. data/lib/compound/resources.rb +0 -1
  45. data/lib/compound/vpc.rb +0 -90
  46. data/lib/compound.rb +0 -1
  47. data/templates/buildspec.yml.erb +0 -21
  48. data/templates/cfn2rubycfn.erb +0 -127
  49. data/templates/cicd.rb.erb +0 -91
  50. data/templates/compile.rb.erb +0 -18
  51. data/templates/example_stack_spec.rb.erb +0 -101
  52. data/templates/format.vim.erb +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f25559943267a800e4f964a93dd295887662876
4
- data.tar.gz: 1828ebf37d85a2901495890633889f18f6a9c9fa
3
+ metadata.gz: f3e0e86dd1547d4101efb979eec8e2d7fc86317c
4
+ data.tar.gz: 7eeb0659142403b03a6595684ea82dd075bd649f
5
5
  SHA512:
6
- metadata.gz: 0048040b6bc29923c05f98bb38d0dda8e87852df009c9f2c69655a2576c09f580576f6fca5449e02570dcbb52e4c19b5b42830d521fe92f533ff075ea1d6764c
7
- data.tar.gz: 3342cbb4ed4070d9dfbfb5439231f656dbe50b7fd58dd41b75e3d879ef789113876e7b6f52265cf45fa4f484bfa34ea1df5007e399c44603947ca235cbb966ed
6
+ metadata.gz: 4247d0ba01aea95e143db51a2cbe6468c74be2107e558a0659de5c9528785b93caf48d0584299f430eace4bc048796905f727923c010bc4ea6788eb7758f533c
7
+ data.tar.gz: 3ee4eb5457c89813e811a63c502d8628ff76bd1b905329d44e1a3a27b177fbf0d03191d80589dabaf7fb12b56b55f4db89b3516097f76ab26e5e124a57ecaf35
data/CHANGELOG.md CHANGED
@@ -2,7 +2,11 @@
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.3.3 (Next Release)
5
+ ## 0.3.4 (Next Release)
6
+
7
+ ## 0.3.3
8
+
9
+ * Added new skeleton for projects -- [@dennisvink][@dennisvink]
6
10
 
7
11
  ## 0.3.2
8
12
  * Added AWS::Serverless::Transform capability -- [@dennisvink][@dennisvink]
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubycfn (0.3.2)
4
+ rubycfn (0.3.3)
5
5
  activesupport (~> 5.1.5)
6
6
  dotenv (~> 2.4.0)
7
7
  json (~> 2.1.0)
data/README.md CHANGED
@@ -3,6 +3,10 @@
3
3
  [RubyCfn](https://rubycfn.com/) is a light-weight tiny CloudFormation, Deployment Manager and ARM DSL to make expressing
4
4
  AWS templates as Ruby code a bit more pleasing to the eye.
5
5
 
6
+ Note, as of 0.3.3 the default project structure changed quite a bit. The README.md does not reflect
7
+ those changes yet. A rubycfn project is now provisioned with a nested stack set up, and includes
8
+ a nested VPC and a nested ECS stack.
9
+
6
10
  ## Quick start
7
11
 
8
12
  Install Rubycfn:
@@ -16,7 +20,7 @@ __________ ____ __________________.___._________ _____________________
16
20
  | _/ | /| | _// | |/ \ \/ | __) | | _/
17
21
  | | \ | / | | \\____ |\ \____| \ | | \
18
22
  |____|_ /______/ |______ // ______| \______ /\___ / |______ /
19
- \/ \/ \/ \/ \/ \/ [v0.3.1]
23
+ \/ \/ \/ \/ \/ \/ [v0.3.3]
20
24
  Project name? example
21
25
  Account ID? 1234567890
22
26
  Select region EU (Frankfurt)
@@ -37,8 +41,14 @@ Running Rubycfn unit tests:
37
41
  Running tests and compiling:
38
42
  `rake`
39
43
 
40
- Converting CloudFormation JSON template to Rubycfn:
41
- `./cfn2rubycfn /path/to/cloudformation_template.json`
44
+ Uploading built stacks to s3:
45
+ `rake upload`
46
+
47
+ Checking difference between local and remote stack:
48
+ `rake diff`
49
+
50
+ Deploying stack to AWS:
51
+ `rake apply`
42
52
 
43
53
  ## Philosophy
44
54
 
@@ -249,7 +259,6 @@ You start a new project by typing `rubycfn` at the prompt. This will ask you a c
249
259
  -rw-r--r-- 1 binx staff 246 Oct 17 16:06 Gemfile
250
260
  -rw-r--r-- 1 binx staff 346 Oct 17 16:06 Rakefile
251
261
  drwxr-xr-x 2 binx staff 64 Oct 17 16:06 build
252
- -rwxrwxrwx 1 binx staff 3223 Oct 17 16:06 cfn2rubycfn
253
262
  drwxr-xr-x 3 binx staff 96 Oct 17 16:06 config
254
263
  -rw-r--r-- 1 binx staff 15 Oct 17 16:06 format.vim
255
264
  drwxr-xr-x 6 binx staff 192 Oct 17 16:06 lib
@@ -271,42 +280,6 @@ The `Gemfile` is a collection of Ruby dependencies. By running `bundle` you inst
271
280
 
272
281
  The `Rakefile` contain the tasks that are performed when you type the `rake` command. It consists of a `compile` task and a `spec` task. You can invoke the tasks individually by typing `rake compile` or `rake spec`, but by default the `spec` task is ran first, and then the `compile` task. A “spec” is another word for unit test. It’s important to run the unit test first, so that if a test fails no template is generated. If you just run `rake` both tasks are executed sequentially, provided the specs throw no error.
273
282
 
274
- `cfn2rubycfn` is a small helper script that converts AWS CloudFormation scripts to Rubycfn code. This allows you to migrate your existing projects over to Rubycfn quickly. It exports the converted CloudFormation script to `generated.rb`, a ready to use module for your stacks.
275
-
276
- Example:
277
- ```
278
- $ cat sample.json
279
- {
280
- "AWSTemplateFormatVersion": "2010-09-09",
281
- "Resources": {
282
- "ApiGatewayRestApi": {
283
- "Properties": {
284
- "Name": "trigger-github-webhook"
285
- },
286
- "Type": "AWS::ApiGateway::RestApi"
287
- }
288
- }
289
- }
290
-
291
- $ ./cfn2rubycfn sample.json
292
- Reformatting code...
293
-
294
- $ cat generated.rb
295
- module ConvertedStack
296
- module Main
297
- extend ActiveSupport::Concern
298
- included do
299
- resource :api_gateway_rest_api,
300
- type: "AWS::ApiGateway::RestApi" do |r|
301
- r.property(:name) { "trigger-github-webhook" }
302
- end
303
- end
304
- end
305
- end
306
- ```
307
-
308
- The `format.vim` file is used by the CloudFormation conversion script to reindent the file after conversion. You can make changes to the file to reflect your preferred style of code indentation.
309
-
310
283
  Onto the subdirectories:
311
284
 
312
285
  The `build` directory is where all the compiled templates end up.
data/bin/rubycfn CHANGED
@@ -32,41 +32,77 @@ dotenv = render('.env', {
32
32
  :region => region
33
33
  }, path)
34
34
 
35
- buildspec = render('buildspec.yml', {}, path)
36
- cicd = render('cicd.rb', { name: project_name.capitalize, small_name: project_name }, path)
37
- compile = render('compile.rb', {}, path)
38
- dotenv_test = render('.env.test', { project_name: project_name }, path)
39
- example_spec = render('example_stack_spec.rb', { name: project_name.capitalize }, path)
35
+ aws_sdk = render('aws_sdk.rb', {}, path)
36
+ compiler = render('compiler.rb', {}, path)
37
+ core_deploy = render('core_deploy.rb', { name: project_name }, path)
38
+ core_upload = render('core_upload.rb', {}, path)
39
+ core_compile = render('core_compile.rb', {}, path)
40
+ core_diff = render('core_diff.rb', {}, path)
41
+ dependencies = render('dependencies.rb', {}, path)
42
+ deploy = render('deploy.rb', {}, path)
43
+ dotenv_test = render('.env.test', { name: project_name }, path)
44
+ dotenv_production = render('.env.production', { name: project_name }, path)
45
+ dotenv_rspec = render('.env.rspec', { name: project_name }, path)
46
+ ecs_stack = render('ecs_stack.rb', {}, path)
47
+ ecs_stack_concern = render('ecs_Stack_concern.rb', { name: project_name }, path)
40
48
  gemfile = render('Gemfile', { version: Rubycfn::VERSION }, path)
41
- global_variables = render('global_variables.rb', {}, path)
49
+ global_variables = render('global_variables.rb', { name: project_name.downcase }, path)
50
+ helpers = render('helpers.rb', {}, path)
51
+ helper_methods = render('helper_methods.rb', {}, path)
42
52
  main = render('main.rb', {}, path)
53
+ main_aws_helper = render('main_aws_helper.rb', {}, path)
54
+ parent_spec = render('parent_stack_spec.rb', { name: project_name.capitalize }, path)
43
55
  project_concern = render('project_concern.rb', { name: project_name.capitalize }, path)
44
56
  project_stack = render('project_stack.rb', { name: project_name.capitalize }, path)
45
57
  rakefile = render('Rakefile', {}, path)
58
+ rubocop = render('.rubocop.yml', {}, path)
59
+ shared_methods = render('shared_methods.rb', {}, path)
46
60
  spec_helper = render('spec_helper.rb', {}, path)
47
- converter = render('cfn2rubycfn', {}, path)
48
- vimfile = render('format.vim', {}, path)
61
+ subnets = render('subnets.rb', { name: project_name }, path)
62
+ upload_stack = render('upload_stack.rb', {}, path)
63
+ vpc_stack = render('vpc_stack.rb', { name: project_name }, path)
64
+ vpc_concern = render('vpc_concerns.rb', { name: project_name }, path)
65
+ vpc_spec = render('vpc_spec.rb', { name: project_name.capitalize }, path)
49
66
 
50
67
  # Create directory structure
51
- FileUtils.mkdir_p project_path + '/lib/stacks/' + project_name + '_stack'
52
68
  rubycfn_structure(project_path).each do |dir|
53
69
  FileUtils.mkdir_p dir
54
70
  end
55
71
 
72
+ File.open("#{project_path}/lib/aws_helper/aws_sdk.rb", 'w') { |file| file.write(aws_sdk) }
73
+ File.open("#{project_path}/lib/aws_helper/compiler.rb", 'w') { |file| file.write(compiler) }
74
+ File.open("#{project_path}/lib/aws_helper/dependencies.rb", 'w') { |file| file.write(dependencies) }
75
+ File.open("#{project_path}/lib/aws_helper/deploy.rb", 'w') { |file| file.write(deploy) }
76
+ File.open("#{project_path}/lib/core/deploy.rb", 'w') { |file| file.write(core_deploy) }
77
+ File.open("#{project_path}/lib/core/compile.rb", 'w') { |file| file.write(core_compile) }
78
+ File.open("#{project_path}/lib/core/diff.rb", 'w') { |file| file.write(core_diff) }
79
+ File.open("#{project_path}/lib/core/upload.rb", 'w') { |file| file.write(core_upload) }
56
80
  File.open("#{project_path}/.env", 'w') { |file| file.write(dotenv) }
57
81
  File.open("#{project_path}/.env.test", 'w') { |file| file.write(dotenv_test) }
82
+ File.open("#{project_path}/.env.production", 'w') { |file| file.write(dotenv_production) }
83
+ File.open("#{project_path}/.env.rspec", 'w') { |file| file.write(dotenv_rspec) }
84
+ File.open("#{project_path}/lib/stacks/ecs_stack.rb", 'w') { |file| file.write(ecs_stack) }
85
+ File.open("#{project_path}/lib/stacks/ecs_stack/ecs_cluster.rb", 'w') { |file| file.write(ecs_stack_concern) }
58
86
  File.open("#{project_path}/Gemfile", 'w') { |file| file.write(gemfile) }
59
- File.open("#{project_path}/Rakefile", 'w') { |file| file.write(rakefile) }
60
- File.open("#{project_path}/cfn2rubycfn", 'w') { |file| file.write(converter) }
61
- File.chmod(0777,"#{project_path}/cfn2rubycfn")
62
- File.open("#{project_path}/format.vim", 'w') { |file| file.write(vimfile) }
63
- File.open("#{project_path}/config/buildspec.yml", 'w') { |file| file.write(buildspec) }
64
- File.open("#{project_path}/lib/main.rb", 'w') { |file| file.write(main) }
65
- File.open("#{project_path}/lib/compile.rb", 'w') { |file| file.write(compile) }
66
87
  File.open("#{project_path}/lib/shared_concerns/global_variables.rb", 'w') { |file| file.write(global_variables) }
67
- File.open("#{project_path}/lib/stacks/#{project_name}_stack.rb", 'w') { |file| file.write(project_stack) }
68
- File.open("#{project_path}/lib/stacks/#{project_name}_stack/example.rb", 'w') { |file| file.write(project_concern) }
69
- File.open("#{project_path}/lib/stacks/#{project_name}_stack/cicd.rb", 'w') { |file| file.write(cicd) }
88
+ File.open("#{project_path}/lib/aws_helper/helpers.rb", 'w') { |file| file.write(helpers) }
89
+ File.open("#{project_path}/lib/shared_concerns/helper_methods.rb", 'w') { |file| file.write(helper_methods) }
90
+ File.open("#{project_path}/lib/main.rb", 'w') { |file| file.write(main) }
91
+ File.open("#{project_path}/lib/aws_helper/main.rb", 'w') { |file| file.write(main_aws_helper) }
92
+ File.open("#{project_path}/spec/lib/parent_spec.rb", 'w') { |file| file.write(parent_spec) }
93
+ File.open("#{project_path}/lib/stacks/parent_stack.rb", 'w') { |file| file.write(project_stack) }
94
+ File.open("#{project_path}/lib/stacks/parent_stack/parent.rb", 'w') { |file| file.write(project_concern) }
95
+ File.open("#{project_path}/Rakefile", 'w') { |file| file.write(rakefile) }
96
+ File.open("#{project_path}/.rubocop.yml", 'w') { |file| file.write(rubocop) }
97
+ File.open("#{project_path}/lib/shared_concerns/shared_methods.rb", 'w') { |file| file.write(shared_methods) }
70
98
  File.open("#{project_path}/spec/spec_helper.rb", 'w') { |file| file.write(spec_helper) }
71
- File.open("#{project_path}/spec/lib/#{project_name}_spec.rb", 'w') { |file| file.write(example_spec) }
99
+ File.open("#{project_path}/lib/stacks/vpc_stack/subnets.rb", 'w') { |file| file.write(subnets) }
100
+ File.open("#{project_path}/lib/aws_helper/upload_stack.rb", 'w') { |file| file.write(upload_stack) }
101
+ File.open("#{project_path}/spec/lib/vpc_spec.rb", 'w') { |file| file.write(vpc_spec) }
102
+ File.open("#{project_path}/lib/stacks/vpc_stack.rb", 'w') { |file| file.write(vpc_stack) }
103
+ File.open("#{project_path}/lib/stacks/vpc_stack/vpc.rb", 'w') { |file| file.write(vpc_concern) }
72
104
 
105
+ puts "Setting up Rubycfn #{project_name} project..."
106
+ `cd #{project_name}-rubycfn && git init && bundle`
107
+ `bundle`
108
+ puts "Done!"
data/lib/cli_methods.rb CHANGED
@@ -39,9 +39,13 @@ def rubycfn_structure(project_name)
39
39
  [
40
40
  project_name,
41
41
  project_name + '/build',
42
- project_name + '/config',
42
+ project_name + '/lib/aws_helper',
43
+ project_name + '/lib/core',
43
44
  project_name + '/lib/shared_concerns',
44
45
  project_name + '/lib/stacks',
46
+ project_name + '/lib/stacks/ecs_stack',
47
+ project_name + '/lib/stacks/parent_stack',
48
+ project_name + '/lib/stacks/vpc_stack',
45
49
  project_name + '/spec',
46
50
  project_name + '/spec/lib'
47
51
  ]
@@ -1,4 +1,4 @@
1
1
  # Rubycfn version
2
2
  module Rubycfn
3
- VERSION = "0.3.2"
3
+ VERSION = "0.3.3"
4
4
  end
data/lib/rubycfn.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # Rubycfn RubyCFN is a light-weight CloudFormation DSL
2
2
  require 'active_support/concern'
3
- require "compound/resources"
4
3
  require "json"
5
4
  require "neatjson"
6
5
  require "rubycfn/version"
data/templates/.env.erb CHANGED
@@ -1,5 +1,4 @@
1
1
  AWS_ACCOUNT_ID="<%= account_id %>"
2
2
  AWS_REGION="<%= region %>"
3
3
  ENVIRONMENT="test"
4
- GITHUB_REPOSITORY="https://github.com/dennisvink/elastic-cloud-engineering/"
5
4
  PROJECT_NAME="<%= project_name %>"
@@ -0,0 +1,6 @@
1
+ # ENV vars for production environment
2
+ CLOUD_TRAIL_MONITOR_SNS_RECIPIENTS="changeme@example.com,changemetoo@example.com"
3
+ ROOT_MONITOR_SNS_RECIPIENTS="changeme@example.com,changemetoo@example.com"
4
+ VPC_CIDR_BLOCK="10.200.0.0/16"
5
+ ARTIFACT_BUCKET="my-awesome-cloudformation-artifact-bucket-for-production"
6
+ STACK_NAME="production"
@@ -0,0 +1,6 @@
1
+ # ENV vars for rspec environment
2
+ CLOUD_TRAIL_MONITOR_SNS_RECIPIENTS="should@match"
3
+ ROOT_MONITOR_SNS_RECIPIENTS="should@match"
4
+ VPC_CIDR_BLOCK="10.0.0.0/16"
5
+ ARTIFACT_BUCKET="my-mock-bucket"
6
+ STACK_NAME="rspec"
@@ -1,2 +1,6 @@
1
1
  # ENV vars for test environment
2
- SOME_ENV_VAR="my-awesome-s3-bucket-for-<%= project_name %>-test"
2
+ CLOUD_TRAIL_MONITOR_SNS_RECIPIENTS="changeme@example.com,changemetoo@example.com"
3
+ ROOT_MONITOR_SNS_RECIPIENTS="changeme@example.com,changemetoo@example.com"
4
+ VPC_CIDR_BLOCK="10.100.0.0/16"
5
+ ARTIFACT_BUCKET="my-awesome-cloudformation-artifact-bucket"
6
+ STACK_NAME="test"
@@ -0,0 +1,82 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ .idea/
5
+ /coverage/
6
+ /InstalledFiles
7
+ /pkg/
8
+ /spec/reports/
9
+ /spec/examples.txt
10
+ /test/tmp/
11
+ /test/version_tmp/
12
+ /tmp/
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+ *.bridgesupport
17
+ build-iPhoneOS/
18
+ build-iPhoneSimulator/
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+ /.bundle/
24
+ /vendor/bundle
25
+ /lib/bundler/man/
26
+ .rvmrc
27
+ Thumbs.db
28
+ ehthumbs.db
29
+ ehthumbs_vista.db
30
+ *.stackdump
31
+ [Dd]esktop.ini
32
+ $RECYCLE.BIN/
33
+ *.cab
34
+ *.msi
35
+ *.msix
36
+ *.msm
37
+ *.msp
38
+ *.lnk
39
+ .DS_Store
40
+ .AppleDouble
41
+ .LSOverride
42
+ Icon
43
+ ._*
44
+ .DocumentRevisions-V100
45
+ .fseventsd
46
+ .Spotlight-V100
47
+ .TemporaryItems
48
+ .Trashes
49
+ .VolumeIcon.icns
50
+ .com.apple.timemachine.donotpresent
51
+ .AppleDB
52
+ .AppleDesktop
53
+ Network Trash Folder
54
+ Temporary Items
55
+ .apdisk
56
+ *~
57
+ .fuse_hidden*
58
+ .directory
59
+ .Trash-*
60
+ .nfs*
61
+ [._]*.s[a-v][a-z]
62
+ [._]*.sw[a-p]
63
+ [._]s[a-v][a-z]
64
+ [._]sw[a-p]
65
+ Session.vim
66
+ .netrwhist
67
+ *~
68
+ tags
69
+ [._]*.un~
70
+ cmake-build-debug/
71
+ cmake-build-release/
72
+ *.iws
73
+ out/
74
+ atlassian-ide-plugin.xml
75
+ com_crashlytics_export_strings.xml
76
+ crashlytics.properties
77
+ crashlytics-build.properties
78
+ fabric.properties
79
+ .env.private
80
+ test-reports
81
+ temp/
82
+ attic/
@@ -0,0 +1,75 @@
1
+ image: rubycfn/rubycfn:latest
2
+
3
+ before_script:
4
+ - bundle
5
+
6
+ variables:
7
+ CFN_ARTIFACT_BUCKET: "my-awesome-cloudformation-bucket"
8
+ STAGING_AWS_REGION: eu-west-1
9
+ PROD_AWS_REGION: eu-west-1
10
+
11
+ stages:
12
+ - build
13
+ - test
14
+ - upload
15
+ - staging
16
+ - production
17
+
18
+ build:
19
+ stage: build
20
+ variables:
21
+ ARTIFACT_BUCKET: ${CFN_ARTIFACT_BUCKET}
22
+ script:
23
+ - export SLACK_WEBHOOK=$K8S_SECRET_SLACK_POST_HOOK
24
+ - ENVIRONMENT="test" rake compile
25
+ - ENVIRONMENT="production" rake compile
26
+ - rubocop
27
+ - cfn_nag_scan --input-path build/ || true
28
+ artifacts:
29
+ paths:
30
+ - build/
31
+
32
+ test:
33
+ stage: test
34
+ script:
35
+ - rake spec
36
+ dependencies:
37
+ - build
38
+
39
+ upload:
40
+ stage: upload
41
+ variables:
42
+ ARTIFACT_BUCKET: ${CFN_ARTIFACT_BUCKET}
43
+ AWS_REGION: ${STAGING_AWS_REGION}
44
+ script:
45
+ - export AWS_SECRET_ACCESS_KEY=$K8S_SECRET_AWS_SECRET_ACCESS_KEY
46
+ - export AWS_ACCESS_KEY_ID=$K8S_SECRET_AWS_ACCESS_KEY_ID
47
+ - ENVIRONMENT="test" rake upload
48
+ - ENVIRONMENT="production" rake upload
49
+
50
+ deploy_staging:
51
+ stage: staging
52
+ variables:
53
+ ARTIFACT_BUCKET: ${CFN_ARTIFACT_BUCKET}
54
+ AWS_REGION: ${STAGING_AWS_REGION}
55
+ script:
56
+ - export AWS_SECRET_ACCESS_KEY=$K8S_SECRET_AWS_SECRET_ACCESS_KEY
57
+ - export AWS_ACCESS_KEY_ID=$K8S_SECRET_AWS_ACCESS_KEY_ID
58
+ - export ENVIRONMENT="test"
59
+ - rake apply
60
+ allow_failure: false
61
+
62
+ deploy_prod:
63
+ stage: production
64
+ variables:
65
+ ARTIFACT_BUCKET: ${CFN_ARTIFACT_BUCKET}
66
+ AWS_REGION: ${PROD_AWS_REGION}
67
+ script:
68
+ - export AWS_SECRET_ACCESS_KEY=$K8S_SECRET_AWS_SECRET_ACCESS_KEY
69
+ - export AWS_ACCESS_KEY_ID=$K8S_SECRET_AWS_ACCESS_KEY_ID
70
+ - export ENVIRONMENT="production"
71
+ - rake apply
72
+ dependencies:
73
+ - deploy_staging
74
+ when: manual
75
+ allow_failure: false
@@ -0,0 +1,91 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+
4
+ DisplayCopNames: true
5
+ Include:
6
+ - "Gemfile"
7
+ - "Rakefile"
8
+ - "bin/*"
9
+ - "*.gemspec"
10
+ - "lib/**/*.rb"
11
+ Exclude:
12
+ - "test/**/*.rb"
13
+ - "spec/**/*.rb"
14
+
15
+ Metrics/AbcSize:
16
+ Max: 500
17
+ Exclude:
18
+ - "test/**/*"
19
+ - "spec/**/*"
20
+
21
+ Metrics/ClassLength:
22
+ Max: 500
23
+ Exclude:
24
+ - "test/**/*"
25
+ - "spec/**/*"
26
+
27
+ Metrics/CyclomaticComplexity:
28
+ Max: 40
29
+ Exclude:
30
+ - "test/**/*"
31
+ - "spec/**/*"
32
+
33
+ Style/Documentation:
34
+ Enabled: false
35
+
36
+ Metrics/LineLength:
37
+ Max: 500
38
+ Exclude:
39
+ - "test/**/*"
40
+ - "spec/**/*"
41
+
42
+ Metrics/ModuleLength:
43
+ Max: 500
44
+
45
+ Metrics/MethodLength:
46
+ Max: 40
47
+
48
+ Metrics/BlockLength:
49
+ Max: 500
50
+
51
+ Performance/Casecmp:
52
+ Enabled: false
53
+
54
+ Style/DoubleNegation:
55
+ Enabled: false
56
+
57
+ Style/StringLiterals:
58
+ EnforcedStyle: double_quotes
59
+
60
+ Style/StringLiteralsInInterpolation:
61
+ EnforcedStyle: double_quotes
62
+
63
+ Style/Next:
64
+ Enabled: false
65
+
66
+ Style/FrozenStringLiteralComment:
67
+ Enabled: false
68
+
69
+ Security/MarshalLoad:
70
+ Enabled: false
71
+
72
+ Style/PercentLiteralDelimiters:
73
+ PreferredDelimiters:
74
+ default: '()'
75
+ '%i': '()'
76
+ '%w': '()'
77
+
78
+ Style/ExpandPathArguments:
79
+ Enabled: false
80
+
81
+ Style/RescueStandardError:
82
+ EnforcedStyle: "implicit"
83
+
84
+ Style/IfUnlessModifier:
85
+ Enabled: false
86
+
87
+ Style/DateTime:
88
+ Enabled: false
89
+
90
+ Layout/SpaceInsideHashLiteralBraces:
91
+ EnforcedStyle: space
@@ -1,9 +1,17 @@
1
1
  source "https://rubygems.org" do
2
- gem "rubycfn", "~> <%= version %>"
3
- gem "rspec", "~> 3.2"
4
- gem "rspec-its", "~> 1.2"
5
- gem "rspec-given", "~> 3.7"
2
+ gem "aws-sdk", "~> 3.0.1"
3
+ gem "aws-sdk-s3", "~> 1.36.0"
4
+ gem "colorize", "~> 0.8.1"
5
+ gem "diffy", "~> 3.3.0"
6
+ gem "git-revision", "~> 0.0.2"
7
+ gem "launchy", "~> 2.4.3"
8
+ gem "rspec", "~> 3.8"
9
+ gem "rspec-expectations", "~> 3.8", ">= 3.8.3"
10
+ gem "rspec-given", "~> 3.8"
11
+ gem "rspec-its", "~> 1.3"
12
+ gem "rspec-mocks", "~> 3.8"
6
13
  gem "rspec_junit_formatter", "~> 0.2"
14
+ gem "rubocop", "~> 0.57.1"
15
+ gem "rubycfn", "~> <%= version %>"
7
16
  gem "simplecov", "~> 0.16.1"
8
- gem "launchy", "~> 2.4.3"
9
17
  end
@@ -1,6 +1,9 @@
1
1
  require "rubygems"
2
2
  require "bundler"
3
3
  require "rspec/core/rake_task"
4
+ require "rubocop/rake_task"
5
+
6
+ Bundler.setup
4
7
 
5
8
  RSpec::Core::RakeTask.new do |t|
6
9
  t.rspec_opts = \
@@ -8,10 +11,40 @@ RSpec::Core::RakeTask.new do |t|
8
11
  " --out test-reports/rspec.xml"
9
12
  end
10
13
 
14
+ desc "Apply CloudFormation template"
15
+ task :apply do
16
+ require_relative "lib/main"
17
+ require_relative "lib/core/deploy"
18
+ end
19
+
20
+ desc "Upload stacks to s3"
21
+ task :upload do
22
+ require_relative "lib/main"
23
+ require_relative "lib/core/upload"
24
+ end
25
+
26
+ desc "Clean build directory"
27
+ task :clean do
28
+ Dir.foreach("build/") do |f|
29
+ fn = File.join("build/", f)
30
+ File.delete(fn) if f != "." && f != ".."
31
+ end
32
+ end
33
+
34
+ desc "Diff CloudFormation template"
35
+ task :diff do
36
+ require_relative "lib/main"
37
+ require_relative "lib/core/diff"
38
+ end
39
+
11
40
  desc "Compile CloudFormation"
12
41
  task :compile do
13
42
  require_relative "lib/main"
14
- require_relative "lib/compile"
43
+ require_relative "lib/core/compile"
44
+ end
45
+
46
+ RuboCop::RakeTask.new(:rubocop) do |t|
47
+ t.options = ["--display-cop-names"]
15
48
  end
16
49
 
17
50
  task default: %i(spec compile)
@@ -0,0 +1,18 @@
1
+ def create_bucket_if_not_exists(aws_region, artifact_bucket)
2
+ s3 = Aws::S3::Resource.new(region: aws_region)
3
+ begin
4
+ s3.create_bucket(bucket: artifact_bucket)
5
+ rescue => exception
6
+ raise exception unless exception.class == Aws::S3::Errors::BucketAlreadyOwnedByYou
7
+ end
8
+ s3
9
+ end
10
+
11
+ def set_aws_credentials(region, access_key_id, secret_access_key)
12
+ Aws.config.update(
13
+ region: region,
14
+ credentials: Aws::Credentials.new(
15
+ access_key_id, secret_access_key
16
+ )
17
+ )
18
+ end