kurgan 0.2.0 → 0.4.0

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
  SHA256:
3
- metadata.gz: 85a9e2245bfe3886184f93bae66f16c5f8b565354ada5319f9ce5e0c40fd9775
4
- data.tar.gz: 5e8ae3b2bd577f44ee6c0f11999a67dbb3674a3f07c4d52c7f88a1f50bd08fae
3
+ metadata.gz: 488e05edbe120ded7cbfb9dbaa7b751fc4cc168192d4ac63e31d107481073587
4
+ data.tar.gz: c57b6526b9b8e69b73c7089619337d6e2cc4575d9f72a8a65a36850b02b32881
5
5
  SHA512:
6
- metadata.gz: c610c92985b8211e380fcd6597ed24a151af72eda13142812618ac37db87d7c9328757b2d94e3fb3ff3c0c5710af129226eaa827d062ea1551c3a23acacc6917
7
- data.tar.gz: ff7b9e28fa2496a129f1dbbcff7157b52ce394dcadad23fd1992c3702c6c8e7ae2e4f3aa343d41260d575492c80760ded2c1c665aa9e3d8fe7019014e366a9d0
6
+ metadata.gz: df9a706171fd7bd1d722cb43f9e8bac729514fb2fec973d47a03d342e453e39817f31aa9271029dca782948f4f6129e9f4c9a38b4c3e31ab149a31d44cccf1b3
7
+ data.tar.gz: 05d00def80a4cd83c51feab7b94602b27e29cb2c4de1526577d5016391ae2afd2fe465d63c02f56d034a124072caaec3a8dc9da89f18b0a5cac3c07f4492ee94
@@ -0,0 +1,25 @@
1
+ name: test and build gem
2
+ on:
3
+ push:
4
+ branches: [ master ]
5
+ pull_request:
6
+ branches: [ master ]
7
+
8
+ jobs:
9
+ build:
10
+ name: test + build
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - name: set up ruby 2.7
16
+ uses: actions/setup-ruby@v1
17
+ with:
18
+ ruby-version: 2.7.x
19
+ - name: rspec
20
+ run: |
21
+ gem install rspec
22
+ rspec
23
+ - name: build gem
24
+ run: |
25
+ gem build kurgan.gemspec
@@ -0,0 +1,24 @@
1
+ name: release gem
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ build:
9
+ name: Build and publish gem
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - name: Check out the repo
14
+ uses: actions/checkout@v2
15
+
16
+ - name: Set up ruby 2.7
17
+ uses: actions/setup-ruby@v1
18
+ with:
19
+ ruby-version: 2.7.x
20
+
21
+ - name: Publish gem
22
+ uses: dawidd6/action-publish-gem@v1
23
+ with:
24
+ api_key: ${{secrets.RUBYGEMS_API_KEY}}
data/Gemfile.lock CHANGED
@@ -1,14 +1,34 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kurgan (0.2.0)
4
+ kurgan (0.3.0)
5
+ faraday (~> 1, < 2)
6
+ terminal-table (~> 1, < 2)
5
7
  thor (~> 0.19)
6
8
 
7
9
  GEM
8
10
  remote: https://rubygems.org/
9
11
  specs:
10
- rake (10.5.0)
12
+ faraday (1.4.3)
13
+ faraday-em_http (~> 1.0)
14
+ faraday-em_synchrony (~> 1.0)
15
+ faraday-excon (~> 1.1)
16
+ faraday-net_http (~> 1.0)
17
+ faraday-net_http_persistent (~> 1.1)
18
+ multipart-post (>= 1.2, < 3)
19
+ ruby2_keywords (>= 0.0.4)
20
+ faraday-em_http (1.0.0)
21
+ faraday-em_synchrony (1.0.0)
22
+ faraday-excon (1.1.0)
23
+ faraday-net_http (1.0.1)
24
+ faraday-net_http_persistent (1.2.0)
25
+ multipart-post (2.1.1)
26
+ rake (13.0.1)
27
+ ruby2_keywords (0.0.5)
28
+ terminal-table (1.8.0)
29
+ unicode-display_width (~> 1.1, >= 1.1.1)
11
30
  thor (0.20.3)
31
+ unicode-display_width (1.7.0)
12
32
 
13
33
  PLATFORMS
14
34
  ruby
@@ -16,7 +36,7 @@ PLATFORMS
16
36
  DEPENDENCIES
17
37
  bundler (~> 2.0)
18
38
  kurgan!
19
- rake (~> 10.0)
39
+ rake (~> 13.0)
20
40
 
21
41
  BUNDLED WITH
22
- 2.0.1
42
+ 2.1.4
data/README.md CHANGED
@@ -1,20 +1,244 @@
1
1
  # Kurgan
2
2
  ---
3
+ ![build workflow](https://github.com/theonestack/kurgan/actions/workflows/build-gem.yml/badge.svg)
4
+ ![release workflow](https://github.com/theonestack/kurgan/actions/workflows/release-gem.yml/badge.svg)
3
5
 
4
- [![Build Status](https://travis-ci.com/theonestack/kurgan.svg?branch=master)](https://travis-ci.com/theonestack/kurgan) [![Join the chat at https://gitter.im/theonestack/cfhighlander](https://badges.gitter.im/theonestack/cfhighlander.svg)](https://gitter.im/theonestack/cfhighlander?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
6
+ Command line tool to create and manage CfHighlander projects and components
5
7
 
6
- Tool to manage CfHighlander stacks
8
+ ## Setup
9
+
10
+ ```sh
11
+ gem install kurgan
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ### Help
17
+
18
+ view all available commands
7
19
 
8
20
  ```bash
21
+ ➜ kurgan help
9
22
  Commands:
10
- kurgan --version, -v # print the version
11
- kurgan add [component] # Adds a new component to an existing CfHighlander project
12
- kurgan component [name] # Generates a new CfHighlander component
13
- kurgan help [COMMAND] # Describe available commands or one specific command
14
- kurgan list # List available components and latest version from theonestack github
15
- kurgan project [name] # Generates a new CfHighlander project
23
+ kurgan --version, -v # print the version
24
+ kurgan add [component] # Adds a new component to an existing CfHighlander project
25
+ kurgan component [name] # Generates a new CfHighlander component
26
+ kurgan extend [component] # Generates a files to extend a component in a CfHighlander project
27
+ kurgan help [COMMAND] # Describe available commands or one specific command
28
+ kurgan inspect # inspect a cfhighlander files of it's components
29
+ kurgan list # list all components in the onestack
30
+ kurgan project [name] # Generates a new CfHighlander project
31
+ kurgan search [component] # search for a component and it's release history
32
+ kurgan test [name] # Create a new test case for a component
33
+ ```
34
+
35
+ help can also be used on commands to see available options and usage
36
+
37
+ ```bash
38
+ ➜ kurgan help project
39
+ Usage:
40
+ kurgan project [name]
41
+
42
+ Options:
43
+ -p, [--project=PROJECT] # Create a pre-canned project
44
+ # Default: empty
45
+ # Possible values: empty, vpc, ecs
46
+
47
+ Generates a new CfHighlander project
48
+ ```
49
+
50
+ ### Create a New Project
51
+
52
+ A CfHighlander project allows you to configure and compile a group of components to generate you Cloudformation stack.
53
+
54
+ To create a new project run the `project` command with the name of your new project and fill in the prompts
55
+
56
+ ```sh
57
+ ➜ kurgan project myproject
58
+ directory name (myproject)
59
+ create myproject
60
+ template description (myproject)
61
+ create myproject/myproject.cfhighlander.rb
62
+ create myproject/myproject.config.yaml
63
+ git init project? y
64
+ run git init myproject from "."
65
+ Initialized empty Git repository in /Users/gus/src/testbed/hl/myproject/.git/
66
+ create myproject/.gitignore
67
+ create myproject/README.md
68
+ Setup a CI pipeline? y
69
+ CI flavour [github, jenkins, travis, codebuild] jenkins
70
+ create myproject/Jenkinsfile
71
+ ```
72
+
73
+ cd into the new directory and you'll see the following project structure
74
+
75
+ ```txt
76
+ .
77
+ ├── Jenkinsfile # depending on CI flavour this will be different
78
+ ├── README.md
79
+ ├── myproject.cfhighlander.rb
80
+ └── myproject.config.yaml
81
+ ```
82
+
83
+
84
+ ### Add a Component to a Project
85
+
86
+ To add a component to your nproject use the `add` command along with the component name with optional component version and friendly name
87
+
88
+ ```sh
89
+ ➜ myproject git:(master) ✗ kurgan add vpc-v2 --name network --version 0.7.0
90
+ adding vpc-v2@0.7.0 to the myproject project
91
+ insert myproject.cfhighlander.rb
92
+ create network.config.yaml
93
+ ```
94
+
95
+ this will create a yaml config file for the new component configuration and add the component to the `myproject.cfhighlander.rb` file
96
+
97
+ ```rb
98
+ CfhighlanderTemplate do
99
+ Name 'myproject'
100
+ Description "myproject"
101
+ Component name: 'network', template: 'vpc-v2@0.7.0'
102
+ end
103
+ ```
104
+
105
+
106
+ ### Extend a Component in a Project
107
+
108
+ Extending a component allows you to add resources to an existing component whilest still allowing you to update the component.
109
+
110
+ to extend a component use the `extend` command along with the component name with optional component version and friendly name
111
+
112
+ ```sh
113
+ ➜ myproject git:(master) ✗ kurgan extend aurora-mysql --name database --version 3.3.0
114
+ create database
115
+ extending aurora-mysql@3.3.0 to the myproject project
116
+ create database/database.cfhighlander.rb
117
+ create database/database.config.yaml
118
+ create database/database.cfndsl.rb
119
+ insert myproject.cfhighlander.rb
120
+ ```
121
+
122
+ this will create a new sub directory with a cfhighlander file containing the component you're extending, a cfndsl file to add your resources and a config.yaml for configuration
123
+
124
+ ```txt
125
+ .
126
+ ├── Jenkinsfile
127
+ ├── README.md
128
+ ├── database
129
+ │   ├── database.cfhighlander.rb
130
+ │   ├── database.cfndsl.rb
131
+ │   └── database.config.yaml
132
+ ├── myproject.cfhighlander.rb
133
+ ├── myproject.config.yaml
134
+ └── network.config.yaml
16
135
  ```
17
136
 
137
+ ```rb
138
+ CfhighlanderTemplate do
139
+ Name 'database'
140
+ Extends 'aurora-mysql@3.3.0'
141
+ end
142
+ ```
143
+
144
+
145
+ ### Inspect a Project
146
+
147
+ To see a list of components used by a project including versions and latest available version use the `inspect` command.
148
+
149
+ ```sh
150
+ ➜ myproject git:(master) ✗ kurgan inspect
151
+ +-----------+-----------+----------------+
152
+ | Project: myproject |
153
+ +-----------+-----------+----------------+
154
+ | Component | Version | Latest Release |
155
+ +-----------+-----------+----------------+
156
+ | vpc-v2 | 0.7.0 | 0.7.0 |
157
+ +-----------+-----------+----------------+
158
+ ```
159
+
160
+
161
+ ### Create a New Component
162
+
163
+ Components are the basic building blocks of CfHighlander, containing cloudformation resources that can be templated and reused across multiple project.
164
+
165
+ To create a new project use the `component` command with the name of your new component and fill in the prompts
166
+
167
+ ```txt
168
+ ➜ kurgan component rds-mysql
169
+ directory name (hl-component-rds-mysql)
170
+ create hl-component-rds-mysql
171
+ template description (rds-mysql - #{component_version})
172
+ create hl-component-rds-mysql/rds-mysql.cfhighlander.rb
173
+ create hl-component-rds-mysql/rds-mysql.config.yaml
174
+ git init project? y
175
+ run git init hl-component-rds-mysql from "."
176
+ Initialized empty Git repository in /Users/gus/src/testbed/hl/hl-component-rds-mysql/.git/
177
+ create hl-component-rds-mysql/.gitignore
178
+ create hl-component-rds-mysql/README.md
179
+ Setup a CI pipeline? y
180
+ CI flavour [github, jenkins, travis, codebuild] github
181
+ create hl-component-rds-mysql/.github/workflows/spec.yaml
182
+ create hl-component-rds-mysql/rds-mysql.cfndsl.rb
183
+ create hl-component-rds-mysql/tests/default.test.yaml
184
+ Use MIT license? y
185
+ create hl-component-rds-mysql/LICENSE
186
+ ```
187
+
188
+ the following folder structure is generated
189
+
190
+ ```txt
191
+ .
192
+ ├── LICENSE
193
+ ├── README.md
194
+ ├── rds-mysql.cfhighlander.rb
195
+ ├── rds-mysql.cfndsl.rb
196
+ ├── rds-mysql.config.yaml
197
+ └── tests
198
+ └── default.test.yaml
199
+ ```
200
+
201
+
202
+ ### Add tests to a Component
203
+
204
+ Kurgan can be used to add configuration tests to a component as well as generating spec tests based upon the cloudformation generated by a configuration test.
205
+
206
+ to create a new config test run the test command along with the name of the test
207
+
208
+ ```sh
209
+ ➜ hl-component-rds-mysql git:(master) ✗ kurgan test mytest
210
+ create tests/mytest.test.yaml
211
+ created config test case tests/mytest.test.yaml
212
+ ```
213
+
214
+ A test.yaml file is created in the tests directory, add in you test and run the `cfhighlander test` command to execute the test
215
+
216
+ Once the cftest has successfully passed you can then generate a spec test from the cloudformation template generated by the test in the `out/tests/<test-name>/` directory
217
+
218
+ To generate the spec test use the `test` command again with the name of the test and pass the `--type spec` flag
219
+
220
+ ```sh
221
+ ➜ hl-component-rds-mysql git:(master) ✗ kurgan test mytest --type spec
222
+ create spec/mytest_spec.rb
223
+ created spec test spec/mytest_spec.rb
224
+ ```
225
+
226
+
227
+ ### Searching for Components
228
+
229
+ to list all available components on the onestack use the `list` command
230
+
231
+ ```sh
232
+ ➜ kurgan list
233
+ ```
234
+
235
+ to search for a components releases use the `search [component]` command
236
+
237
+ ```sh
238
+ ➜ kurgan search vpc
239
+ ```
240
+
241
+
18
242
  ## License
19
243
 
20
244
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/kurgan.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
18
  # to allow pushing to a single host or delete this section to allow pushing to any host.
19
19
  if spec.respond_to?(:metadata)
20
- spec.metadata["allowed_push_host"] = "http://mygemserver.com"
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
21
  else
22
22
  raise "RubyGems 2.0 or newer is required to protect against " \
23
23
  "public gem pushes."
@@ -31,7 +31,9 @@ Gem::Specification.new do |spec|
31
31
  spec.require_paths = ["lib"]
32
32
 
33
33
  spec.add_dependency "thor", "~> 0.19"
34
+ spec.add_dependency "terminal-table", '~> 1', '<2'
35
+ spec.add_dependency "faraday", '~> 1', '<2'
34
36
 
35
37
  spec.add_development_dependency "bundler", "~> 2.0"
36
- spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "rake", "~> 13.0"
37
39
  end
data/lib/kurgan.rb CHANGED
@@ -7,6 +7,9 @@ require "kurgan/component"
7
7
  require "kurgan/add"
8
8
  require "kurgan/test"
9
9
  require "kurgan/list"
10
+ require "kurgan/extend"
11
+ require "kurgan/search"
12
+ require "kurgan/inspect"
10
13
 
11
14
  module Kurgan
12
15
  class Cli < Thor
@@ -26,18 +29,20 @@ module Kurgan
26
29
  register Kurgan::Add, 'add', 'add [component]', 'Adds a new component to an existing CfHighlander project'
27
30
  tasks["add"].options = Kurgan::Add.class_options
28
31
 
32
+ register Kurgan::Extend, 'extend', 'extend [component]', 'Generates a files to extend a component in a CfHighlander project'
33
+ tasks["extend"].options = Kurgan::Extend.class_options
34
+
29
35
  register Kurgan::Test, 'test', 'test [name]', 'Create a new test case for a component'
30
36
  tasks["test"].options = Kurgan::Test.class_options
31
37
 
32
- desc "list", "List available components and latest version from theonestack github"
33
- method_option :filter, aliases: '-f', type: :string, desc: "filter components by service type"
34
- method_option :component, aliases: '-c', type: :string, desc: "list all versions for matched components"
35
- method_option :update, aliases: '-u', type: :boolean, lazy_default: true, default: false, desc: "Update components list"
36
- def list
37
- cmd = Kurgan::List.new(options)
38
- cmd.execute
39
- end
38
+ register Kurgan::List, 'list', 'list', 'list all components in the onestack'
39
+ tasks["list"].options = Kurgan::List.class_options
40
+
41
+ register Kurgan::Search, 'search', 'search [component]', "search for a component and it's release history"
42
+ tasks["search"].options = Kurgan::Search.class_options
40
43
 
44
+ register Kurgan::Inspect, 'inspect', 'inspect', "inspect a cfhighlander files of it's components"
45
+ tasks["inspect"].options = Kurgan::Inspect.class_options
41
46
 
42
47
  end
43
48
  end
@@ -27,6 +27,10 @@ module Kurgan
27
27
  template('templates/cfndsl.rb.tt', "#{@dir}/#{name}.cfndsl.rb")
28
28
  end
29
29
 
30
+ def create_readme
31
+ template "templates/README.md.component.tt", "#{@dir}/README.md"
32
+ end
33
+
30
34
  def create_default_config_test
31
35
  @test_name = 'default'
32
36
  template('templates/test.yaml.tt', "#{@dir}/tests/#{@test_name}.test.yaml")
@@ -0,0 +1,47 @@
1
+ module Kurgan
2
+ class Extend < Thor::Group
3
+ include Thor::Actions
4
+
5
+ argument :component
6
+
7
+ class_option :name, aliases: :n, type: :string
8
+ class_option :version, aliases: :v, type: :string
9
+
10
+ def self.source_root
11
+ File.dirname(__FILE__)
12
+ end
13
+
14
+ def get_cfhighlander_template
15
+ @cfhighlander_template = Dir['*.cfhighlander.rb'][0]
16
+ if @cfhighlander_template.nil?
17
+ raise "No cfhighlander.rb file found in #{Dir.pwd}, are you in a cfhighlander project folder?"
18
+ end
19
+ end
20
+
21
+ def get_component_name
22
+ @name = options[:name] || component
23
+ end
24
+
25
+ def create_sub_dir_for_extended_component
26
+ empty_directory @name
27
+ end
28
+
29
+ def get_template_version
30
+ @template = options[:version] ? "#{component}@#{options[:version]}" : component
31
+ say "extending #{@template} to the #{@cfhighlander_template.split('.')[0]} project"
32
+ end
33
+
34
+ def create_cfhighlander_files
35
+ opts = {template: @template, name: @name}
36
+ template('templates/cfhighlander.extend.rb.tt', "#{@name}/#{@name}.cfhighlander.rb", opts)
37
+ template('templates/config.yaml.tt', "#{@name}/#{@name}.config.yaml")
38
+ template('templates/cfndsl.rb.tt', "#{@name}/#{@name}.cfndsl.rb")
39
+ end
40
+
41
+ def add_component
42
+ insert_into_file @cfhighlander_template, "\tComponent name: '#{@name}', template: '#{@name}'\n\n", :before => /^end/
43
+ end
44
+
45
+ end
46
+ end
47
+
@@ -0,0 +1,34 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module Kurgan
5
+ class GitHub
6
+
7
+ GITHUB_URL = "https://api.github.com"
8
+ GITHUB_ORG = "theonestack"
9
+
10
+ def self.get_repos
11
+ url = "#{GITHUB_URL}/orgs/#{GITHUB_ORG}/repos"
12
+ response = Faraday.get(url, {type: 'public', per_page: 100}, {'Accept' => 'Accept: application/vnd.github.v3+json'})
13
+
14
+ if response.status != 200
15
+ return nil
16
+ end
17
+
18
+ repos = JSON.parse(response.body, symbolize_names: true)
19
+ return repos.select {|repo| repo[:name].start_with?('hl-component')}
20
+ end
21
+
22
+ def self.get_releases(component)
23
+ url = "#{GITHUB_URL}/repos/#{GITHUB_ORG}/hl-component-#{component}/releases"
24
+ response = Faraday.get(url, {}, {'Accept' => 'Accept: application/vnd.github.v3+json'})
25
+
26
+ if response.status != 200
27
+ return nil
28
+ end
29
+
30
+ return JSON.parse(response.body, symbolize_names: true)
31
+ end
32
+
33
+ end
34
+ end
data/lib/kurgan/init.rb CHANGED
@@ -36,33 +36,39 @@ module Kurgan
36
36
 
37
37
  def create_cfhighlander_template
38
38
  opts = {parameters: @parameters, components: @components, description: @description}
39
- template('templates/cfhighlander.rb.tt', "#{@dir}/#{name}.cfhighlander.rb", opts)
39
+ template 'templates/cfhighlander.rb.tt', "#{@dir}/#{name}.cfhighlander.rb", opts
40
40
  end
41
41
 
42
42
  def create_config_yaml
43
43
  template 'templates/config.yaml.tt', "#{@dir}/#{name}.config.yaml"
44
44
  end
45
45
 
46
+ def create_readme
47
+ template "templates/README.md.project.tt", "#{@dir}/README.md"
48
+ end
49
+
46
50
  def git_init
47
- if yes?("git init project?")
51
+ if yes? "git init project?"
48
52
  run "git init #{@dir}"
49
53
  template 'templates/gitignore.tt', "#{@dir}/.gitignore"
50
- template "templates/README.md.tt", "#{@dir}/README.md"
51
54
  else
52
55
  say "Skipping git init", :yellow
53
56
  end
54
57
  end
55
58
 
56
59
  def ci_init
57
- if yes?("Setup a CI pipeline?")
58
- ci = ask "CI flavour", limited_to: ['jenkins', 'travis', 'codebuild']
60
+ if yes? "Setup a CI pipeline?"
61
+ ci = ask "CI flavour", limited_to: ['github', 'jenkins', 'codebuild']
59
62
  case ci
63
+ when 'github'
64
+ template 'templates/github_actions.yaml.tt', "#{@dir}/.github/workflows/rspec.yaml"
65
+ insert_into_file "#{@dir}/README.md",
66
+ "![cftest](https://github.com/theonestack/hl-component-#{name}/actions/workflows/rspec.yaml/badge.svg)\n\n",
67
+ :after => /^# #{name} CfHighlander Component\n\n/
60
68
  when 'jenkins'
61
- template('templates/Jenkinsfile.tt', "#{@dir}/Jenkinsfile")
62
- when 'travis'
63
- template('templates/travis.yml.tt', "#{@dir}/.travis.yml")
69
+ template 'templates/Jenkinsfile.tt', "#{@dir}/Jenkinsfile"
64
70
  when 'codebuild'
65
- template('templates/codebuild.yaml.tt', "#{@dir}/.codebuild.yaml")
71
+ template 'templates/codebuild.yaml.tt', "#{@dir}/.codebuild.yaml"
66
72
  end
67
73
  else
68
74
  say "Skipping CI setup", :yellow
@@ -0,0 +1,50 @@
1
+ require "thor"
2
+ require 'terminal-table'
3
+
4
+ module Kurgan
5
+ class Inspect < Thor::Group
6
+ include Thor::Actions
7
+
8
+ def get_cfhighlander_template
9
+ @cfhighlander_rb = Dir['*.cfhighlander.rb'][0]
10
+ if @cfhighlander_rb.nil?
11
+ raise "No cfhighlander.rb file found in #{Dir.pwd}"
12
+ end
13
+ end
14
+
15
+ def get_project_name
16
+ @project_name = @cfhighlander_rb.split('.').first
17
+ end
18
+
19
+ def get_components
20
+ cfhighlander_file = File.read(@cfhighlander_rb)
21
+ raw_components = cfhighlander_file.scan(/template:\s?(.*?)\s/).flatten
22
+
23
+ @components = raw_components.map do |template_str|
24
+ template = template_str.strip.gsub(/("|'|,)/, '').split(/(@|#)/)
25
+ { template: template.first, version: (template.size > 1 ? template.last : "not found") }
26
+ end
27
+ end
28
+
29
+ def check_versions
30
+ @components.each do |comp|
31
+ releases = Kurgan::GitHub.get_releases(comp[:template])
32
+ if !releases.nil? && releases.any?
33
+ latest_release = releases.sort_by { |r| r[:tag_name] }.reverse.first
34
+ comp[:latest_release] = latest_release[:tag_name]
35
+ else
36
+ comp[:latest_release] = 'not found'
37
+ end
38
+ end
39
+ end
40
+
41
+ def display
42
+ puts Terminal::Table.new(
43
+ :title => "Project: #{@project_name}",
44
+ :headings => ['Component', 'Version', 'Latest Release'],
45
+ :rows => @components.map {|comp| [comp[:template], comp[:version], comp[:latest_release]] }
46
+ )
47
+ end
48
+
49
+ end
50
+ end
data/lib/kurgan/list.rb CHANGED
@@ -1,58 +1,24 @@
1
- require 'open-uri'
1
+ require "thor"
2
+ require 'terminal-table'
3
+ require 'kurgan/github'
2
4
 
3
5
  module Kurgan
4
- class List
6
+ class List < Thor::Group
7
+ include Thor::Actions
5
8
 
6
- def initialize(options)
7
- @filter = options[:filter]
8
- @component = options[:component]
9
- if options[:update] || !File.exists?(Kurgan.components_file)
10
- update_component_list
9
+ def get_repos
10
+ repos = Kurgan::GitHub.get_repos()
11
+ if repos.nil?
12
+ abort "Error: Somthing went wrong with connecting to the github api"
11
13
  end
12
- content = File.read(Kurgan.components_file)
13
- @components = JSON.parse(content)['components']
14
+ @hl_repos = repos.map {|repo| [repo[:name], repo[:url], repo[:updated_at]]}
14
15
  end
15
16
 
16
- def execute
17
- puts "\n\s\s============================="
18
- puts "\s\s## CfHighlander Components ##"
19
- puts "\s\s=============================\n\n"
20
- if @component
21
- return component
22
- elsif @filter
23
- return filter
24
- else
25
- return all
26
- end
27
- end
28
-
29
- def component
30
- components = @components.select { |comp| comp['name'].include? @component }
31
- abort "no match for component #{@component}" if !components.any?
32
- components.each { |comp| puts "\s\s\s\s#{comp['name']} (#{comp['versions'].join(', ')})" }
33
- end
34
-
35
- def filter
36
- components = @components.select { |comp| comp['filter'].include? @filter }
37
- abort "no match for filter #{@filter}" if !components.any?
38
- components.each { |comp| format(comp['name'],comp['latest']) }
39
- end
40
-
41
- def all
42
- @components.each { |comp| format(comp['name'],comp['latest']) }
43
- end
44
-
45
- def format(name,version)
46
- version = version != "" ? version : 'latest'
47
- puts "\s\s\s\s#{name}@#{version}"
48
- end
49
-
50
- def update_component_list
51
- puts "Updating components list"
52
- FileUtils.mkdir_p File.dirname(Kurgan.components_file)
53
- content = open('https://s3-ap-southeast-2.amazonaws.com/cfhighlander-component-specification/components.json').read
54
- File.open(Kurgan.components_file, 'w') { |f| f.puts content }
55
- puts "Succesfully updated components list #{Kurgan.components_file}"
17
+ def display
18
+ puts Terminal::Table.new(
19
+ :headings => ['Component', 'Git URL', 'Last Updated'],
20
+ :rows => @hl_repos.sort
21
+ )
56
22
  end
57
23
 
58
24
  end
@@ -0,0 +1,33 @@
1
+ require "thor"
2
+ require 'terminal-table'
3
+ require 'kurgan/github'
4
+
5
+ module Kurgan
6
+ class Search < Thor::Group
7
+ include Thor::Actions
8
+
9
+ argument :component
10
+
11
+ def get_releases
12
+ releases = Kurgan::GitHub.get_releases(component)
13
+ if releases.nil?
14
+ abort "ERROR: unable to find component in theonestack"
15
+ end
16
+
17
+ if releases.any?
18
+ @rows = releases.map {|release| [release[:tag_name], release[:name], release[:published_at], release[:html_url]]}
19
+ else
20
+ tags = Kurgan::GitHub.get_tags(component)
21
+ end
22
+ end
23
+
24
+ def display
25
+ puts Terminal::Table.new(
26
+ :title => "Component: #{component}",
27
+ :headings => ['Version', 'name', 'Published', 'URL'],
28
+ :rows => @rows.sort.reverse
29
+ )
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,77 @@
1
+ # <%= name %> CfHighlander Component
2
+
3
+ <!--- add component description --->
4
+
5
+ ```bash
6
+ kurgan add <%= name %>
7
+ ```
8
+
9
+ ## Requirements
10
+
11
+ ## Parameters
12
+
13
+ | Name | Use | Default | Global | Type | Allowed Values |
14
+ | ---- | --- | ------- | ------ | ---- | -------------- |
15
+
16
+
17
+ ## Configuration
18
+
19
+ <!--- add component config examples --->
20
+
21
+ ```yaml
22
+ example_config: test
23
+ ```
24
+
25
+ ## Outputs/Exports
26
+
27
+ | Name | Value | Exported |
28
+ | ---- | ----- | -------- |
29
+
30
+
31
+ ## Development
32
+
33
+ ```bash
34
+ gem install cfhighlander
35
+ ```
36
+
37
+ or via docker
38
+
39
+ ```bash
40
+ docker pull theonestack/cfhighlander
41
+ ```
42
+
43
+ ### Testing
44
+
45
+ Generate cftest
46
+
47
+ ```bash
48
+ kurgan test example
49
+ ```
50
+
51
+ Run cftest
52
+
53
+ ```bash
54
+ cfhighlander cftest -t tests/example.test.yaml
55
+ ```
56
+
57
+ or run all tests
58
+
59
+ ```bash
60
+ cfhighlander cftest
61
+ ```
62
+
63
+ Generate spec tests
64
+
65
+ ```bash
66
+ kurgan test example --type spec
67
+ ```
68
+
69
+ run spec tests
70
+
71
+ ```bash
72
+ gem install rspec
73
+ ```
74
+
75
+ ```bash
76
+ rspec
77
+ ```
@@ -1,4 +1,4 @@
1
- # <%= name %> CfHighlander <%= @type %>
1
+ # <%= name %> CfHighlander Project
2
2
 
3
3
  ## Cfhighlander Setup
4
4
 
@@ -24,7 +24,7 @@ cfhighlander cftest <%= name %>
24
24
  <%- elsif @type == 'project' -%>
25
25
  ## Compiling the project
26
26
 
27
- compiling with the vaildate fag to validate the templates
27
+ compiling with the validate tag to validate the templates
28
28
 
29
29
  ```bash
30
30
  cfcompile <%= name %> --validate
@@ -0,0 +1,4 @@
1
+ CfhighlanderTemplate do
2
+ Name '<%= config[:name] %>'
3
+ Extends '<%= config[:template] %>'
4
+ end
@@ -1,6 +1,3 @@
1
1
  CloudFormation do
2
2
  ## Add your cfndsl resources here
3
- SNS_Topic(:Topic) {
4
- TopicName topic_name if defined? topic_name
5
- }
6
3
  end
@@ -0,0 +1,25 @@
1
+ name: cftest
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ name: test
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ - name: set up ruby 2.7
13
+ uses: actions/setup-ruby@v1
14
+ with:
15
+ ruby-version: 2.7.x
16
+ - name: install gems
17
+ run: gem install cfhighlander rspec
18
+ - name: set cfndsl spec
19
+ run: cfndsl -u
20
+ - name: cftest
21
+ run: rspec
22
+ env:
23
+ AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
24
+ AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
25
+ AWS_REGION: ap-southeast-2
@@ -0,0 +1,31 @@
1
+ require 'yaml'
2
+
3
+ describe 'compiled component <%= @component_name %>' do
4
+
5
+ context 'cftest' do
6
+ it 'compiles test' do
7
+ expect(system("cfhighlander cftest #{@validate} --tests tests/<%= @test_name %>.test.yaml")).to be_truthy
8
+ end
9
+ end
10
+
11
+ let(:template) { YAML.load_file("#{File.dirname(__FILE__)}/../out/tests/<%= @test_name %>/<%= @component_name %>.compiled.yaml") }
12
+
13
+ context "Resource" do
14
+
15
+ <% config['Resources'].each do |resource, details| %>
16
+ context "<%= resource %>" do
17
+ let(:resource) { template["Resources"]["<%= resource %>"] }
18
+
19
+ it "is of type <%= details['Type'] %>" do
20
+ expect(resource["Type"]).to eq("<%= details['Type'] %>")
21
+ end
22
+ <% if details.has_key?('Properties')%><% details['Properties'].each do |property, value| %>
23
+ it "to have property <%= property %>" do
24
+ expect(resource["Properties"]["<%= property %>"]).to eq(<%= value.is_a?(String) ? "\"#{value}\"" : value %>)
25
+ end
26
+ <% end %><% end %>
27
+ end
28
+ <% end %>
29
+ end
30
+
31
+ end
data/lib/kurgan/test.rb CHANGED
@@ -1,10 +1,12 @@
1
+ require 'yaml'
2
+
1
3
  module Kurgan
2
4
  class Test < Thor::Group
3
5
  include Thor::Actions
4
6
 
5
7
  argument :test_name
6
8
 
7
- class_option :type, aliases: :t, type: :string, enum: %w(config), default: 'config'
9
+ class_option :type, aliases: :t, type: :string, enum: %w(config spec), default: 'config'
8
10
  class_option :directory, aliases: :d, type: :string, default: 'tests'
9
11
 
10
12
  def self.source_root
@@ -16,6 +18,7 @@ module Kurgan
16
18
  if @cfhighlander_template.nil?
17
19
  raise "No cfhighlander.rb file found in #{Dir.pwd}"
18
20
  end
21
+ @component_name = @cfhighlander_template.split('.').first
19
22
  end
20
23
 
21
24
  def create_test
@@ -23,6 +26,14 @@ module Kurgan
23
26
  when 'config'
24
27
  template('templates/test.yaml.tt', "#{options[:directory]}/#{test_name}.test.yaml")
25
28
  say "created config test case #{options[:directory]}/#{test_name}.test.yaml", :green
29
+ when 'spec'
30
+ output_file = "#{Dir.pwd}/out/tests/#{test_name}/#{@component_name}.compiled.yaml"
31
+ if !File.file?(output_file)
32
+ error "compile cloudformation test output file #{output_file} not found.\nRun `cfhighlander cftest -t #{options[:directory]}/#{test_name}.test.yaml`"
33
+ end
34
+ compiled_test = YAML.load_file("#{Dir.pwd}/out/tests/#{test_name}/#{@component_name}.compiled.yaml")
35
+ template('templates/test.spec.tt', "spec/#{test_name}_spec.rb", compiled_test)
36
+ say "created spec test spec/#{test_name}_spec.rb", :green
26
37
  else
27
38
  error "#{options[:type]} is not a supported test type yet", :red
28
39
  end
@@ -1,3 +1,3 @@
1
1
  module Kurgan
2
- VERSION = "0.2.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/list.rb ADDED
@@ -0,0 +1,25 @@
1
+ require "thor"
2
+ require 'faraday'
3
+ require 'json'
4
+ require 'terminal-table'
5
+
6
+ module Kurgan
7
+ class List < Thor::Group
8
+ include Thor::Actions
9
+
10
+ def get_repos
11
+ url = 'https://api.github.com/orgs/theonestack/repos'
12
+ response = Faraday.get(url, {type: 'public', per_page: 100}, {'Accept' => 'Accept: application/vnd.github.v3+json'})
13
+ repos = JSON.parse(response.body, symbolize_names: true)
14
+ @hl_repos = repos.select {|repo| repo[:name].start_with?('hl-component')}.map {|repo| [repo[:name], repo[:url], repo[:updated_at]]}
15
+ end
16
+
17
+ def display
18
+ puts Terminal::Table.new(
19
+ :headings => ['Component', 'Git URL', 'Last Updated'],
20
+ :rows => @hl_repos.sort
21
+ )
22
+ end
23
+
24
+ end
25
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kurgan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guslington
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-23 00:00:00.000000000 Z
11
+ date: 2021-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -24,6 +24,46 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.19'
27
+ - !ruby/object:Gem::Dependency
28
+ name: terminal-table
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '2'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '2'
47
+ - !ruby/object:Gem::Dependency
48
+ name: faraday
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1'
54
+ - - "<"
55
+ - !ruby/object:Gem::Version
56
+ version: '2'
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '1'
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: '2'
27
67
  - !ruby/object:Gem::Dependency
28
68
  name: bundler
29
69
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +84,14 @@ dependencies:
44
84
  requirements:
45
85
  - - "~>"
46
86
  - !ruby/object:Gem::Version
47
- version: '10.0'
87
+ version: '13.0'
48
88
  type: :development
49
89
  prerelease: false
50
90
  version_requirements: !ruby/object:Gem::Requirement
51
91
  requirements:
52
92
  - - "~>"
53
93
  - !ruby/object:Gem::Version
54
- version: '10.0'
94
+ version: '13.0'
55
95
  description: Manage a cfhighalnder project
56
96
  email:
57
97
  - theonestackcfhighlander@gmail.com
@@ -60,8 +100,9 @@ executables:
60
100
  extensions: []
61
101
  extra_rdoc_files: []
62
102
  files:
103
+ - ".github/workflows/build-gem.yml"
104
+ - ".github/workflows/release-gem.yml"
63
105
  - ".gitignore"
64
- - ".travis.yml"
65
106
  - Gemfile
66
107
  - Gemfile.lock
67
108
  - LICENSE.txt
@@ -72,27 +113,35 @@ files:
72
113
  - lib/kurgan.rb
73
114
  - lib/kurgan/add.rb
74
115
  - lib/kurgan/component.rb
116
+ - lib/kurgan/extend.rb
117
+ - lib/kurgan/github.rb
75
118
  - lib/kurgan/globals.rb
76
119
  - lib/kurgan/init.rb
120
+ - lib/kurgan/inspect.rb
77
121
  - lib/kurgan/list.rb
78
122
  - lib/kurgan/projects.rb
123
+ - lib/kurgan/search.rb
79
124
  - lib/kurgan/templates/Jenkinsfile.tt
80
125
  - lib/kurgan/templates/MITLICENSE
81
- - lib/kurgan/templates/README.md.tt
126
+ - lib/kurgan/templates/README.md.component.tt
127
+ - lib/kurgan/templates/README.md.project.tt
128
+ - lib/kurgan/templates/cfhighlander.extend.rb.tt
82
129
  - lib/kurgan/templates/cfhighlander.rb.tt
83
130
  - lib/kurgan/templates/cfndsl.rb.tt
84
131
  - lib/kurgan/templates/codebuild.yaml.tt
85
132
  - lib/kurgan/templates/config.yaml.tt
133
+ - lib/kurgan/templates/github_actions.yaml.tt
86
134
  - lib/kurgan/templates/gitignore.tt
135
+ - lib/kurgan/templates/test.spec.tt
87
136
  - lib/kurgan/templates/test.yaml.tt
88
- - lib/kurgan/templates/travis.yml.tt
89
137
  - lib/kurgan/test.rb
90
138
  - lib/kurgan/version.rb
139
+ - list.rb
91
140
  homepage: http://iamkurgan.com
92
141
  licenses:
93
142
  - MIT
94
143
  metadata:
95
- allowed_push_host: http://mygemserver.com
144
+ allowed_push_host: https://rubygems.org
96
145
  post_install_message:
97
146
  rdoc_options: []
98
147
  require_paths:
@@ -108,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
157
  - !ruby/object:Gem::Version
109
158
  version: '0'
110
159
  requirements: []
111
- rubygems_version: 3.0.3
160
+ rubygems_version: 3.1.6
112
161
  signing_key:
113
162
  specification_version: 4
114
163
  summary: Manage a cfhighalnder project
data/.travis.yml DELETED
@@ -1,17 +0,0 @@
1
- sudo: required
2
- dist: trusty
3
- language: ruby
4
- rvm:
5
- - 2.5
6
- script:
7
- - bundle install
8
- - gem build kurgan.gemspec
9
- - gem install kurgan-*.gem
10
- - kurgan help
11
- deploy:
12
- provider: rubygems
13
- api_key: "${RUBYGEMS_API_KEY}"
14
- gem: kurgan
15
- on:
16
- all_branches: true
17
- condition: $TRAVIS_BRANCH =~ ^develop|master && $TRAVIS_EVENT_TYPE =~ ^push|api$ && $TRAVIS_REPO_SLUG == "theonestack/kurgan"
@@ -1,15 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.5
4
- install:
5
- - gem install cfhighlander cfn-nag
6
- before_script:
7
- - cfndsl -u
8
- <%- if @type == 'component' -%>
9
- script:
10
- - if [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then cfhighlander cftest --no-validate; else cfhighlander cftest; fi
11
- - cfn_nag_scan -i out/tests
12
- <%- elsif @type == 'project' -%>
13
- script:
14
- - cfcompile
15
- <%- end -%>