rubycfn 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29062bf33bd5efb1396cbeceb1377db608577eaf
4
- data.tar.gz: ce1c38eb6a9160a03ecc284fa17e6b80f2cdef8c
3
+ metadata.gz: c09925e14474150813c8cc1fc68f659c2fd9b4f6
4
+ data.tar.gz: 147d961011de3e4452b273cd9d7192fa14bfa50a
5
5
  SHA512:
6
- metadata.gz: bcc956f265c0d06d16d1b2b53e06273c9abec57005ee83a2c50b13ce0016e4ee83a44452b49b3e7dc46f5b0081d5c365547d624f53efc01ebe8773cfdb93e5df
7
- data.tar.gz: c7edb919f6eebee33003ea1ad8aa780e9d52e83708c7421828148fa20eb523d1855cc4f6317526e3257afc3542fb8136f984fcf36470ddb4a0101ac4dbe633e1
6
+ metadata.gz: a2d9cc012275a915b20b7ceaaf952d40d741d74b1efb5b22f5d84c62d448e000f9ad021607a53a12ed4e94d252331ece33cb6725fb3ce0af9a90e3c85b8d5fad
7
+ data.tar.gz: 4f4fd5565902584c1568bb5ed8198783a2f3ba6befe96a3a20d9de65206ddf2c6b4ccc46f261ec1d9fafb65d3fea5e26e2aa19c2cd3ad68bb260508c9293d985
data/Gemfile.lock CHANGED
@@ -1,10 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubycfn (0.1.0)
4
+ rubycfn (0.1.1)
5
5
  activesupport (~> 5.1.5)
6
+ dotenv (~> 2.4.0)
6
7
  json (~> 2.1.0)
7
8
  neatjson (~> 0.8.4)
9
+ tty-prompt (~> 0.16.0)
8
10
 
9
11
  GEM
10
12
  remote: https://rubygems.org/
@@ -21,6 +23,8 @@ GEM
21
23
  concurrent-ruby (1.0.5)
22
24
  diff-lcs (1.3)
23
25
  docile (1.3.1)
26
+ dotenv (2.4.0)
27
+ equatable (0.5.0)
24
28
  ffi (1.9.25)
25
29
  formatador (0.2.5)
26
30
  given_core (3.8.0)
@@ -39,6 +43,7 @@ GEM
39
43
  guard (~> 2.1)
40
44
  guard-compat (~> 1.1)
41
45
  rspec (>= 2.99.0, < 4.0)
46
+ hitimes (1.3.0)
42
47
  i18n (1.0.1)
43
48
  concurrent-ruby (~> 1.0)
44
49
  json (2.1.0)
@@ -52,10 +57,14 @@ GEM
52
57
  method_source (0.9.0)
53
58
  minitest (5.11.3)
54
59
  neatjson (0.8.4)
60
+ necromancer (0.4.0)
55
61
  nenv (0.3.0)
56
62
  notiffany (0.1.1)
57
63
  nenv (~> 0.1)
58
64
  shellany (~> 0.0)
65
+ pastel (0.7.2)
66
+ equatable (~> 0.5.0)
67
+ tty-color (~> 0.4.0)
59
68
  pry (0.11.3)
60
69
  coderay (~> 1.1.0)
61
70
  method_source (~> 0.9.0)
@@ -95,8 +104,24 @@ GEM
95
104
  sorcerer (1.0.2)
96
105
  thor (0.20.0)
97
106
  thread_safe (0.3.6)
107
+ timers (4.1.2)
108
+ hitimes
109
+ tty-color (0.4.2)
110
+ tty-cursor (0.5.0)
111
+ tty-prompt (0.16.1)
112
+ necromancer (~> 0.4.0)
113
+ pastel (~> 0.7.0)
114
+ timers (~> 4.0)
115
+ tty-cursor (~> 0.5.0)
116
+ tty-reader (~> 0.3.0)
117
+ tty-reader (0.3.0)
118
+ tty-cursor (~> 0.5.0)
119
+ tty-screen (~> 0.6.4)
120
+ wisper (~> 2.0.0)
121
+ tty-screen (0.6.4)
98
122
  tzinfo (1.2.5)
99
123
  thread_safe (~> 0.1)
124
+ wisper (2.0.0)
100
125
 
101
126
  PLATFORMS
102
127
  ruby
data/README.md CHANGED
@@ -12,10 +12,14 @@ or, create a Gemfile with this content:
12
12
  ```
13
13
  source "https://rubygems.org"
14
14
 
15
- gem "rubycfn", "~> 0.1.0"
15
+ gem "rubycfn", "~> 0.1.1"
16
16
 
17
17
  ```
18
18
 
19
+ ## Starting a new project
20
+
21
+ Typing `rubycfn` at the prompt and answering its questions generates a new sample project.
22
+
19
23
  ## Example code
20
24
 
21
25
  You can find stack examples at [https://github.com/dennisvink/rubycfn-example](https://github.com/dennisvink/rubycfn-example/)
data/bin/rubycfn ADDED
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "erb"
4
+ require 'fileutils'
5
+ require 'ostruct'
6
+ require "tty-prompt"
7
+ require "rubycfn/version"
8
+
9
+ require_relative "../lib/cli_methods"
10
+
11
+ path = File.expand_path(File.dirname(File.dirname(__FILE__)))
12
+ puts rubycfn_banner(Rubycfn::VERSION)
13
+ prompt = TTY::Prompt.new
14
+
15
+ project_name = prompt.ask('Project name?', default: 'example') do |q|
16
+ q.validate(/^([a-z0-9]*)$/, 'Invalid project name')
17
+ end
18
+
19
+ project_path = project_name + '-rubycfn'
20
+
21
+ account_id = prompt.ask('AWS Account ID?', default: '1234567890') do |q|
22
+ q.validate(/^([0-9]*)$/, 'Invalid account id')
23
+ end
24
+
25
+ region = prompt.select(
26
+ "Select AWS region", aws_regions
27
+ )
28
+
29
+ dotenv = render('.env', {
30
+ :project_name => project_name,
31
+ :account_id => account_id,
32
+ :region => region
33
+ }, path)
34
+
35
+ dotenv_test = render('.env.test', { project_name: project_name }, path)
36
+ gemfile = render('Gemfile', { version: Rubycfn::VERSION }, path)
37
+ rakefile = render('Rakefile', {}, path)
38
+ main = render('main.rb', {}, path)
39
+ compile = render('compile.rb', {}, path)
40
+ global_variables = render('global_variables.rb', {}, path)
41
+ project_stack = render('project_stack.rb', { name: project_name.capitalize }, path)
42
+ project_concern = render('project_concern.rb', { name: project_name.capitalize }, path)
43
+
44
+ # Create directory structure
45
+ FileUtils.mkdir_p project_path + '/lib/stacks/' + project_name + '_stack'
46
+ rubycfn_structure(project_path).each do |dir|
47
+ FileUtils.mkdir_p dir
48
+ end
49
+
50
+ File.open("#{project_path}/.env", 'w') { |file| file.write(dotenv) }
51
+ File.open("#{project_path}/.env.test", 'w') { |file| file.write(dotenv_test) }
52
+ File.open("#{project_path}/Gemfile", 'w') { |file| file.write(gemfile) }
53
+ File.open("#{project_path}/Rakefile", 'w') { |file| file.write(rakefile) }
54
+ File.open("#{project_path}/lib/main.rb", 'w') { |file| file.write(main) }
55
+ File.open("#{project_path}/lib/compile.rb", 'w') { |file| file.write(compile) }
56
+ File.open("#{project_path}/lib/shared_concerns/global_variables.rb", 'w') { |file| file.write(global_variables) }
57
+ File.open("#{project_path}/lib/stacks/#{project_name}_stack.rb", 'w') { |file| file.write(project_stack) }
58
+ File.open("#{project_path}/lib/stacks/#{project_name}_stack/example.rb", 'w') { |file| file.write(project_concern) }
59
+
@@ -0,0 +1,45 @@
1
+ def render(file, vars, path)
2
+ template = File.read("#{path}/templates/#{file}.erb")
3
+ ERB.new(template).result(OpenStruct.new(vars).instance_eval { binding })
4
+ end
5
+
6
+ def aws_regions
7
+ [
8
+ { name: "US East (N. Virginia)", value: "us-east-1" },
9
+ { name: "US East (Ohio)", value: "us-east-2" },
10
+ { name: "US West (N. California)", value: "us-west-1" },
11
+ { name: "US West (Oregon)", value: "us-west-2" },
12
+ { name: "Canada (Central)", value: "ca-central-1" },
13
+ { name: "EU (Frankfurt)", value: "eu-central-1" },
14
+ { name: "EU (Ireland)", value: "eu-west-1" },
15
+ { name: "EU (London)", value: "eu-west-2" },
16
+ { name: "EU (Paris)", value: "eu-west-3" },
17
+ { name: "Asia Pacific (Tokyo)", value: "ap-northeast-1" },
18
+ { name: "Asia Pacific (Seoul)", value: "ap-northeast-2" },
19
+ { name: "Asia Pacific (Osaka-Local)", value: "ap-northeast-3" },
20
+ { name: "Asia Pacific (Singapore)", value: "ap-southeast-1" },
21
+ { name: "Asia Pacific (Sydney)", value: "ap-southeast-2" },
22
+ { name: "Asia Pacific (Mumbai)", value: "ap-south-1" },
23
+ { name: "South America (São Paulo)", value: "sa-east-1" }
24
+ ]
25
+ end
26
+
27
+ def rubycfn_banner(version)
28
+ [
29
+ "__________ ____ __________________.___._________ _____________________ ",
30
+ "\\______ \\ | \\______ \\__ | |\\_ ___ \\\\_ _____/\\______ \\",
31
+ " | _/ | /| | _// | |/ \\ \\/ | __) | | _/",
32
+ " | | \\ | / | | \\\\____ |\\ \\____| \\ | | \\",
33
+ " |____|_ /______/ |______ // ______| \\______ /\\___ / |______ /",
34
+ " \\/ \\/ \\/ \\/ \\/ \\/ [v#{version}]"
35
+ ].join("\n")
36
+ end
37
+
38
+ def rubycfn_structure(project_name)
39
+ [
40
+ project_name,
41
+ project_name + '/build',
42
+ project_name + '/lib/stacks',
43
+ project_name + '/lib/shared_concerns'
44
+ ]
45
+ end
@@ -1,4 +1,4 @@
1
1
  # Rubycfn version
2
2
  module Rubycfn
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
data/rubycfn.gemspec CHANGED
@@ -14,12 +14,15 @@ Gem::Specification.new do |spec|
14
14
  spec.required_ruby_version = ">= 2.2.0"
15
15
  spec.license = "MIT"
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
18
  spec.test_files = spec.files.grep(/(?:test|spec|features)/)
18
19
  spec.require_paths = ["lib"]
19
20
 
20
21
  spec.add_runtime_dependency "neatjson", "~> 0.8.4"
21
22
  spec.add_runtime_dependency "json", "~> 2.1.0"
22
23
  spec.add_runtime_dependency "activesupport", "~> 5.1.5"
24
+ spec.add_runtime_dependency "tty-prompt", "~> 0.16.0"
25
+ spec.add_runtime_dependency "dotenv", "~> 2.4.0"
23
26
 
24
27
  spec.add_development_dependency "awesome_print", "~> 1.2"
25
28
  spec.add_development_dependency "bundler", "~> 1.7"
@@ -0,0 +1,4 @@
1
+ AWS_ACCOUNT_ID="<%= account_id %>"
2
+ AWS_REGION="<%= region %>"
3
+ PROJECT_NAME="<%= project_name %>"
4
+ ENVIRONMENT="test"
@@ -0,0 +1,2 @@
1
+ # ENV vars for test environment
2
+ SOME_ENV_VAR="my-awesome-s3-bucket-for-<%= project_name %>-test"
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org' do
2
+ gem 'rubycfn', '~> <%= version %>'
3
+ end
@@ -0,0 +1,11 @@
1
+ require "rubygems"
2
+ require "bundler"
3
+ Bundler.setup
4
+
5
+ desc "Compile CloudFormation"
6
+ task :compile do
7
+ require_relative "lib/main"
8
+ require_relative "lib/compile"
9
+ end
10
+
11
+ task default: [:compile]
@@ -0,0 +1,16 @@
1
+ require 'fileutils'
2
+
3
+ FileUtils.mkdir_p 'build'
4
+
5
+ stacks = {}
6
+ Module.constants.select do |mod|
7
+ if mod =~ /Stack$/
8
+ send("include", Object.const_get("SharedConcerns"))
9
+ stacks[mod.to_sym] = send("include", Object.const_get(mod)).render_template
10
+ end
11
+ end
12
+
13
+ stacks.each do |stack_name, stack|
14
+ puts "- Saved #{stack_name} to build/#{stack_name.downcase}.json"
15
+ File.open("build/#{stack_name.downcase}.json", "w") { |f| f.write(stack) }
16
+ end
@@ -0,0 +1,12 @@
1
+ module Concerns
2
+ module GlobalVariables
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ variable :environment,
7
+ default: "test",
8
+ global: true,
9
+ value: ENV["ENVIRONMENT"]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,30 @@
1
+ require "rubycfn"
2
+ require "dotenv"
3
+
4
+ Dotenv.load(".env")
5
+ Dotenv.load(".env.private")
6
+ Dotenv.load(".env.#{ENV["ENVIRONMENT"]}")
7
+
8
+ # Include all group concerns
9
+ Dir[File.expand_path('../shared_concerns/', __FILE__) + '/*.rb'].sort.each do |file|
10
+ require file
11
+ end
12
+
13
+ # SharedConcerns module is injected in each stack
14
+ module SharedConcerns
15
+ extend ActiveSupport::Concern
16
+ include Rubycfn
17
+
18
+ included do
19
+ include Concerns::GlobalVariables
20
+ end
21
+ end
22
+
23
+ # Include all stack concerns
24
+ Dir[File.expand_path('../stacks/', __FILE__) + '/*.rb'].sort.each do |file|
25
+ subdir = File.basename(file, ".rb")
26
+ Dir[File.expand_path('../stacks/', __FILE__) + "/#{subdir}/*.rb"].sort.each do |subfile|
27
+ require subfile
28
+ end
29
+ require file
30
+ end
@@ -0,0 +1,42 @@
1
+ module <%= name %>Stack
2
+ module Main
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ # Example stack parameter
7
+ #parameter :example_stack_parameter_name,
8
+ # default: "example_value"
9
+
10
+ # Example variable
11
+ variable :example_variable,
12
+ required: false,
13
+ value: ENV["SOME_ENV_VAR"],
14
+ default: "default_value"
15
+
16
+ # Example resource, custom name
17
+ resource :my_example_s3_bucket,
18
+ type: "AWS::S3::Bucket" do |r|
19
+ #r.depends_on "SomeLogicalResourceName"
20
+ r.property(:name) { example_variable }
21
+ end
22
+
23
+ # Example resource, dynamically generated name
24
+ resource :my_example_s3_bucket,
25
+ type: "AWS::S3::Bucket"
26
+
27
+ # Multiple resources of the same type
28
+ resource :my_sqs_queue,
29
+ amount: 3,
30
+ type: "AWS::SQS::Queue"
31
+
32
+ queue_names = %w(MyFirstQueue MySecondQueue)
33
+
34
+ # Multiple resources with index, starts at 0
35
+ resource :sqs_with_index,
36
+ amount: 2,
37
+ type: "AWS::SQS::Queue" do |r, index|
38
+ r.property(:queue_name) { queue_names[index] }
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,8 @@
1
+ module <%= name %>Stack
2
+ extend ActiveSupport::Concern
3
+ include Rubycfn
4
+
5
+ included do
6
+ include <%= name %>Stack::Main
7
+ end
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubycfn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Vink
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-24 00:00:00.000000000 Z
11
+ date: 2018-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: neatjson
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 5.1.5
55
+ - !ruby/object:Gem::Dependency
56
+ name: tty-prompt
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.16.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.16.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: dotenv
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.4.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.4.0
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: awesome_print
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -223,7 +251,8 @@ dependencies:
223
251
  description: RubyCFN is a light-weight CloudFormation DSL
224
252
  email:
225
253
  - dennis@drvink.com
226
- executables: []
254
+ executables:
255
+ - rubycfn
227
256
  extensions: []
228
257
  extra_rdoc_files: []
229
258
  files:
@@ -232,11 +261,22 @@ files:
232
261
  - Gemfile.lock
233
262
  - README.md
234
263
  - Rakefile
264
+ - bin/rubycfn
265
+ - lib/cli_methods.rb
235
266
  - lib/rubycfn.rb
236
267
  - lib/rubycfn/version.rb
237
268
  - rubycfn.gemspec
238
269
  - spec/lib/rubycfn_spec.rb
239
270
  - spec/spec_helper.rb
271
+ - templates/.env.erb
272
+ - templates/.env.test.erb
273
+ - templates/Gemfile.erb
274
+ - templates/Rakefile.erb
275
+ - templates/compile.rb.erb
276
+ - templates/global_variables.rb.erb
277
+ - templates/main.rb.erb
278
+ - templates/project_concern.rb.erb
279
+ - templates/project_stack.rb.erb
240
280
  homepage: https://github.com/dennisvink/rubycfn
241
281
  licenses:
242
282
  - MIT
@@ -265,3 +305,4 @@ test_files:
265
305
  - rubycfn.gemspec
266
306
  - spec/lib/rubycfn_spec.rb
267
307
  - spec/spec_helper.rb
308
+ - templates/.env.test.erb