chef-dk 0.15.9 → 0.15.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +26 -24
- data/README.md +5 -1
- data/acceptance/Gemfile.lock +20 -18
- data/lib/chef-dk/command/generator_commands/base.rb +148 -148
- data/lib/chef-dk/command/generator_commands/build_cookbook.rb +5 -0
- data/lib/chef-dk/command/generator_commands/cookbook.rb +3 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/serverspec_spec_helper.rb +8 -8
- data/lib/chef-dk/skeletons/code_generator/recipes/app.rb +97 -97
- data/lib/chef-dk/skeletons/code_generator/recipes/build_cookbook.rb +64 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/cookbook.rb +15 -1
- data/lib/chef-dk/skeletons/code_generator/templates/default/serverspec_default_spec.rb.erb +9 -9
- data/lib/chef-dk/version.rb +1 -1
- data/omnibus_overrides.rb +1 -1
- data/spec/shared/custom_generator_cookbook.rb +7 -1
- data/spec/shared/setup_git_committer_config.rb +54 -0
- data/spec/unit/command/generator_commands/app_spec.rb +169 -169
- data/spec/unit/command/generator_commands/build_cookbook_spec.rb +39 -5
- data/spec/unit/command/generator_commands/cookbook_spec.rb +22 -14
- data/version_policy.rb +1 -1
- metadata +4 -2
@@ -56,6 +56,7 @@ module ChefDK
|
|
56
56
|
super
|
57
57
|
Generator.add_attr_to_context(:delivery_project_dir, delivery_project_dir)
|
58
58
|
|
59
|
+
Generator.add_attr_to_context(:delivery_project_git_initialized, delivery_project_git_initialized?)
|
59
60
|
Generator.add_attr_to_context(:build_cookbook_parent_is_cookbook, build_cookbook_parent_is_cookbook?)
|
60
61
|
end
|
61
62
|
|
@@ -91,6 +92,10 @@ module ChefDK
|
|
91
92
|
project_dir
|
92
93
|
end
|
93
94
|
|
95
|
+
def delivery_project_git_initialized?
|
96
|
+
File.exist?(File.join(delivery_project_dir, ".git"))
|
97
|
+
end
|
98
|
+
|
94
99
|
def read_and_validate_params
|
95
100
|
arguments = parse_options(params)
|
96
101
|
@cookbook_name_or_path = arguments[0]
|
@@ -72,6 +72,8 @@ module ChefDK
|
|
72
72
|
if params_valid?
|
73
73
|
setup_context
|
74
74
|
chef_runner.converge
|
75
|
+
msg("")
|
76
|
+
msg("Your cookbook is ready. Type `cd #{cookbook_name_or_path}` to start working.")
|
75
77
|
0
|
76
78
|
else
|
77
79
|
err(opt_parser)
|
@@ -96,6 +98,7 @@ module ChefDK
|
|
96
98
|
Generator.add_attr_to_context(:enable_delivery, enable_delivery?)
|
97
99
|
Generator.add_attr_to_context(:delivery_project_dir, cookbook_full_path)
|
98
100
|
Generator.add_attr_to_context(:build_cookbook_parent_is_cookbook, true)
|
101
|
+
Generator.add_attr_to_context(:delivery_project_git_initialized, have_git? && !cookbook_path_in_git_repo?)
|
99
102
|
|
100
103
|
Generator.add_attr_to_context(:use_berkshelf, berks_mode?)
|
101
104
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require 'serverspec'
|
2
|
-
|
3
|
-
if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM).nil?
|
4
|
-
set :backend, :exec
|
5
|
-
else
|
6
|
-
set :backend, :cmd
|
7
|
-
set :os, family: 'windows'
|
8
|
-
end
|
1
|
+
require 'serverspec'
|
2
|
+
|
3
|
+
if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM).nil?
|
4
|
+
set :backend, :exec
|
5
|
+
else
|
6
|
+
set :backend, :cmd
|
7
|
+
set :os, family: 'windows'
|
8
|
+
end
|
@@ -1,97 +1,97 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
context = ChefDK::Generator.context
|
4
|
-
app_dir = File.join(context.app_root, context.app_name)
|
5
|
-
cookbooks_dir = context.cookbook_root
|
6
|
-
cookbook_dir = File.join(cookbooks_dir, context.cookbook_name)
|
7
|
-
|
8
|
-
# app root dir
|
9
|
-
directory app_dir
|
10
|
-
|
11
|
-
# Top level files
|
12
|
-
|
13
|
-
# TK
|
14
|
-
template "#{app_dir}/.kitchen.yml" do
|
15
|
-
source 'kitchen.yml.erb'
|
16
|
-
helpers(ChefDK::Generator::TemplateHelper)
|
17
|
-
end
|
18
|
-
|
19
|
-
directory "#{app_dir}/test/integration/default/serverspec" do
|
20
|
-
recursive true
|
21
|
-
end
|
22
|
-
|
23
|
-
directory "#{app_dir}/test/integration/helpers/serverspec" do
|
24
|
-
recursive true
|
25
|
-
end
|
26
|
-
|
27
|
-
cookbook_file "#{app_dir}/test/integration/helpers/serverspec/spec_helper.rb" do
|
28
|
-
source 'serverspec_spec_helper.rb'
|
29
|
-
action :create_if_missing
|
30
|
-
end
|
31
|
-
|
32
|
-
template "#{app_dir}/test/integration/default/serverspec/default_spec.rb" do
|
33
|
-
source 'serverspec_default_spec.rb.erb'
|
34
|
-
helpers(ChefDK::Generator::TemplateHelper)
|
35
|
-
action :create_if_missing
|
36
|
-
end
|
37
|
-
|
38
|
-
# README
|
39
|
-
template "#{app_dir}/README.md" do
|
40
|
-
helpers(ChefDK::Generator::TemplateHelper)
|
41
|
-
end
|
42
|
-
|
43
|
-
# Generated Cookbook:
|
44
|
-
|
45
|
-
# cookbook collection dir
|
46
|
-
directory cookbooks_dir
|
47
|
-
|
48
|
-
# cookbook collection dir
|
49
|
-
directory cookbook_dir
|
50
|
-
|
51
|
-
# metadata.rb
|
52
|
-
template "#{cookbook_dir}/metadata.rb" do
|
53
|
-
helpers(ChefDK::Generator::TemplateHelper)
|
54
|
-
end
|
55
|
-
|
56
|
-
# chefignore
|
57
|
-
cookbook_file "#{cookbook_dir}/chefignore"
|
58
|
-
|
59
|
-
# Berks
|
60
|
-
cookbook_file "#{cookbook_dir}/Berksfile"
|
61
|
-
|
62
|
-
# Recipes
|
63
|
-
|
64
|
-
directory "#{cookbook_dir}/recipes"
|
65
|
-
|
66
|
-
template "#{cookbook_dir}/recipes/default.rb" do
|
67
|
-
source "recipe.rb.erb"
|
68
|
-
helpers(ChefDK::Generator::TemplateHelper)
|
69
|
-
end
|
70
|
-
|
71
|
-
# Chefspec
|
72
|
-
directory "#{cookbook_dir}/spec/unit/recipes" do
|
73
|
-
recursive true
|
74
|
-
end
|
75
|
-
|
76
|
-
cookbook_file "#{cookbook_dir}/spec/spec_helper.rb" do
|
77
|
-
action :create_if_missing
|
78
|
-
end
|
79
|
-
|
80
|
-
template "#{cookbook_dir}/spec/unit/recipes/default_spec.rb" do
|
81
|
-
source "recipe_spec.rb.erb"
|
82
|
-
helpers(ChefDK::Generator::TemplateHelper)
|
83
|
-
action :create_if_missing
|
84
|
-
end
|
85
|
-
|
86
|
-
# git
|
87
|
-
if context.have_git
|
88
|
-
if !context.skip_git_init
|
89
|
-
execute("initialize-git") do
|
90
|
-
command("git init .")
|
91
|
-
cwd app_dir
|
92
|
-
end
|
93
|
-
end
|
94
|
-
cookbook_file "#{app_dir}/.gitignore" do
|
95
|
-
source "gitignore"
|
96
|
-
end
|
97
|
-
end
|
1
|
+
|
2
|
+
|
3
|
+
context = ChefDK::Generator.context
|
4
|
+
app_dir = File.join(context.app_root, context.app_name)
|
5
|
+
cookbooks_dir = context.cookbook_root
|
6
|
+
cookbook_dir = File.join(cookbooks_dir, context.cookbook_name)
|
7
|
+
|
8
|
+
# app root dir
|
9
|
+
directory app_dir
|
10
|
+
|
11
|
+
# Top level files
|
12
|
+
|
13
|
+
# TK
|
14
|
+
template "#{app_dir}/.kitchen.yml" do
|
15
|
+
source 'kitchen.yml.erb'
|
16
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
17
|
+
end
|
18
|
+
|
19
|
+
directory "#{app_dir}/test/integration/default/serverspec" do
|
20
|
+
recursive true
|
21
|
+
end
|
22
|
+
|
23
|
+
directory "#{app_dir}/test/integration/helpers/serverspec" do
|
24
|
+
recursive true
|
25
|
+
end
|
26
|
+
|
27
|
+
cookbook_file "#{app_dir}/test/integration/helpers/serverspec/spec_helper.rb" do
|
28
|
+
source 'serverspec_spec_helper.rb'
|
29
|
+
action :create_if_missing
|
30
|
+
end
|
31
|
+
|
32
|
+
template "#{app_dir}/test/integration/default/serverspec/default_spec.rb" do
|
33
|
+
source 'serverspec_default_spec.rb.erb'
|
34
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
35
|
+
action :create_if_missing
|
36
|
+
end
|
37
|
+
|
38
|
+
# README
|
39
|
+
template "#{app_dir}/README.md" do
|
40
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Generated Cookbook:
|
44
|
+
|
45
|
+
# cookbook collection dir
|
46
|
+
directory cookbooks_dir
|
47
|
+
|
48
|
+
# cookbook collection dir
|
49
|
+
directory cookbook_dir
|
50
|
+
|
51
|
+
# metadata.rb
|
52
|
+
template "#{cookbook_dir}/metadata.rb" do
|
53
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
54
|
+
end
|
55
|
+
|
56
|
+
# chefignore
|
57
|
+
cookbook_file "#{cookbook_dir}/chefignore"
|
58
|
+
|
59
|
+
# Berks
|
60
|
+
cookbook_file "#{cookbook_dir}/Berksfile"
|
61
|
+
|
62
|
+
# Recipes
|
63
|
+
|
64
|
+
directory "#{cookbook_dir}/recipes"
|
65
|
+
|
66
|
+
template "#{cookbook_dir}/recipes/default.rb" do
|
67
|
+
source "recipe.rb.erb"
|
68
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Chefspec
|
72
|
+
directory "#{cookbook_dir}/spec/unit/recipes" do
|
73
|
+
recursive true
|
74
|
+
end
|
75
|
+
|
76
|
+
cookbook_file "#{cookbook_dir}/spec/spec_helper.rb" do
|
77
|
+
action :create_if_missing
|
78
|
+
end
|
79
|
+
|
80
|
+
template "#{cookbook_dir}/spec/unit/recipes/default_spec.rb" do
|
81
|
+
source "recipe_spec.rb.erb"
|
82
|
+
helpers(ChefDK::Generator::TemplateHelper)
|
83
|
+
action :create_if_missing
|
84
|
+
end
|
85
|
+
|
86
|
+
# git
|
87
|
+
if context.have_git
|
88
|
+
if !context.skip_git_init
|
89
|
+
execute("initialize-git") do
|
90
|
+
command("git init .")
|
91
|
+
cwd app_dir
|
92
|
+
end
|
93
|
+
end
|
94
|
+
cookbook_file "#{app_dir}/.gitignore" do
|
95
|
+
source "gitignore"
|
96
|
+
end
|
97
|
+
end
|
@@ -86,3 +86,67 @@ cookbook_file "#{build_cookbook_dir}/test/fixtures/cookbooks/test/recipes/defaul
|
|
86
86
|
source "build-cookbook/test-fixture-recipe.rb"
|
87
87
|
end
|
88
88
|
|
89
|
+
# Construct git history as if we did all the work in a feature branch which we
|
90
|
+
# merged into master at the end, which looks like this:
|
91
|
+
#
|
92
|
+
# ```
|
93
|
+
# git log --graph --oneline
|
94
|
+
# * 5fec5bd Merge branch 'add-delivery-configuration'
|
95
|
+
# |\
|
96
|
+
# | * 967bb9f Add generated delivery build cookbook
|
97
|
+
# | * 1558e0a Add generated delivery configuration
|
98
|
+
# |/
|
99
|
+
# * db22790 Add generated cookbook content
|
100
|
+
# ```
|
101
|
+
#
|
102
|
+
if context.have_git && context.delivery_project_git_initialized && !context.skip_git_init
|
103
|
+
|
104
|
+
execute("git-create-feature-branch") do
|
105
|
+
command("git checkout -t -b add-delivery-configuration")
|
106
|
+
cwd delivery_project_dir
|
107
|
+
end
|
108
|
+
|
109
|
+
execute("git-add-delivery-config-json") do
|
110
|
+
command("git add .delivery/config.json")
|
111
|
+
cwd delivery_project_dir
|
112
|
+
|
113
|
+
only_if "git status --porcelain |grep \".\""
|
114
|
+
end
|
115
|
+
|
116
|
+
execute("git-commit-delivery-config") do
|
117
|
+
command("git commit -m \"Add generated delivery configuration\"")
|
118
|
+
cwd delivery_project_dir
|
119
|
+
|
120
|
+
only_if "git status --porcelain |grep \".\""
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
execute("git-add-delivery-build-cookbook-files") do
|
125
|
+
command("git add .delivery")
|
126
|
+
cwd delivery_project_dir
|
127
|
+
|
128
|
+
only_if "git status --porcelain |grep \".\""
|
129
|
+
end
|
130
|
+
|
131
|
+
execute("git-commit-delivery-build-cookbook") do
|
132
|
+
command("git commit -m \"Add generated delivery build cookbook\"")
|
133
|
+
cwd delivery_project_dir
|
134
|
+
|
135
|
+
only_if "git status --porcelain |grep \".\""
|
136
|
+
end
|
137
|
+
|
138
|
+
execute("git-return-to-master-branch") do
|
139
|
+
command("git checkout master")
|
140
|
+
cwd delivery_project_dir
|
141
|
+
end
|
142
|
+
|
143
|
+
execute("git-merge-delivery-config-branch") do
|
144
|
+
command("git merge --no-ff add-delivery-configuration")
|
145
|
+
cwd delivery_project_dir
|
146
|
+
end
|
147
|
+
|
148
|
+
execute("git-remove-delivery-config-branch") do
|
149
|
+
command("git branch -d add-delivery-configuration")
|
150
|
+
cwd delivery_project_dir
|
151
|
+
end
|
152
|
+
end
|
@@ -103,17 +103,31 @@ end
|
|
103
103
|
|
104
104
|
# git
|
105
105
|
if context.have_git
|
106
|
-
|
106
|
+
unless context.skip_git_init
|
107
107
|
|
108
108
|
execute("initialize-git") do
|
109
109
|
command("git init .")
|
110
110
|
cwd cookbook_dir
|
111
111
|
end
|
112
|
+
|
112
113
|
end
|
113
114
|
|
114
115
|
cookbook_file "#{cookbook_dir}/.gitignore" do
|
115
116
|
source "gitignore"
|
116
117
|
end
|
118
|
+
|
119
|
+
unless context.skip_git_init
|
120
|
+
|
121
|
+
execute("git-add-new-files") do
|
122
|
+
command("git add .")
|
123
|
+
cwd cookbook_dir
|
124
|
+
end
|
125
|
+
|
126
|
+
execute("git-commit-new-files") do
|
127
|
+
command("git commit -m \"Add generated cookbook content\"")
|
128
|
+
cwd cookbook_dir
|
129
|
+
end
|
130
|
+
end
|
117
131
|
end
|
118
132
|
|
119
133
|
if context.enable_delivery
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '<%= cookbook_name %>::default' do
|
4
|
-
# Serverspec examples can be found at
|
5
|
-
# http://serverspec.org/resource_types.html
|
6
|
-
it 'does something' do
|
7
|
-
skip 'Replace this with meaningful tests'
|
8
|
-
end
|
9
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '<%= cookbook_name %>::default' do
|
4
|
+
# Serverspec examples can be found at
|
5
|
+
# http://serverspec.org/resource_types.html
|
6
|
+
it 'does something' do
|
7
|
+
skip 'Replace this with meaningful tests'
|
8
|
+
end
|
9
|
+
end
|
data/lib/chef-dk/version.rb
CHANGED
data/omnibus_overrides.rb
CHANGED
@@ -16,7 +16,13 @@ shared_examples_for "custom generator cookbook" do
|
|
16
16
|
|
17
17
|
let(:argv) { [generator_arg, "--generator-cookbook", generator_cookbook_path] }
|
18
18
|
|
19
|
-
|
19
|
+
let(:stdout_io) { StringIO.new }
|
20
|
+
|
21
|
+
subject(:code_generator) do
|
22
|
+
described_class.new(argv).tap do |gen|
|
23
|
+
allow(gen).to receive(:stdout).and_return(stdout_io)
|
24
|
+
end
|
25
|
+
end
|
20
26
|
|
21
27
|
before do
|
22
28
|
reset_tempdir
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2016 Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "mixlib/shellout"
|
19
|
+
|
20
|
+
RSpec.shared_context("setup_git_committer_config") do
|
21
|
+
|
22
|
+
def _have_git_config_key?(key)
|
23
|
+
cmd = Mixlib::ShellOut.new("git config --global #{key}", returns: [0,1])
|
24
|
+
cmd.run_command
|
25
|
+
cmd.error!
|
26
|
+
cmd.status.success?
|
27
|
+
end
|
28
|
+
|
29
|
+
def _git_config(subcommand_args)
|
30
|
+
cmd = Mixlib::ShellOut.new("git config --global #{subcommand_args}")
|
31
|
+
cmd.run_command
|
32
|
+
cmd.error!
|
33
|
+
cmd
|
34
|
+
end
|
35
|
+
|
36
|
+
before(:all) do
|
37
|
+
unless _have_git_config_key?("user.name")
|
38
|
+
_git_config("user.name \"chefdk_rspec_user\"")
|
39
|
+
end
|
40
|
+
unless _have_git_config_key?("user.email")
|
41
|
+
_git_config("user.email \"chefdk_rspec_user@example.com\"")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
after(:all) do
|
46
|
+
if _git_config("user.name").stdout.include?("chefdk_rspec_user")
|
47
|
+
_git_config("--unset user.name")
|
48
|
+
end
|
49
|
+
if _git_config("user.email").stdout.include?("chefdk_rspec_user")
|
50
|
+
_git_config("--unset user.email")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|