chef-dk 0.3.5 → 0.4.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 +4 -4
- data/CONTRIBUTING.md +4 -4
- data/README.md +4 -4
- data/lib/chef-dk/builtin_commands.rb +4 -0
- data/lib/chef-dk/chef_runner.rb +7 -1
- data/lib/chef-dk/command/exec.rb +9 -0
- data/lib/chef-dk/command/export.rb +132 -0
- data/lib/chef-dk/command/generator_commands.rb +1 -1
- data/lib/chef-dk/command/generator_commands/app.rb +8 -0
- data/lib/chef-dk/command/generator_commands/base.rb +46 -4
- data/lib/chef-dk/command/generator_commands/cookbook.rb +8 -0
- data/lib/chef-dk/command/generator_commands/cookbook_code_file.rb +1 -0
- data/lib/chef-dk/command/push.rb +3 -6
- data/lib/chef-dk/command/shell_init.rb +28 -5
- data/lib/chef-dk/command/update.rb +106 -0
- data/lib/chef-dk/command/verify.rb +72 -0
- data/lib/chef-dk/component_test.rb +12 -1
- data/lib/chef-dk/configurable.rb +52 -0
- data/lib/chef-dk/cookbook_metadata.rb +10 -1
- data/lib/chef-dk/cookbook_profiler/git.rb +1 -1
- data/lib/chef-dk/exceptions.rb +17 -2
- data/lib/chef-dk/helpers.rb +2 -2
- data/lib/chef-dk/policyfile/community_cookbook_source.rb +1 -1
- data/lib/chef-dk/policyfile/dsl.rb +7 -0
- data/lib/chef-dk/policyfile/uploader.rb +25 -4
- data/lib/chef-dk/policyfile_compiler.rb +21 -1
- data/lib/chef-dk/policyfile_lock.rb +5 -0
- data/lib/chef-dk/policyfile_services/export_repo.rb +194 -0
- data/lib/chef-dk/policyfile_services/install.rb +8 -2
- data/lib/chef-dk/policyfile_services/push.rb +4 -1
- data/lib/chef-dk/service_exceptions.rb +6 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/Berksfile +1 -1
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/README.md +1 -1
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/cookbooks/README.md +1 -1
- data/lib/chef-dk/skeletons/code_generator/files/default/repo/environments/README.md +2 -2
- data/lib/chef-dk/skeletons/code_generator/files/default/serverspec_spec_helper.rb +3 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/spec_helper.rb +1 -7
- data/lib/chef-dk/skeletons/code_generator/metadata.rb +1 -1
- data/lib/chef-dk/skeletons/code_generator/recipes/app.rb +31 -1
- data/lib/chef-dk/skeletons/code_generator/recipes/cookbook.rb +32 -2
- data/lib/chef-dk/skeletons/code_generator/recipes/recipe.rb +18 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/recipe.rb.erb +5 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/recipe_spec.rb.erb +23 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/serverspec_default_spec.rb.erb +12 -0
- data/lib/chef-dk/version.rb +1 -1
- data/lib/kitchen/provisioner/policyfile_zero.rb +149 -0
- data/spec/shared/a_file_generator.rb +1 -0
- data/spec/shared/command_with_ui_object.rb +11 -0
- data/spec/shared/custom_generator_cookbook.rb +117 -0
- data/spec/unit/chef_runner_spec.rb +26 -0
- data/spec/unit/command/exec_spec.rb +46 -5
- data/spec/unit/command/export_spec.rb +176 -0
- data/spec/unit/command/generator_commands/app_spec.rb +38 -0
- data/spec/unit/command/generator_commands/cookbook_spec.rb +37 -28
- data/spec/unit/command/generator_commands/recipe_spec.rb +4 -2
- data/spec/unit/command/install_spec.rb +3 -6
- data/spec/unit/command/push_spec.rb +3 -6
- data/spec/unit/command/shell_init_spec.rb +77 -49
- data/spec/unit/command/update_spec.rb +155 -0
- data/spec/unit/command/verify_spec.rb +22 -7
- data/spec/unit/cookbook_metadata_spec.rb +44 -8
- data/spec/unit/cookbook_profiler/git_spec.rb +12 -0
- data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/Berksfile +1 -1
- data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/Berksfile +1 -1
- data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/Berksfile +1 -1
- data/spec/unit/fixtures/cookbooks_api/small_universe.json +667 -667
- data/spec/unit/fixtures/cookbooks_api/universe.json +1 -1
- data/spec/unit/fixtures/cookbooks_api/update_fixtures.rb +1 -1
- data/spec/unit/fixtures/example_cookbook/Berksfile +1 -1
- data/spec/unit/fixtures/example_cookbook_metadata_json_only/.gitignore +17 -0
- data/spec/unit/fixtures/example_cookbook_metadata_json_only/.kitchen.yml +16 -0
- data/spec/unit/fixtures/example_cookbook_metadata_json_only/Berksfile +3 -0
- data/spec/unit/fixtures/example_cookbook_metadata_json_only/README.md +4 -0
- data/spec/unit/fixtures/example_cookbook_metadata_json_only/chefignore +96 -0
- data/spec/unit/fixtures/example_cookbook_metadata_json_only/metadata.json +5 -0
- data/spec/unit/fixtures/example_cookbook_metadata_json_only/recipes/default.rb +8 -0
- data/spec/unit/fixtures/example_cookbook_no_metadata/.gitignore +17 -0
- data/spec/unit/fixtures/example_cookbook_no_metadata/.kitchen.yml +16 -0
- data/spec/unit/fixtures/example_cookbook_no_metadata/Berksfile +3 -0
- data/spec/unit/fixtures/example_cookbook_no_metadata/README.md +4 -0
- data/spec/unit/fixtures/example_cookbook_no_metadata/chefignore +96 -0
- data/spec/unit/fixtures/example_cookbook_no_metadata/recipes/default.rb +8 -0
- data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/Berksfile +1 -1
- data/spec/unit/policyfile/community_cookbook_source_spec.rb +2 -2
- data/spec/unit/policyfile/cookbook_location_specification_spec.rb +3 -3
- data/spec/unit/policyfile/uploader_spec.rb +61 -25
- data/spec/unit/policyfile_demands_spec.rb +47 -0
- data/spec/unit/policyfile_evaluation_spec.rb +1 -1
- data/spec/unit/policyfile_lock_build_spec.rb +60 -3
- data/spec/unit/policyfile_services/export_repo_spec.rb +321 -0
- data/spec/unit/policyfile_services/install_spec.rb +20 -1
- data/spec/unit/policyfile_services/push_spec.rb +36 -9
- metadata +53 -38
- data/lib/chef-dk/skeletons/code_generator/files/default/converge_spec.rb +0 -9
- data/lib/chef-dk/skeletons/code_generator/templates/default/default_recipe.rb.erb +0 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dc8cebdbcdaa5a3c3f4e2b3bf18fc1c3caca8843
|
|
4
|
+
data.tar.gz: 9f57e9e37cf5b66823e9a6e3f6470afb369177fe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0f3578a7438281d5360cc4278e16e424e84c1dcec4f7087a8d9ce9dbbecd8a0e74c3b67d5fde04128bf58ee7815a21f3a48e12d444241928f2f2dd75cc1dc082
|
|
7
|
+
data.tar.gz: e2e691462cb8febe46e0fec9d07f5f6f21e1bfc73bb89c7bb7556e475253f25ad75f521521cdd523f61c62ceaa3ab7323aead451a568c5339e9bd64c0ca61e21
|
data/CONTRIBUTING.md
CHANGED
|
@@ -174,7 +174,7 @@ We frequently make `alpha` and `beta` releases with version numbers that look li
|
|
|
174
174
|
We do a `Minor` release approximately every 3 months and `Patch` releases on a when-needed
|
|
175
175
|
basis for regressions, significant bugs, and security issues.
|
|
176
176
|
|
|
177
|
-
Announcements of releases are available on [Chef Blog](
|
|
177
|
+
Announcements of releases are available on [Chef Blog](https://www.chef.io/blog/) when they are
|
|
178
178
|
available.
|
|
179
179
|
|
|
180
180
|
## Chef Community
|
|
@@ -187,6 +187,6 @@ Chef is made possible by a strong community of developers and system administrat
|
|
|
187
187
|
|
|
188
188
|
Also here are some additional pointers to some awesome Chef content:
|
|
189
189
|
|
|
190
|
-
* [Chef Docs](
|
|
191
|
-
* [Learn Chef](https://
|
|
192
|
-
* [Chef Inc](
|
|
190
|
+
* [Chef Docs](https://docs.chef.io/)
|
|
191
|
+
* [Learn Chef](https://learn.chef.io/)
|
|
192
|
+
* [Chef Inc](https://www.chef.io/)
|
data/README.md
CHANGED
|
@@ -219,10 +219,10 @@ dpkg -P chefdk
|
|
|
219
219
|
- - -
|
|
220
220
|
|
|
221
221
|
[Berkshelf]: http://berkshelf.com "Berkshelf"
|
|
222
|
-
[Chef]: https://www.
|
|
223
|
-
[ChefDK]: https://www.
|
|
224
|
-
[Chef Documentation]: http://docs.
|
|
222
|
+
[Chef]: https://www.chef.io "Chef"
|
|
223
|
+
[ChefDK]: https://www.chef.io/downloads/chef-dk "Chef Development Kit"
|
|
224
|
+
[Chef Documentation]: http://docs.chef.io "Chef Documentation"
|
|
225
225
|
[ChefSpec]: http://chefspec.org "ChefSpec"
|
|
226
226
|
[Foodcritic]: http://foodcritic.io "Foodcritic"
|
|
227
|
-
[Learn Chef]: http://learn.
|
|
227
|
+
[Learn Chef]: http://learn.chef.io "Learn Chef"
|
|
228
228
|
[Test Kitchen]: http://kitchen.ci "Test Kitchen"
|
|
@@ -29,7 +29,11 @@ ChefDK.commands do |c|
|
|
|
29
29
|
|
|
30
30
|
c.builtin "install", :Install, desc: "Install cookbooks from a Policyfile and generate a locked cookbook set"
|
|
31
31
|
|
|
32
|
+
c.builtin "update", :Update, desc: "Updates a Policyfile.lock.json with latest run_list and cookbooks"
|
|
33
|
+
|
|
32
34
|
c.builtin "push", :Push, desc: "Push a local policy lock to a policy group on the server"
|
|
33
35
|
|
|
36
|
+
c.builtin "export", :Export, desc: "Export a policy lock as a Chef Zero code repo"
|
|
37
|
+
|
|
34
38
|
c.builtin "verify", :Verify, desc: "Test the embedded ChefDK applications"
|
|
35
39
|
end
|
data/lib/chef-dk/chef_runner.rb
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
# limitations under the License.
|
|
16
16
|
#
|
|
17
17
|
|
|
18
|
+
require 'chef-dk/exceptions'
|
|
18
19
|
require 'chef'
|
|
19
20
|
|
|
20
21
|
module ChefDK
|
|
@@ -25,7 +26,7 @@ module ChefDK
|
|
|
25
26
|
attr_reader :run_list
|
|
26
27
|
|
|
27
28
|
def initialize(cookbook_path, run_list)
|
|
28
|
-
@cookbook_path = cookbook_path
|
|
29
|
+
@cookbook_path = File.expand_path(cookbook_path)
|
|
29
30
|
@run_list = run_list
|
|
30
31
|
@formatter = nil
|
|
31
32
|
@ohai = nil
|
|
@@ -34,6 +35,11 @@ module ChefDK
|
|
|
34
35
|
def converge
|
|
35
36
|
configure
|
|
36
37
|
Chef::Runner.new(run_context).converge
|
|
38
|
+
rescue Chef::Exceptions::CookbookNotFound => e
|
|
39
|
+
message = "Could not find cookbook(s) to satisfy run list #{run_list.inspect} in #{cookbook_path}"
|
|
40
|
+
raise CookbookNotFound.new(message, e)
|
|
41
|
+
rescue => e
|
|
42
|
+
raise ChefConvergeError.new("Chef failed to converge: #{e}", e)
|
|
37
43
|
end
|
|
38
44
|
|
|
39
45
|
def run_context
|
data/lib/chef-dk/command/exec.rb
CHANGED
|
@@ -30,6 +30,15 @@ module ChefDK
|
|
|
30
30
|
exec(*params)
|
|
31
31
|
raise "Exec failed without an exception, your ruby is buggy" # should never get here
|
|
32
32
|
end
|
|
33
|
+
|
|
34
|
+
def needs_version?(params)
|
|
35
|
+
# Force version to get passed down to command
|
|
36
|
+
false
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def needs_help?(params)
|
|
40
|
+
['-h', '--help'].include? params[0]
|
|
41
|
+
end
|
|
33
42
|
end
|
|
34
43
|
end
|
|
35
44
|
end
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright:: Copyright (c) 2014 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 'chef-dk/command/base'
|
|
19
|
+
require 'chef-dk/ui'
|
|
20
|
+
require 'chef-dk/policyfile_services/export_repo'
|
|
21
|
+
require 'chef-dk/configurable'
|
|
22
|
+
|
|
23
|
+
module ChefDK
|
|
24
|
+
module Command
|
|
25
|
+
|
|
26
|
+
class Export < Base
|
|
27
|
+
|
|
28
|
+
include Configurable
|
|
29
|
+
|
|
30
|
+
banner(<<-E)
|
|
31
|
+
Usage: chef export [ POLICY_FILE ] DESTINATION_DIRECTORY [options]
|
|
32
|
+
|
|
33
|
+
`chef export` creates a Chef Zero compatible Chef repository containing the
|
|
34
|
+
cookbooks described in a Policyfile.lock.json. Once the exported repo is copied
|
|
35
|
+
to the target machine, you can apply the policy to the machine with
|
|
36
|
+
`chef-client -z`. You will need at least the following config:
|
|
37
|
+
|
|
38
|
+
use_policyfile true
|
|
39
|
+
deployment_group '$POLICY_NAME-local'
|
|
40
|
+
versioned_cookbooks true
|
|
41
|
+
|
|
42
|
+
The Policyfile feature is incomplete and beta quality. See our detailed README
|
|
43
|
+
for more information.
|
|
44
|
+
|
|
45
|
+
https://github.com/opscode/chef-dk/blob/master/POLICYFILE_README.md
|
|
46
|
+
|
|
47
|
+
Options:
|
|
48
|
+
|
|
49
|
+
E
|
|
50
|
+
|
|
51
|
+
option :force,
|
|
52
|
+
short: "-f",
|
|
53
|
+
long: "--force",
|
|
54
|
+
description: "If the DESTINATION_DIRECTORY is not empty, remove its content.",
|
|
55
|
+
default: false,
|
|
56
|
+
boolean: true
|
|
57
|
+
|
|
58
|
+
option :debug,
|
|
59
|
+
short: "-D",
|
|
60
|
+
long: "--debug",
|
|
61
|
+
description: "Enable stacktraces and other debug output",
|
|
62
|
+
default: false
|
|
63
|
+
|
|
64
|
+
attr_reader :policyfile_relative_path
|
|
65
|
+
attr_reader :export_dir
|
|
66
|
+
|
|
67
|
+
attr_accessor :ui
|
|
68
|
+
|
|
69
|
+
def initialize(*args)
|
|
70
|
+
super
|
|
71
|
+
@push = nil
|
|
72
|
+
@ui = nil
|
|
73
|
+
@policyfile_relative_path = nil
|
|
74
|
+
@export_dir = nil
|
|
75
|
+
@chef_config = nil
|
|
76
|
+
@ui = UI.new
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def run(params = [])
|
|
80
|
+
return 1 unless apply_params!(params)
|
|
81
|
+
export_service.run
|
|
82
|
+
ui.msg("Exported policy '#{export_service.policyfile_lock.name}' to #{export_dir}")
|
|
83
|
+
0
|
|
84
|
+
rescue ExportDirNotEmpty => e
|
|
85
|
+
ui.err("ERROR: " + e.message)
|
|
86
|
+
ui.err("Use --force to force export")
|
|
87
|
+
1
|
|
88
|
+
rescue PolicyfileServiceError => e
|
|
89
|
+
handle_error(e)
|
|
90
|
+
1
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def debug?
|
|
94
|
+
!!config[:debug]
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def export_service
|
|
98
|
+
@export_service ||= PolicyfileServices::ExportRepo.new(policyfile: policyfile_relative_path,
|
|
99
|
+
export_dir: export_dir,
|
|
100
|
+
root_dir: Dir.pwd,
|
|
101
|
+
force: config[:force])
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def handle_error(error)
|
|
105
|
+
ui.err("Error: #{error.message}")
|
|
106
|
+
if error.respond_to?(:reason)
|
|
107
|
+
ui.err("Reason: #{error.reason}")
|
|
108
|
+
ui.err("")
|
|
109
|
+
ui.err(error.extended_error_info) if debug?
|
|
110
|
+
ui.err(error.cause.backtrace.join("\n")) if debug?
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def apply_params!(params)
|
|
115
|
+
remaining_args = parse_options(params)
|
|
116
|
+
case remaining_args.size
|
|
117
|
+
when 1
|
|
118
|
+
@export_dir = remaining_args[0]
|
|
119
|
+
when 2
|
|
120
|
+
@policyfile_relative_path, @export_dir = remaining_args
|
|
121
|
+
else
|
|
122
|
+
ui.err(banner)
|
|
123
|
+
return false
|
|
124
|
+
end
|
|
125
|
+
true
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
|
|
@@ -55,7 +55,7 @@ module ChefDK
|
|
|
55
55
|
:short => "-g GENERATOR_COOKBOOK_PATH",
|
|
56
56
|
:long => "--generator-cookbook GENERATOR_COOKBOOK_PATH",
|
|
57
57
|
:description => "Use GENERATOR_COOKBOOK_PATH for the code_generator cookbook",
|
|
58
|
-
:default =>
|
|
58
|
+
:default => nil,
|
|
59
59
|
:proc => Proc.new { |s| File.expand_path(s) },
|
|
60
60
|
:on => :tail
|
|
61
61
|
|
|
@@ -49,6 +49,9 @@ module ChefDK
|
|
|
49
49
|
msg(banner)
|
|
50
50
|
1
|
|
51
51
|
end
|
|
52
|
+
rescue ChefDK::ChefRunnerError => e
|
|
53
|
+
err("ERROR: #{e}")
|
|
54
|
+
1
|
|
52
55
|
end
|
|
53
56
|
|
|
54
57
|
def setup_context
|
|
@@ -57,12 +60,17 @@ module ChefDK
|
|
|
57
60
|
Generator.add_attr_to_context(:app_name, app_name)
|
|
58
61
|
Generator.add_attr_to_context(:cookbook_root, cookbook_root)
|
|
59
62
|
Generator.add_attr_to_context(:cookbook_name, cookbook_name)
|
|
63
|
+
Generator.add_attr_to_context(:recipe_name, recipe_name)
|
|
60
64
|
end
|
|
61
65
|
|
|
62
66
|
def recipe
|
|
63
67
|
"app"
|
|
64
68
|
end
|
|
65
69
|
|
|
70
|
+
def recipe_name
|
|
71
|
+
"default"
|
|
72
|
+
end
|
|
73
|
+
|
|
66
74
|
def app_name
|
|
67
75
|
File.basename(app_full_path)
|
|
68
76
|
end
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
# limitations under the License.
|
|
16
16
|
#
|
|
17
17
|
|
|
18
|
+
require 'chef-dk/configurable'
|
|
18
19
|
require 'chef-dk/command/generator_commands'
|
|
19
20
|
|
|
20
21
|
module ChefDK
|
|
@@ -31,6 +32,8 @@ module ChefDK
|
|
|
31
32
|
# chef-dk/skeletons/code_generator.
|
|
32
33
|
class Base < Command::Base
|
|
33
34
|
|
|
35
|
+
include Configurable
|
|
36
|
+
|
|
34
37
|
attr_reader :params
|
|
35
38
|
|
|
36
39
|
options.merge!(SharedGeneratorOptions.options)
|
|
@@ -38,19 +41,26 @@ module ChefDK
|
|
|
38
41
|
def initialize(params)
|
|
39
42
|
super()
|
|
40
43
|
@params = params
|
|
44
|
+
|
|
45
|
+
@generator_cookbook_path = nil
|
|
46
|
+
@generator_cookbook_name = nil
|
|
41
47
|
end
|
|
42
48
|
|
|
43
49
|
# An instance of ChefRunner. Calling ChefRunner#converge will trigger
|
|
44
50
|
# convergence and generate the desired code.
|
|
45
51
|
def chef_runner
|
|
46
|
-
@chef_runner ||= ChefRunner.new(generator_cookbook_path, ["
|
|
52
|
+
@chef_runner ||= ChefRunner.new(generator_cookbook_path, ["recipe[#{generator_cookbook_name}::#{recipe}]"])
|
|
47
53
|
end
|
|
48
54
|
|
|
49
55
|
# Path to the directory where the code_generator cookbook is located.
|
|
50
|
-
# For now, this is hard coded to the 'skeletons' directory in this
|
|
51
|
-
# repo.
|
|
52
56
|
def generator_cookbook_path
|
|
53
|
-
|
|
57
|
+
detect_generator_cookbook_name_and_path! unless @generator_cookbook_path
|
|
58
|
+
@generator_cookbook_path
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def generator_cookbook_name
|
|
62
|
+
detect_generator_cookbook_name_and_path! unless @generator_cookbook_name
|
|
63
|
+
@generator_cookbook_name
|
|
54
64
|
end
|
|
55
65
|
|
|
56
66
|
# Sets git related generator_context values.
|
|
@@ -73,6 +83,38 @@ module ChefDK
|
|
|
73
83
|
paths = path.split(File::PATH_SEPARATOR)
|
|
74
84
|
paths.any? {|bin_path| File.exist?(File.join(bin_path, "git#{RbConfig::CONFIG['EXEEXT']}"))}
|
|
75
85
|
end
|
|
86
|
+
|
|
87
|
+
private
|
|
88
|
+
|
|
89
|
+
# Inspects the `config[:generator_cookbook]` option to determine the
|
|
90
|
+
# generator_cookbook_name and generator_cookbook_path. There are two
|
|
91
|
+
# supported ways this can work:
|
|
92
|
+
#
|
|
93
|
+
# * `config[:generator_cookbook]` is the full path to the generator
|
|
94
|
+
# cookbook. In this case, the last path component is the cookbook name,
|
|
95
|
+
# and the parent directory is the cookbook path
|
|
96
|
+
# * `config[:generator_cookbook]` is the path to a directory that
|
|
97
|
+
# contains a cookbook named "code_generator" (DEPRECATED). This is how
|
|
98
|
+
# the `--generator-cookbook` feature was originally written, so we
|
|
99
|
+
# support this for backwards compatibility. This way has poor UX and
|
|
100
|
+
# we'd like to get rid of it, so a warning is printed in this case.
|
|
101
|
+
def detect_generator_cookbook_name_and_path!
|
|
102
|
+
given_path = generator_cookbook_option
|
|
103
|
+
code_generator_subdir = File.join(given_path, "code_generator")
|
|
104
|
+
if File.directory?(code_generator_subdir)
|
|
105
|
+
@generator_cookbook_name = "code_generator"
|
|
106
|
+
@generator_cookbook_path = given_path
|
|
107
|
+
err("WARN: Please configure the generator cookbook by giving the full path to the desired cookbook (like '#{code_generator_subdir}')")
|
|
108
|
+
else
|
|
109
|
+
@generator_cookbook_name = File.basename(given_path)
|
|
110
|
+
@generator_cookbook_path = File.dirname(given_path)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def generator_cookbook_option
|
|
115
|
+
config[:generator_cookbook] || chefdk_config.generator_cookbook
|
|
116
|
+
end
|
|
117
|
+
|
|
76
118
|
end
|
|
77
119
|
end
|
|
78
120
|
end
|
|
@@ -52,6 +52,9 @@ module ChefDK
|
|
|
52
52
|
msg(banner)
|
|
53
53
|
1
|
|
54
54
|
end
|
|
55
|
+
rescue ChefDK::ChefRunnerError => e
|
|
56
|
+
err("ERROR: #{e}")
|
|
57
|
+
1
|
|
55
58
|
end
|
|
56
59
|
|
|
57
60
|
def setup_context
|
|
@@ -59,12 +62,17 @@ module ChefDK
|
|
|
59
62
|
Generator.add_attr_to_context(:skip_git_init, cookbook_path_in_git_repo?)
|
|
60
63
|
Generator.add_attr_to_context(:cookbook_root, cookbook_root)
|
|
61
64
|
Generator.add_attr_to_context(:cookbook_name, cookbook_name)
|
|
65
|
+
Generator.add_attr_to_context(:recipe_name, recipe_name)
|
|
62
66
|
end
|
|
63
67
|
|
|
64
68
|
def recipe
|
|
65
69
|
"cookbook"
|
|
66
70
|
end
|
|
67
71
|
|
|
72
|
+
def recipe_name
|
|
73
|
+
"default"
|
|
74
|
+
end
|
|
75
|
+
|
|
68
76
|
def cookbook_name
|
|
69
77
|
File.basename(cookbook_full_path)
|
|
70
78
|
end
|
|
@@ -58,6 +58,7 @@ module ChefDK
|
|
|
58
58
|
Generator.add_attr_to_context(:cookbook_root, cookbook_root)
|
|
59
59
|
Generator.add_attr_to_context(:cookbook_name, cookbook_name)
|
|
60
60
|
Generator.add_attr_to_context(:new_file_basename, new_file_basename)
|
|
61
|
+
Generator.add_attr_to_context(:recipe_name, new_file_basename)
|
|
61
62
|
end
|
|
62
63
|
|
|
63
64
|
def cookbook_root
|
data/lib/chef-dk/command/push.rb
CHANGED
|
@@ -18,12 +18,15 @@
|
|
|
18
18
|
require 'chef-dk/command/base'
|
|
19
19
|
require 'chef-dk/ui'
|
|
20
20
|
require 'chef-dk/policyfile_services/push'
|
|
21
|
+
require 'chef-dk/configurable'
|
|
21
22
|
|
|
22
23
|
module ChefDK
|
|
23
24
|
module Command
|
|
24
25
|
|
|
25
26
|
class Push < Base
|
|
26
27
|
|
|
28
|
+
include Configurable
|
|
29
|
+
|
|
27
30
|
banner(<<-E)
|
|
28
31
|
Usage: chef push POLICY_GROUP [ POLICY_FILE ] [options]
|
|
29
32
|
|
|
@@ -80,12 +83,6 @@ E
|
|
|
80
83
|
!!config[:debug]
|
|
81
84
|
end
|
|
82
85
|
|
|
83
|
-
def chef_config
|
|
84
|
-
return @chef_config if @chef_config
|
|
85
|
-
Chef::WorkstationConfigLoader.new(config[:config_file]).load
|
|
86
|
-
@chef_config = Chef::Config
|
|
87
|
-
end
|
|
88
|
-
|
|
89
86
|
def push
|
|
90
87
|
@push ||= PolicyfileServices::Push.new(policyfile: policyfile_relative_path,
|
|
91
88
|
ui: ui,
|
|
@@ -22,7 +22,7 @@ module ChefDK
|
|
|
22
22
|
module Command
|
|
23
23
|
class ShellInit < ChefDK::Command::Base
|
|
24
24
|
|
|
25
|
-
SUPPORTED_SHELLS = %w[ bash zsh sh ].map(&:freeze).freeze
|
|
25
|
+
SUPPORTED_SHELLS = %w[ bash zsh sh powershell posh].map(&:freeze).freeze
|
|
26
26
|
|
|
27
27
|
banner(<<-HELP)
|
|
28
28
|
Usage: chef shell-init
|
|
@@ -32,11 +32,17 @@ ruby.
|
|
|
32
32
|
|
|
33
33
|
To enable for just the current shell session:
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
In sh, bash, and zsh:
|
|
36
|
+
eval "$(chef shell-init SHELL_NAME)"
|
|
37
|
+
In Powershell:
|
|
38
|
+
chef shell-init powershell | Invoke-Expression
|
|
36
39
|
|
|
37
40
|
To permanently enable:
|
|
38
41
|
|
|
39
|
-
|
|
42
|
+
In sh, bash, and zsh:
|
|
43
|
+
echo 'eval "$(chef shell-init SHELL_NAME)"' >> ~/.YOUR_SHELL_RC_FILE
|
|
44
|
+
In Powershell
|
|
45
|
+
"chef shell-init powershell | Invoke-Expression" >> $PROFILE
|
|
40
46
|
|
|
41
47
|
OPTIONS:
|
|
42
48
|
|
|
@@ -67,12 +73,29 @@ HELP
|
|
|
67
73
|
|
|
68
74
|
env = omnibus_env.dup
|
|
69
75
|
path = env.delete("PATH")
|
|
70
|
-
|
|
76
|
+
export(shell_name, "PATH", path)
|
|
71
77
|
env.each do |var_name, value|
|
|
72
|
-
|
|
78
|
+
export(shell_name, var_name, value)
|
|
73
79
|
end
|
|
74
80
|
0
|
|
75
81
|
end
|
|
82
|
+
|
|
83
|
+
def export(shell, var, val)
|
|
84
|
+
case shell
|
|
85
|
+
when 'sh', 'bash', 'zsh'
|
|
86
|
+
posix_shell_export(var, val)
|
|
87
|
+
when 'powershell', 'posh'
|
|
88
|
+
powershell_export(var, val)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def posix_shell_export(var, val)
|
|
93
|
+
msg("export #{var}=\"#{val}\"")
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def powershell_export(var, val)
|
|
97
|
+
msg("$env:#{var}=\"#{val}\"")
|
|
98
|
+
end
|
|
76
99
|
end
|
|
77
100
|
end
|
|
78
101
|
end
|