chef-flavor-flay 0.2.1 → 0.3.0

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: 9f079d980eef92521cd03d0c927afa918d856f6f
4
- data.tar.gz: 8f012e3247d68a05ee0e697ef020f6c18a57ea4c
3
+ metadata.gz: 32dae8d8ec27b60daf4ddf74271a57cd83c3b80f
4
+ data.tar.gz: 3fb9dce91f352246f5de60c8c59c0c20b0707880
5
5
  SHA512:
6
- metadata.gz: 06f2f667988e80583a76c0442eb65538fa87521a46e75c768617bd35e812f06d08aeaa20014e791c57be5ece079cd90d9bd519ac8f303eee97f817b46d4c1e25
7
- data.tar.gz: 79f9aa69916bab25d696ca20df4b6362e9681851220e878fee571f0e7b085d25e00e4b4145d9b4cede1f06bc46a367c78354982a9d1b08dd94d9aa0c13fc44ac
6
+ metadata.gz: 6ef158d393e4a40f03602e14799d78ffe36c23d5c673c1f6bf6bea0a5d5bebcdec1f78608b23c95004d72e29a082094160c6323529d503ece050a9cccbff075a
7
+ data.tar.gz: 9a1a0674f340208b7a2b43f0f4fd6c1ed0200d2a1ecf783447ea094066721631792f6d2b2d554c7f3a19cd434eb04ad4accacb32f3c4672828299fea54b38819
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --order rand
2
+ --color
3
+ --format progress
4
+ --require spec_helper
data/.rubocop.yml CHANGED
@@ -10,6 +10,12 @@ Style/StringLiterals:
10
10
  Style/Documentation:
11
11
  Enabled: false
12
12
 
13
+ Style/ClassAndModuleChildren:
14
+ EnforcedStyle: compact
15
+
16
+ Style/SingleLineBlockParams:
17
+ Enabled: false
18
+
13
19
  Metrics/LineLength:
14
20
  Max: 120
15
21
 
data/Gemfile CHANGED
@@ -1,10 +1,13 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec
3
3
 
4
- group :development do
4
+ group :development, :test do
5
5
  gem "aruba", "~> 0.0"
6
6
  gem "bundler", "~> 1.11"
7
7
  gem "chef-dk", "~> 0.0"
8
+ gem "coveralls", require: false
9
+ gem "pry-byebug", "~> 3.0"
8
10
  gem "rake", "~> 10.0"
11
+ gem "rspec", "~> 3.0"
9
12
  gem "rubocop", "~> 0.0"
10
13
  end
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Flay - A Customizable Chef Cookbook Template
2
2
 
3
3
  [![Build Status](https://travis-ci.org/sweeperio/flay.svg?branch=master)](https://travis-ci.org/sweeperio/flay)
4
+ [![Gem Version](https://badge.fury.io/rb/chef-flavor-flay.svg)](https://badge.fury.io/rb/chef-flavor-flay)
5
+ [![Coverage Status](https://coveralls.io/repos/sweeperio/flay/badge.svg?branch=master&service=github)](https://coveralls.io/github/sweeperio/flay?branch=master)
4
6
 
5
7
  This repo is a custom cookbook/recipe template for use with the [ChefDK]. It uses [chef-gen-flavors] to create a custom
6
8
  template that can be used with `chef generate [cookbook|recipe]` commands.
@@ -69,19 +71,33 @@ Celebrate! :rocket:
69
71
 
70
72
  ## Usage
71
73
 
72
- * `chef generate cookbook my_cookbook`
73
- * `chef generate recipe my_recipe` (from within the cookbook directory)
74
+ * `chef exec flay cookbook my_cookbook`
75
+ * `chef exec flay recipe my_cookbook` (from within the cookbook directory)
76
+ * `chef exec flay release` (see below)
74
77
 
75
- If you're using this for sweeper cookbooks you should use these instead. They simply call the normal generate methods
76
- but pass parameters for maintainer, email and license.
78
+ There are a few other commands available. Run `chef exec flay help` for details.
77
79
 
78
- * `chef exec flay cookbook my_cookbook`
79
- * `chef exec flay recipe my_cookbook`
80
+ ### Releasing Cookbooks
81
+
82
+ Modelled after bundler's `rake release`, there's `chef exec flay release`.
83
+
84
+ When the following conditions are met:
85
+
86
+ * `Dir.pwd` is a git repo (or a subdirectory of one)
87
+ * There are no uncommitted changes in git
88
+ * _metadata.rb_ exists (at the root of the repo) and contains a valid version
89
+
90
+ It will run:
91
+
92
+ * `git tag -a -m "Version #{version}" v#{version}` - unless the tag already exists
93
+ * `git push && git push --tags`
94
+ * `chef exec berks install`
95
+ * `chef exec berks upload --no-ssl-verify`
80
96
 
81
97
  ### Example
82
98
 
83
99
  ```
84
- $ chef generate cookbook chef-demo-flay
100
+ $ chef exec flay generate cookbook chef-demo-flay
85
101
 
86
102
  using ChefGen flavor 'flay'
87
103
  Compiling Cookbooks...
data/Rakefile CHANGED
@@ -1,9 +1,11 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
3
  require "cucumber/rake/task"
4
+ require "rspec/core/rake_task"
4
5
  require "rubocop/rake_task"
5
6
 
6
7
  Cucumber::Rake::Task.new(:features)
8
+ RSpec::Core::RakeTask.new(:spec)
7
9
  RuboCop::RakeTask.new(:rubocop)
8
10
 
9
- task default: [:rubocop, :features]
11
+ task default: [:rubocop, :spec, :features]
data/cucumber.yml ADDED
@@ -0,0 +1,2 @@
1
+ default: -r features --format "pretty" --tags ~@wip --snippet-type regexp
2
+ wip: -r features --tags @wip --wip
data/exe/flay CHANGED
@@ -1,30 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "open3"
3
+ ENV["CHEFGEN_FLAVOR"] = "flay"
4
4
 
5
- ARGS = "-C sweeper.io -m developers@sweeper.io -I mit".freeze
6
-
7
- def run_generator(type, name)
8
- command = "chef generate #{type} #{name} #{ARGS}"
9
- output, err, status = Open3.capture3(command)
10
- puts output
11
- puts err if status != 0
12
- end
13
-
14
- def usage
15
- puts "USAGE:"
16
- puts "flay cookbook NAME"
17
- puts "flay recipe NAME"
18
- exit 1
19
- end
20
-
21
- type, name = ARGV
22
- usage if ARGV.size != 2
23
- usage if type.nil? || name.nil?
24
-
25
- case type
26
- when "cookbook" then run_generator("cookbook", name)
27
- when "recipe" then run_generator("recipe", name)
28
- else
29
- usage
30
- end
5
+ require "flay"
6
+ Flay::CLI.start
data/flay.gemspec CHANGED
@@ -1,7 +1,10 @@
1
1
  # coding: utf-8
2
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
3
+ require "flay/version"
4
+
2
5
  Gem::Specification.new do |spec|
3
6
  spec.name = "chef-flavor-flay"
4
- spec.version = "0.2.1"
7
+ spec.version = Flay::VERSION
5
8
  spec.authors = ["pseudomuto"]
6
9
  spec.email = ["developers@sweeper.io"]
7
10
 
@@ -16,6 +19,7 @@ Gem::Specification.new do |spec|
16
19
  spec.require_paths = ["lib"]
17
20
 
18
21
  spec.add_runtime_dependency "chef-gen-flavors", "~> 0.9"
22
+ spec.add_runtime_dependency "thor", "~> 0.0"
19
23
 
20
24
  spec.post_install_message = <<-EOM
21
25
  Thanks for installing chef-flavor-flay! Be sure to update your knife.rb file
@@ -1,9 +1,8 @@
1
- module ChefGen
2
- module Flavor
1
+ module ChefGen # rubocop:disable Style/ClassAndModuleChildren
2
+ module Flavor # rubocop:disable Style/ClassAndModuleChildren
3
3
  class Flay
4
- NAME = "flay".freeze
5
- DESC = "Generate a new cookbook with **better** defaults".freeze
6
- VERSION = "0.2.1".freeze
4
+ NAME = "flay".freeze
5
+ DESC = "Generate a new cookbook with **better** defaults".freeze
7
6
 
8
7
  attr_reader :temp_path
9
8
 
data/lib/flay.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "open3"
2
+ require "thor"
3
+
4
+ module Flay
5
+ autoload :CLI, "flay/cli"
6
+ autoload :Commands, "flay/commands"
7
+ autoload :Helpers, "flay/helpers"
8
+ autoload :VERSION, "flay/version"
9
+ end
data/lib/flay/cli.rb ADDED
@@ -0,0 +1,26 @@
1
+ class Flay::CLI < Thor
2
+ include Thor::Actions
3
+
4
+ package_name "flay"
5
+
6
+ Flay::Commands::Generate.register_with(self, as: "generate")
7
+ Flay::Commands::Release.register_with(self, as: "release")
8
+
9
+ method_option(
10
+ :chef_path,
11
+ type: :string,
12
+ desc: "The path that contains your knife.rb file",
13
+ default: "~/.chef-sweeper"
14
+ )
15
+ desc "link [--chef-path=PATH]", "symlinks .chef to --chef-path"
16
+ long_desc "Creates a symlink in the current directory from .chef to --chef-path"
17
+ def link
18
+ create_link File.join(Dir.pwd, ".chef"), options.fetch("chef_path")
19
+ end
20
+
21
+ desc "version", "display the current version"
22
+ long_desc "Show the current version of flay"
23
+ def version
24
+ say "flay version: #{Flay::VERSION}"
25
+ end
26
+ end
@@ -0,0 +1,4 @@
1
+ module Flay::Commands
2
+ autoload :Generate, "flay/commands/generate"
3
+ autoload :Release, "flay/commands/release"
4
+ end
@@ -0,0 +1,21 @@
1
+ class Flay::Commands::Generate < Thor
2
+ include Flay::Helpers
3
+
4
+ ARGS = "-C sweeper.io -m developers@sweeper.io -I mit".freeze
5
+
6
+ def self.register_with(thor, as: "MISSING NAME")
7
+ thor.register(self, as, "#{as} TYPE NAME", "generate a cookbook/recipe using flay defaults")
8
+ end
9
+
10
+ desc "cookbook NAME", "generate a cookbook"
11
+ long_desc "generates a cookbook with steeze"
12
+ def cookbook(name)
13
+ shell_exec("chef generate cookbook #{name} #{ARGS}")
14
+ end
15
+
16
+ desc "recipe NAME", "generate a recipe"
17
+ long_desc "generates a recipe with steeze"
18
+ def recipe(name)
19
+ shell_exec("chef generate recipe #{name} #{ARGS}")
20
+ end
21
+ end
@@ -0,0 +1,87 @@
1
+ class Flay::Commands::Release < Thor::Group
2
+ include Flay::Helpers
3
+ include Thor::Actions
4
+
5
+ ERROR_METADATA = "metadata.rb file not found in current repo".freeze
6
+ ERROR_GIT = "There are files that need to be committed before releasing".freeze
7
+ ERROR_VERSION = "Missing or invalid version in metadata.rb".freeze
8
+
9
+ VERSION_MATCH = /^\s*version\s*\(?'?"?([^"']+)"?'?\)?\s*$/.freeze
10
+
11
+ def self.register_with(thor, as: "MISSING NAME")
12
+ thor.register(self, as, as, "creates a release for this cookbook")
13
+ end
14
+
15
+ desc "creates a new release and uploads it"
16
+
17
+ def fail_fast
18
+ exit 1 unless git_repo? && git_clean? && git_committed?
19
+ exit 1 if version.nil?
20
+ end
21
+
22
+ def berks_install
23
+ say "Installing berks dependencies...", :green
24
+ shell_exec("chef exec berks install")
25
+ end
26
+
27
+ def create_tag
28
+ say "Tag for v#{version} already exists!", :green && return if tag_exists?
29
+ say "Creating tag for v#{version}...", :green
30
+ shell_exec("git tag -a -m \"Version #{version}\" v#{version}")
31
+ end
32
+
33
+ def push_commits_and_tags
34
+ say "Pushing commits and tags...", :green
35
+ exit 1 unless shell_exec_quiet("git push", error_message: "Couldn't push commits")
36
+ exit 1 unless shell_exec_quiet("git push --tags", error_message: "Couldn't push tags")
37
+ end
38
+
39
+ def berks_upload
40
+ say "Uploading cookbook to chef server...", :green
41
+ shell_exec("chef exec berks upload --no-ssl-verify")
42
+ end
43
+
44
+ def all_done
45
+ say "Done! Version v#{version} pushed to git remote and chef server.", :green
46
+ end
47
+
48
+ private
49
+
50
+ def version
51
+ return nil unless metadata_exists?
52
+
53
+ @version ||= begin
54
+ contents = File.read(metadata_path)
55
+ version = VERSION_MATCH.match(contents)
56
+ return version[1] if version && Gem::Version.correct?(version[1])
57
+
58
+ say ERROR_VERSION, :red
59
+ nil
60
+ end
61
+ end
62
+
63
+ def metadata_exists?
64
+ path = metadata_path
65
+ say ERROR_METADATA, :red unless path && File.exist?(path)
66
+ path && File.exist?(path)
67
+ end
68
+
69
+ def git_repo?
70
+ return true unless git_root.nil?
71
+ say ERROR_GIT, :red
72
+ false
73
+ end
74
+
75
+ def git_clean?
76
+ shell_exec_quiet("git diff --exit-code", error_message: ERROR_GIT)
77
+ end
78
+
79
+ def git_committed?
80
+ shell_exec_quiet("git diff-index --quiet --cached HEAD", error_message: ERROR_GIT)
81
+ end
82
+
83
+ def tag_exists?
84
+ tags = shell_exec("git tag").first
85
+ tags.include?("v#{version}")
86
+ end
87
+ end
@@ -0,0 +1,31 @@
1
+ module Flay::Helpers
2
+ def metadata_path
3
+ return nil if git_root.nil?
4
+ File.join(git_root, "metadata.rb")
5
+ end
6
+
7
+ def git_root
8
+ @git_root ||= begin
9
+ output, _, status = shell_exec("git rev-parse --show-toplevel", show_output: false)
10
+ return nil unless status == 0
11
+ output.chomp
12
+ end
13
+ end
14
+
15
+ def shell_exec(command, show_output: true)
16
+ output, error, status = Open3.capture3(command)
17
+
18
+ if show_output
19
+ say output
20
+ say error, :red unless status == 0
21
+ end
22
+
23
+ [output, error, status]
24
+ end
25
+
26
+ def shell_exec_quiet(command, error_message: nil)
27
+ status = shell_exec(command, show_output: false).last
28
+ say error_message, :red if error_message && status != 0
29
+ status == 0
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Flay
2
+ VERSION = "0.3.0".freeze
3
+ end
@@ -9,7 +9,6 @@ directory "#{cookbook_dir}/recipes"
9
9
  cookbook_file("#{cookbook_dir}/.gitignore") { source "gitignore" }
10
10
  cookbook_file("#{cookbook_dir}/.rubocop.yml") { source "rubocop.yml" }
11
11
  cookbook_file("#{cookbook_dir}/Berksfile") { action :create_if_missing }
12
- cookbook_file("#{cookbook_dir}/.bundle/config") { source "bundle_config" }
13
12
  cookbook_file "#{cookbook_dir}/chefignore"
14
13
  cookbook_file "#{cookbook_dir}/Gemfile"
15
14
  cookbook_file "#{cookbook_dir}/Rakefile"
@@ -20,6 +19,11 @@ flay_template "#{cookbook_dir}/README.md"
20
19
  # ChefSpec
21
20
  directory("#{cookbook_dir}/test/unit/recipes") { recursive true }
22
21
 
22
+ cookbook_file "#{cookbook_dir}/test/unit/spec_helper.rb" do
23
+ source "spec_helper.rb"
24
+ action :create_if_missing
25
+ end
26
+
23
27
  cookbook_file("#{cookbook_dir}/.rspec") { source "rspec" }
24
28
  cookbook_file("#{cookbook_dir}/.travis.yml") { source "travis.yml" }
25
29
 
@@ -40,11 +44,6 @@ cookbook_file "#{cookbook_dir}/test/integration/helpers/serverspec/spec_helper.r
40
44
  action :create_if_missing
41
45
  end
42
46
 
43
- cookbook_file "#{cookbook_dir}/test/unit/spec_helper.rb" do
44
- source "spec_helper.rb"
45
- action :create_if_missing
46
- end
47
-
48
47
  flay_template("#{cookbook_dir}/.kitchen.yml") { source "kitchen.yml.erb" }
49
48
 
50
49
  flay_template "#{cookbook_dir}/test/integration/default/serverspec/default_spec.rb" do
@@ -6,7 +6,10 @@ spec_path = File.join(cookbook_dir, "test", "unit", "recipes", "#{context
6
6
 
7
7
  directory("#{cookbook_dir}/test/unit/recipes") { recursive true }
8
8
 
9
- cookbook_file(spec_helper_path) { action :create_if_missing }
9
+ cookbook_file spec_helper_path do
10
+ source "spec_helper.rb"
11
+ action :create_if_missing
12
+ end
10
13
 
11
14
  flay_template(recipe_path) { source "recipe.rb.erb" }
12
15
  flay_template(spec_path) { source "recipe_spec.rb.erb" }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-flavor-flay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pseudomuto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-29 00:00:00.000000000 Z
11
+ date: 2015-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-gen-flavors
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.0'
27
41
  description: A Chef cookbook generator using [chef-gen-flavors](https://rubygems.org/gems/chef-gen-flavors)
28
42
  email:
29
43
  - developers@sweeper.io
@@ -33,6 +47,7 @@ extensions: []
33
47
  extra_rdoc_files: []
34
48
  files:
35
49
  - ".gitignore"
50
+ - ".rspec"
36
51
  - ".rubocop.yml"
37
52
  - ".ruby-version"
38
53
  - ".travis.yml"
@@ -43,13 +58,20 @@ files:
43
58
  - Rakefile
44
59
  - bin/console
45
60
  - bin/setup
61
+ - cucumber.yml
46
62
  - exe/flay
47
63
  - flay.gemspec
48
64
  - lib/chef_gen/flavor/flay.rb
65
+ - lib/flay.rb
66
+ - lib/flay/cli.rb
67
+ - lib/flay/commands.rb
68
+ - lib/flay/commands/generate.rb
69
+ - lib/flay/commands/release.rb
70
+ - lib/flay/helpers.rb
71
+ - lib/flay/version.rb
49
72
  - shared/flavor/flay/files/default/Berksfile
50
73
  - shared/flavor/flay/files/default/Gemfile
51
74
  - shared/flavor/flay/files/default/Rakefile
52
- - shared/flavor/flay/files/default/bundle_config
53
75
  - shared/flavor/flay/files/default/chefignore
54
76
  - shared/flavor/flay/files/default/encrypted_data_bag_secret
55
77
  - shared/flavor/flay/files/default/gitignore
@@ -1,3 +0,0 @@
1
- ---
2
- BUNDLE_DISABLE_SHARED_GEMS: "1"
3
- BUNDLE_WITHOUT: production