souschef 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +177 -0
  6. data/Rakefile +1 -0
  7. data/bin/souschef +33 -0
  8. data/data/chefspec/chefspec.erb +6 -0
  9. data/data/chefspec/spec_helper.rb +8 -0
  10. data/data/gemfile.yml +23 -0
  11. data/data/license.erb +3 -0
  12. data/data/metadata.erb +7 -0
  13. data/data/rakefile.erb +39 -0
  14. data/data/readme.erb +47 -0
  15. data/data/recipe/recipe.erb +6 -0
  16. data/data/rubocop/rubocop.yml +19 -0
  17. data/data/serverspec/serverspec.erb +2 -0
  18. data/data/serverspec/serverspec_helper.rb +10 -0
  19. data/data/testkitchen/kitchen.default.erb +22 -0
  20. data/lib/souschef.rb +16 -0
  21. data/lib/souschef/berkshelf.rb +93 -0
  22. data/lib/souschef/config.rb +20 -0
  23. data/lib/souschef/configure/file.rb +46 -0
  24. data/lib/souschef/gemfile.rb +42 -0
  25. data/lib/souschef/print.rb +40 -0
  26. data/lib/souschef/runner.rb +104 -0
  27. data/lib/souschef/scaffold.rb +145 -0
  28. data/lib/souschef/template.rb +26 -0
  29. data/lib/souschef/template/base.rb +69 -0
  30. data/lib/souschef/template/chefspec.rb +26 -0
  31. data/lib/souschef/template/license.rb +25 -0
  32. data/lib/souschef/template/metadata.rb +30 -0
  33. data/lib/souschef/template/rakefile.rb +23 -0
  34. data/lib/souschef/template/readme.rb +24 -0
  35. data/lib/souschef/template/rubocop.rb +22 -0
  36. data/lib/souschef/template/serverspec.rb +27 -0
  37. data/lib/souschef/testkitchen.rb +135 -0
  38. data/lib/souschef/testkitchen/docker.rb +97 -0
  39. data/lib/souschef/testkitchen/solusvm.rb +101 -0
  40. data/lib/souschef/testkitchen/virtualbox.rb +66 -0
  41. data/lib/souschef/version.rb +4 -0
  42. data/souschef.gemspec +33 -0
  43. metadata +254 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8346f12ba0184f1d32193a4f9fe4fddb1b4d8048
4
+ data.tar.gz: 93f8a98bd81ede8f3638f81f19db3fa283e73ae4
5
+ SHA512:
6
+ metadata.gz: 20e084327520acbc3f39404a85c47a55dc438a36dcb94396ed67357a508606ce1928fdb97b9ff04cae0d441c3669fab07f1f5a4f9b4100f1bc27bdcc5a49b66c
7
+ data.tar.gz: eabede258978b53326a716ffbd93b01d6db9a32a5bbc4b36161d171bfe208473ed4bb66ffffdcd48cbd7cc4a2f5a219e09f34ba6576c4354e6e8f62079afb15b
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in souschef.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Antun Krasic
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,177 @@
1
+ # Souschef
2
+
3
+ Souschef is a helper script to aid with starting a developing Chef cookbook by automating the creation of cookbook per standards.
4
+
5
+ Cookbook creation uses following steps:
6
+ - Using Berkshelf to create the cookbook structure
7
+ - Populates the `Gemfile`, `.kitchen.yml`, `.rubocop.yml`
8
+ - Adjusts the `metadata.rb`, `README` and `LICENSE`
9
+ - Configured directorie and places `spec_helper.rb` for Chefspec and Serverspec
10
+ - Adds `Rakefile` which runs Foodcritic, Rubocop, RSpec and TestKitchecn tests
11
+
12
+ Souschef also can create new recipe and spec test files for you:
13
+ - file under `recipes/` directory
14
+ - file under `spec/unit/` directory
15
+ - file under `test/integration/default/serverspec/localhost/` directory
16
+
17
+
18
+ ## Installation
19
+ Clone this repository and do:
20
+ `gem build souschef.gemspec`
21
+ `gem install souschef-*.gem`
22
+
23
+
24
+ # Getting started
25
+ First off you'd need to generate your configuration file that will hold data
26
+ about your profile - `maintainer`, `maintainer_email` and `license` which are
27
+ written to the `~/.souschef.yml` file.
28
+ Additionally, you can have several profiles specified by the `--profile` argument.
29
+
30
+ **Creating default configuration**
31
+
32
+ `souschef --configure --maintainer 'John Doe' --maintainer-email 'john@doe.com' --license 'MIT'`
33
+
34
+ or
35
+
36
+ `souschef --profile 'default' --configure --maintainer 'John Doe' --maintainer-email 'john@doe.com' --license 'MIT'`
37
+ ## Usage
38
+
39
+ Currently available options:
40
+
41
+ ```
42
+ Options:
43
+ --cookbook <s>: Name of your cookbook
44
+ --path <s>: Define cookbook directory path (relative)
45
+ --testkitchen <s>: Pick your additional configuration to create
46
+ .kitchen.local.yml file
47
+ --scaffold: Create recipe, chefspec and serverspec files for
48
+ recipe
49
+ --recipe <s>: Recipe name, used along with --scaffold
50
+ --profile <s>: Pick your configuration profile (default: default)
51
+ --force: Force create action
52
+ --configure: Create configuration file
53
+ --verbose: Print out detailed information
54
+ --maintainer <s>: Maintainer name
55
+ --maintainer-email <s>: Maintainer email
56
+ --license <s>: Licese you want to use, be explicit
57
+
58
+ ```
59
+
60
+ # Example usage
61
+ **Create cookbook in current directory**
62
+
63
+ `souschef --cookbook mycb --verbose`
64
+
65
+ **Create cookbook using alternate profile from your configuration file**
66
+
67
+ `souschef --cookbook mycb --profile other --verbose`
68
+
69
+ **Create cookbook in a subfolder of current directory**
70
+
71
+ `souschef --cookbook mycb --path subdir --verbose`
72
+
73
+ **Use scaffold to get you started writing a new recipe and tests**
74
+
75
+ `souschef --scaffold --recipe install`
76
+
77
+ # Profile support
78
+ Souschef lets you one or several profiles/configurations under one roof, to get
79
+ started simply configure it via:
80
+
81
+ ```
82
+ souschef --configure --maintainer "YOUR NAME" \
83
+ --maintainer-email "YOUR EMAIL" \
84
+ --license "Restricted license, do not touch"
85
+ ```
86
+
87
+ Profile configuration is written inside `~/.souschef.yml` file and can be easily
88
+ edited by hand if needed.
89
+
90
+ # Note on TestKitchen
91
+ Souschef uses a default template for TestKitchen `.kitchen.yaml`. If this
92
+ doesn't fit your needs, please check the section on custimization and create
93
+ your own `.kitchen.default.erb` template.
94
+
95
+ If you are sporting Docker, DigitalOcean or any other TestKitchen driver please
96
+ follow these steps to make it into your newly generated cookbook:
97
+
98
+ **Create testkitchen directory for your profile**
99
+
100
+ Assuming that your will be using this for the "default" profile, but adjust
101
+ accordingly:
102
+
103
+ `mkdir -p ~/.souschef/default/testkitchen/`
104
+
105
+ **Create your new ERB driver configuration**
106
+
107
+ To differentiate between drivers, TestKitchen template filename has the
108
+ following format: kitchen.DRIVER.yml
109
+ If you want to use your own Docker TestKitchen configuration please create
110
+ following file and populate it with a valid YAML syntax.
111
+
112
+ `vim ~/.souschef/default/testkitchen/kitchen.docker.erb`
113
+
114
+ **Create your new cookbook using TestKitchen Docker tempalte**
115
+
116
+ `souschef --cookbook mycb --testkitchen docker`
117
+
118
+ Souschef will create following standard `.kitchen.yml` file and
119
+ `.kitchen.local.yml` holding your Docker configuration. If you have a custom
120
+ `kitchen.default.erb` Souschef will use that to generate `.kitchen.yml` over the
121
+ bundled template.
122
+
123
+ # Customization
124
+
125
+ When creating a cookbook, Souschef will look first if a custom directory for the
126
+ chosen profile exists - `~/.souschef/$PROFILE` and search if the template it is
127
+ currently creating exists there - if so, it will be used instead of the bundled
128
+ one.
129
+
130
+
131
+ You can customize the default configuration that comes with few easy steps,
132
+ below is an example for a custom recipe file
133
+
134
+ **Create ~/.souschef/ directory for chosen profile**
135
+
136
+ `mkdir -p ~/souschef/default/recipe`
137
+
138
+ **Create your own rubocop.yml file**
139
+
140
+ `vim ~/.shouschef/default/recipe/recipe.erb`
141
+
142
+ **Run souschef command and you will see following in the output**
143
+
144
+ ```
145
+ ~> Create default[recipe] from /home/user/.souschef/default/recipe/recipe.erb
146
+ ```
147
+
148
+ **Full directory structure of custom files**
149
+
150
+ ```
151
+ ├── chefspec
152
+ │   ├── chefspec.erb
153
+ │   └── spec_helper.rb
154
+ ├── gemfile.yml
155
+ ├── license.erb
156
+ ├── metadata.erb
157
+ ├── rakefile.erb
158
+ ├── readme.erb
159
+ ├── recipe
160
+ │   └── recipe.erb
161
+ ├── rubocop
162
+ │   └── rubocop.yml
163
+ ├── serverspec
164
+ │   ├── serverspec.erb
165
+ │   └── serverspec_helper.rb
166
+ └── testkitchen
167
+ └── kitchen.default.erb
168
+ ```
169
+
170
+
171
+ ## Contributing
172
+
173
+ 1. Fork it ( https://github.com/[my-github-username]/souschef/fork )
174
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
175
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
176
+ 4. Push to the branch (`git push origin my-new-feature`)
177
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/ruby
2
+ # souschef - Chef developemnt helper
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '../lib')
4
+ require 'souschef'
5
+
6
+ options = Trollop::Parser.new do
7
+ version "SousChef #{Souschef::VERSION}"
8
+
9
+ opt :cookbook, 'Name of your cookbook', type: :string
10
+ opt :path, 'Define cookbook directory path (relative)', type: :string
11
+ opt :testkitchen, "Pick your additional configuration to create \
12
+ .kitchen.local.yml file", type: :string
13
+ opt :scaffold, 'Create recipe, chefspec and serverspec files for recipe'
14
+ opt :recipe, 'Recipe name, used along with --scaffold', type: :string
15
+ opt :profile, 'Pick your configuration profile', default: 'default'
16
+ opt :force, 'Force create action'
17
+ opt :configure, 'Create configuration file'
18
+ opt :verbose, 'Print out detailed information'
19
+ opt :maintainer, 'Maintainer name', type: :string
20
+ opt :maintainer_email, 'Maintainer email', type: :string
21
+ opt :license, 'Licese you want to use, be explicit', type: :string
22
+ end
23
+
24
+ opts = Trollop.with_standard_exception_handling options do
25
+ fail Trollop::HelpNeeded if ARGV.empty?
26
+ options.parse ARGV
27
+ end
28
+
29
+ begin
30
+ Souschef::Runner.new(opts).run
31
+ rescue RuntimeError => e
32
+ Souschef::Print.error e
33
+ end
@@ -0,0 +1,6 @@
1
+ # Chefspec testing for <%= @recipe %> recipe
2
+ require 'spec_helper'
3
+ # Start description
4
+ describe '<%= @cookbook %>::<%= @recipe %>' do
5
+ let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }
6
+ end
@@ -0,0 +1,8 @@
1
+ require 'chefspec'
2
+ require 'chefspec/berkshelf'
3
+
4
+ RSpec.configure do |config|
5
+ config.color = true
6
+ end
7
+
8
+ at_exit { ChefSpec::Coverage.report! }
@@ -0,0 +1,23 @@
1
+ ---
2
+ :source:
3
+ - https://rubygems.org
4
+ :general:
5
+ - :name: chefspec
6
+ :version: "~> 4"
7
+ - :name: berkshelf
8
+ :version: "~> 3"
9
+ - rake
10
+ - rubocop
11
+ - foodcritic
12
+ :group:
13
+ - :group_name: development
14
+ :gems:
15
+ - :name: vagrant-berkshelf
16
+ :github: berkshelf/vagrant-berkshelf
17
+ - :name: vagrant-omnibus
18
+ :github: schisamo/vagrant-omnibus
19
+ - :group_name: integration
20
+ :gems:
21
+ - test-kitchen
22
+ - kitchen-vagrant
23
+ - kitchen-docker
@@ -0,0 +1,3 @@
1
+ Copyright (C) <%= @year %> <%= @maintainer %>
2
+
3
+ All rights reserved - Do Not Redistribute
@@ -0,0 +1,7 @@
1
+ name '<%= @cookbook %>'
2
+ maintainer '<%= @maintainer %>'
3
+ maintainer_email '<%= @maintainer_email %>'
4
+ license '<%= @license %>'
5
+ description 'Installs/Configures <%= @cookbook %>'
6
+ long_description 'Installs/Configures <%= @cookbook %>'
7
+ version '0.1.0'
@@ -0,0 +1,39 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'rubocop/rake_task'
3
+ require 'foodcritic'
4
+ require 'kitchen'
5
+
6
+ # Style tests. Rubocop and Foodcritic
7
+ namespace :style do
8
+ desc 'Run Ruby style checks'
9
+ RuboCop::RakeTask.new(:ruby)
10
+
11
+ desc 'Run Chef style checks'
12
+ FoodCritic::Rake::LintTask.new(:chef) do |t|
13
+ t.options = {
14
+ fail_tags: ['any'],
15
+ tags: ['~FC005']
16
+ }
17
+ end
18
+ end
19
+
20
+ desc 'Run all style checks'
21
+ task style: ['style:chef', 'style:ruby']
22
+
23
+ # Rspec and ChefSpec
24
+ desc "Run ChefSpec examples"
25
+ RSpec::Core::RakeTask.new(:spec)
26
+
27
+ # Integration tests. Kitchen.ci
28
+ namespace :integration do
29
+ desc 'Run Test Kitchen with Vagrant'
30
+ task :vagrant do
31
+ Kitchen.logger = Kitchen.default_file_logger
32
+ Kitchen::Config.new.instances.each do |instance|
33
+ instance.test(:always)
34
+ end
35
+ end
36
+ end
37
+
38
+ # Default
39
+ task default: ['style', 'spec', 'integration:vagrant']
@@ -0,0 +1,47 @@
1
+ ## <%= @cookbook %>
2
+
3
+ ## Description
4
+
5
+ INSERT DESCRIPTION FOR <%= @cookbook %> HERE
6
+
7
+ ---
8
+
9
+ ## Supported Platforms
10
+
11
+ The following platforms and versions are tested and supported using
12
+ [test-kitchen](http://kitchen.ci/).
13
+
14
+ * CentOS 5.10, 6.5
15
+
16
+
17
+ ---
18
+
19
+ ## Cookbook Dependencies
20
+
21
+ * None
22
+
23
+ ---
24
+
25
+ ## Attributes
26
+
27
+ * None
28
+
29
+ ---
30
+
31
+ ## Recipes
32
+
33
+ * default
34
+ + None
35
+
36
+ ---
37
+
38
+ ## Tests
39
+
40
+ * default
41
+ + None
42
+
43
+ ---
44
+
45
+ ## Author
46
+
47
+ Author: <%= @maintainer %> (<%= @maintainer_email %>)
@@ -0,0 +1,6 @@
1
+ # Cookbook Name:: <%= @cookbook %>
2
+ # Recipe:: <%= @recipe %>
3
+ #
4
+ # Copyright (C) <%= @year %> <%= @maintainer %>
5
+ #
6
+ # <%= @license %>
@@ -0,0 +1,19 @@
1
+ AllCops:
2
+ Include:
3
+ - Berksfile
4
+ - Gemfile
5
+ - Rakefile
6
+ Exclude:
7
+ - vendor/**/*
8
+ AlignParameters:
9
+ Enabled: false
10
+ Encoding:
11
+ Enabled: false
12
+ HashSyntax:
13
+ Enabled: false
14
+ LineLength:
15
+ Enabled: false
16
+ MethodLength:
17
+ Max: 30
18
+ StringLiterals:
19
+ Enabled: false