berkshelf 0.6.0.beta4 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/berkshelf.gemspec +1 -1
- data/features/config.feature +10 -10
- data/features/configure_command.feature +60 -0
- data/features/install.feature +6 -6
- data/features/step_definitions/cli_steps.rb +2 -2
- data/features/step_definitions/configure_cli_steps.rb +6 -0
- data/features/step_definitions/filesystem_steps.rb +6 -10
- data/features/support/env.rb +1 -0
- data/generator_files/Vagrantfile.erb +18 -38
- data/lib/berkshelf.rb +0 -19
- data/lib/berkshelf/cli.rb +82 -17
- data/lib/berkshelf/config.rb +77 -28
- data/lib/berkshelf/errors.rb +5 -2
- data/lib/berkshelf/locations/chef_api_location.rb +16 -11
- data/lib/berkshelf/vagrant/action/install.rb +4 -8
- data/lib/berkshelf/vagrant/action/upload.rb +5 -11
- data/lib/berkshelf/vagrant/config.rb +4 -28
- data/lib/berkshelf/version.rb +1 -1
- data/spec/unit/berkshelf/config_spec.rb +28 -68
- data/spec/unit/berkshelf/locations/chef_api_location_spec.rb +0 -6
- data/spec/unit/berkshelf_spec.rb +0 -20
- metadata +7 -10
- data/features/config_command.feature +0 -10
- data/generator_files/config.json +0 -22
- data/lib/berkshelf/config_generator.rb +0 -8
- data/lib/berkshelf/config_validator.rb +0 -78
- data/spec/unit/berkshelf/config_validator_spec.rb +0 -68
data/berkshelf.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.version = Berkshelf::VERSION
|
27
27
|
s.required_ruby_version = ">= 1.9.1"
|
28
28
|
|
29
|
-
s.add_runtime_dependency 'chozo', '>= 0.1
|
29
|
+
s.add_runtime_dependency 'chozo', '>= 0.2.1'
|
30
30
|
s.add_runtime_dependency 'ridley', '>= 0.0.5'
|
31
31
|
s.add_runtime_dependency 'solve', '>= 0.4.0.rc1'
|
32
32
|
s.add_runtime_dependency 'chef', '~> 10.12'
|
data/features/config.feature
CHANGED
@@ -7,7 +7,6 @@ Feature: cookbook creation with a config file
|
|
7
7
|
Given I do not have a Berkshelf config file
|
8
8
|
When I run the cookbook command to create "sparkle_motion"
|
9
9
|
Then the resulting "sparkle_motion" Vagrantfile should contain:
|
10
|
-
| config.vm.host_name = "sparkle_motion-berkshelf" |
|
11
10
|
| config.vm.box = "Berkshelf-CentOS-6.3-x86_64-minimal" |
|
12
11
|
| config.vm.box_url = "https://dl.dropbox.com/u/31081437/Berkshelf-CentOS-6.3-x86_64-minimal.box" |
|
13
12
|
And the exit status should be 0
|
@@ -23,7 +22,6 @@ Feature: cookbook creation with a config file
|
|
23
22
|
"forward_port": {
|
24
23
|
"12345": "54321"
|
25
24
|
},
|
26
|
-
"host_name": "my_host",
|
27
25
|
"network": {
|
28
26
|
"bridged": true,
|
29
27
|
"hostonly": "12.34.56.78"
|
@@ -37,7 +35,6 @@ Feature: cookbook creation with a config file
|
|
37
35
|
| config.vm.box = "my_box" |
|
38
36
|
| config.vm.box_url = "http://files.vagrantup.com/lucid64.box" |
|
39
37
|
| config.vm.forward_port 12345, 54321 |
|
40
|
-
| config.vm.host_name = "my_host" |
|
41
38
|
| config.vm.network :hostonly, "12.34.56.78" |
|
42
39
|
| config.vm.network :bridged |
|
43
40
|
And the exit status should be 0
|
@@ -64,24 +61,27 @@ Feature: cookbook creation with a config file
|
|
64
61
|
Given I have a Berkshelf config file containing:
|
65
62
|
"""
|
66
63
|
{
|
67
|
-
"
|
64
|
+
"vagrant": null
|
68
65
|
}
|
69
66
|
"""
|
70
67
|
When I run the cookbook command to create "sparkle_motion"
|
71
68
|
Then the output should contain "Invalid configuration"
|
72
|
-
And the output should contain "
|
69
|
+
And the output should contain "vagrant.vm.box Expected attribute: 'vagrant.vm.box' to be a type of: 'String'"
|
70
|
+
And the output should contain "vagrant.vm.box A value is required for attribute: 'vagrant.vm.box'"
|
71
|
+
And the output should contain "vagrant.vm.box_url Expected attribute: 'vagrant.vm.box_url' to be a type of: 'String'"
|
72
|
+
And the output should contain "vagrant.vm.box_url A value is required for attribute: 'vagrant.vm.box_url'"
|
73
73
|
And the CLI should exit with the status code for error "InvalidConfiguration"
|
74
74
|
|
75
75
|
Scenario: creating a new cookbook with a chef client config
|
76
76
|
Given I have a Berkshelf config file containing:
|
77
77
|
"""
|
78
78
|
{
|
79
|
+
"chef": {
|
80
|
+
"chef_server_url": "localhost:4000",
|
81
|
+
"validation_client_name": "my_client-validator",
|
82
|
+
"validation_key_path": "/a/b/c/my_client-validator.pem"
|
83
|
+
},
|
79
84
|
"vagrant": {
|
80
|
-
"chef": {
|
81
|
-
"chef_server_url": "localhost:4000",
|
82
|
-
"validation_client_name": "my_client-validator",
|
83
|
-
"validation_key_path": "/a/b/c/my_client-validator.pem"
|
84
|
-
},
|
85
85
|
"vm": {
|
86
86
|
"provision": "chef_client"
|
87
87
|
}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
Feature: configure command
|
2
|
+
As CLI user of Berkshelf
|
3
|
+
I want a command to generate a Berkshelf configuration file based on my input
|
4
|
+
So I can quickly get up and running with the least amount of resistance
|
5
|
+
|
6
|
+
Scenario: generating a new config file
|
7
|
+
Given I do not have a Berkshelf config file
|
8
|
+
When I run the "configure" command interactively
|
9
|
+
And I type "https://api.opscode.com/organizations/vialstudios"
|
10
|
+
And I type "node_name"
|
11
|
+
And I type "client_key"
|
12
|
+
And I type "reset"
|
13
|
+
And I type "/Users/reset/.chef/reset.pem"
|
14
|
+
And I type "Berkshelf-minimal"
|
15
|
+
And I type "https://dl.dropbox.com/Berkshelf.box"
|
16
|
+
Then the output should contain:
|
17
|
+
"""
|
18
|
+
Config written to:
|
19
|
+
"""
|
20
|
+
And the exit status should be 0
|
21
|
+
And a Berkshelf config file should exist and contain:
|
22
|
+
| chef.chef_server_url | https://api.opscode.com/organizations/vialstudios |
|
23
|
+
| chef.validation_client_name | reset |
|
24
|
+
| chef.node_name | node_name |
|
25
|
+
| chef.client_key | client_key |
|
26
|
+
| chef.validation_key_path | /Users/reset/.chef/reset.pem |
|
27
|
+
| vagrant.vm.box | Berkshelf-minimal |
|
28
|
+
| vagrant.vm.box_url | https://dl.dropbox.com/Berkshelf.box |
|
29
|
+
|
30
|
+
Scenario: generating a config with default values
|
31
|
+
Given I do not have a Berkshelf config file
|
32
|
+
When I run the "configure" command interactively
|
33
|
+
And I type ""
|
34
|
+
And I type ""
|
35
|
+
And I type ""
|
36
|
+
And I type ""
|
37
|
+
And I type ""
|
38
|
+
And I type ""
|
39
|
+
And I type ""
|
40
|
+
Then the output should contain:
|
41
|
+
"""
|
42
|
+
Config written to:
|
43
|
+
"""
|
44
|
+
And the exit status should be 0
|
45
|
+
And a Berkshelf config file should exist and contain:
|
46
|
+
| chef.chef_server_url | http://localhost:4000 |
|
47
|
+
| chef.validation_client_name | chef-validator |
|
48
|
+
| chef.client_key | /etc/chef/client.pem |
|
49
|
+
| chef.validation_key_path | /etc/chef/validation.pem |
|
50
|
+
| vagrant.vm.box | Berkshelf-CentOS-6.3-x86_64-minimal |
|
51
|
+
| vagrant.vm.box_url | https://dl.dropbox.com/u/31081437/Berkshelf-CentOS-6.3-x86_64-minimal.box |
|
52
|
+
|
53
|
+
Scenario: attempting to generate a new config when one already exists
|
54
|
+
Given I have a default Berkshelf config file
|
55
|
+
When I run the "configure" command interactively
|
56
|
+
Then the output should contain:
|
57
|
+
"""
|
58
|
+
A configuration file already exists. Re-run with the --force flag if you wish to overwrite it.
|
59
|
+
"""
|
60
|
+
And the CLI should exit with the status code for error "ConfigExists"
|
data/features/install.feature
CHANGED
@@ -198,7 +198,7 @@ Feature: install cookbooks from a Berksfile
|
|
198
198
|
Scenario: with a cookbook definition containing a chef_api source location
|
199
199
|
Given I write to "Berksfile" with:
|
200
200
|
"""
|
201
|
-
cookbook "artifact", "= 0.10.2", chef_api: :
|
201
|
+
cookbook "artifact", "= 0.10.2", chef_api: :config
|
202
202
|
"""
|
203
203
|
And the Chef server has cookbooks:
|
204
204
|
| artifact | 0.10.2 |
|
@@ -211,18 +211,18 @@ Feature: install cookbooks from a Berksfile
|
|
211
211
|
| artifact | 0.10.2 |
|
212
212
|
And the exit status should be 0
|
213
213
|
|
214
|
-
Scenario: with a chef_api source location specifying :
|
214
|
+
Scenario: with a chef_api source location specifying :config when a Berkshelf config is not found at the given path
|
215
215
|
Given I write to "Berksfile" with:
|
216
216
|
"""
|
217
|
-
cookbook "artifact", chef_api: :
|
217
|
+
cookbook "artifact", chef_api: :config
|
218
218
|
"""
|
219
219
|
When I run the install command with flags:
|
220
|
-
| -c /tmp/
|
220
|
+
| -c /tmp/notthere.lol |
|
221
221
|
Then the output should contain:
|
222
222
|
"""
|
223
|
-
|
223
|
+
You specified a path to a configuration file that did not exist: '/tmp/notthere.lol'
|
224
224
|
"""
|
225
|
-
And the CLI should exit with the status code for error "
|
225
|
+
And the CLI should exit with the status code for error "BerksConfigNotFound"
|
226
226
|
|
227
227
|
Scenario: with a chef_api source location specifying a Chef API URL but missing a node_name option
|
228
228
|
Given I write to "Berksfile" with:
|
@@ -66,8 +66,8 @@ When /^I run the cookbook command to create "(.*?)" with options:$/ do |name, op
|
|
66
66
|
run_simple(unescape("berks cookbook #{name} #{options.raw.join(" ")}"))
|
67
67
|
end
|
68
68
|
|
69
|
-
When /^I run the
|
70
|
-
|
69
|
+
When /^I run the "(.*?)" command interactively$/ do |command|
|
70
|
+
run_interactive("berks #{command}")
|
71
71
|
end
|
72
72
|
|
73
73
|
Then /^the CLI should exit with the status code for error "(.*?)"$/ do |error_constant|
|
@@ -18,14 +18,16 @@ Given /^I do not have a Berksfile\.lock$/ do
|
|
18
18
|
in_current_dir { FileUtils.rm_f(Berkshelf::Lockfile::DEFAULT_FILENAME) }
|
19
19
|
end
|
20
20
|
|
21
|
+
Given /^I have a default Berkshelf config file$/ do
|
22
|
+
Berkshelf::Config.new.save
|
23
|
+
end
|
24
|
+
|
21
25
|
Given /^I have a Berkshelf config file containing:$/ do |contents|
|
22
|
-
|
26
|
+
Berkshelf::Config.new.from_json(contents).save
|
23
27
|
end
|
24
28
|
|
25
29
|
Given /^I do not have a Berkshelf config file$/ do
|
26
|
-
|
27
|
-
|
28
|
-
remove_file file if File.exists? file
|
30
|
+
remove_file Berkshelf::Config.path if File.exists? Berkshelf::Config.path
|
29
31
|
end
|
30
32
|
|
31
33
|
Given /^the cookbook "(.*?)" has the file "(.*?)" with:$/ do |cookbook_name, file_name, content|
|
@@ -234,9 +236,3 @@ end
|
|
234
236
|
Then /^the current directory should not have the following files:$/ do |files|
|
235
237
|
check_file_presence(files.raw.map{|file_row| file_row[0]}, false)
|
236
238
|
end
|
237
|
-
|
238
|
-
Then /^I should have a Berkshelf config file$/ do
|
239
|
-
Pathname.new(ENV['HOME']).join(".berkshelf").should have_structure {
|
240
|
-
file "config.json"
|
241
|
-
}
|
242
|
-
end
|
data/features/support/env.rb
CHANGED
@@ -12,6 +12,7 @@ Spork.prefork do
|
|
12
12
|
APP_ROOT = File.expand_path('../../../', __FILE__)
|
13
13
|
|
14
14
|
ENV["BERKSHELF_PATH"] = File.join(APP_ROOT, "tmp", "berkshelf")
|
15
|
+
ENV["BERKSHELF_CHEF_CONFIG"] = File.join(APP_ROOT, "tmp", "knife.rb")
|
15
16
|
|
16
17
|
Dir[File.join(APP_ROOT, "spec/support/**/*.rb")].each {|f| require f}
|
17
18
|
|
@@ -8,17 +8,6 @@ Vagrant::Config.run do |config|
|
|
8
8
|
# The path to the Berksfile to use with Vagrant Berkshelf
|
9
9
|
# config.berkshelf.berksfile_path = "./Berksfile"
|
10
10
|
|
11
|
-
# The path to the Knife config to use with Vagrant Berkshelf
|
12
|
-
# config.berkshelf.config_path = "~/.chef/knife.rb"
|
13
|
-
|
14
|
-
# A client name (node_name) to use with the Chef Client provisioner to upload
|
15
|
-
# cookbooks installed by Berkshelf.
|
16
|
-
# config.berkshelf.node_name = "reset"
|
17
|
-
|
18
|
-
# A path to a client key on disk to use with the Chef Client provisioner to
|
19
|
-
# upload cookbooks installed by Berkshelf.
|
20
|
-
# config.berkshelf.client_key = "~/.chef/reset.pem"
|
21
|
-
|
22
11
|
# An array of symbols representing groups of cookbook described in the Vagrantfile
|
23
12
|
# to skip installing and copying to Vagrant's shelf.
|
24
13
|
# config.berkshelf.only = []
|
@@ -27,24 +16,10 @@ Vagrant::Config.run do |config|
|
|
27
16
|
# to skip installing and copying to Vagrant's shelf.
|
28
17
|
# config.berkshelf.except = []
|
29
18
|
|
30
|
-
<% if options[:berkshelf_config][:vagrant][:vm][:box].present? -%>
|
31
|
-
config.vm.host_name = "<%= options[:berkshelf_config][:vagrant][:vm][:host_name] %>"
|
32
|
-
<% else -%>
|
33
19
|
config.vm.host_name = "<%= "#{cookbook_name}-berkshelf" %>"
|
34
|
-
<% end -%>
|
35
20
|
|
36
|
-
|
37
|
-
|
38
|
-
<% if options[:berkshelf_config][:vagrant][:vm][:box].present? -%>
|
39
|
-
config.vm.box = "<%= options[:berkshelf_config][:vagrant][:vm][:box] %>"
|
40
|
-
<% else %>
|
41
|
-
config.vm.box = "Berkshelf-CentOS-6.3-x86_64-minimal"
|
42
|
-
<% end -%>
|
43
|
-
<% if options[:berkshelf_config][:vagrant][:vm][:box_url].present? -%>
|
44
|
-
config.vm.box_url = "<%= options[:berkshelf_config][:vagrant][:vm][:box_url] %>"
|
45
|
-
<% else %>
|
46
|
-
config.vm.box_url = "https://dl.dropbox.com/u/31081437/Berkshelf-CentOS-6.3-x86_64-minimal.box"
|
47
|
-
<% end -%>
|
21
|
+
config.vm.box = "<%= options[:berkshelf_config].vagrant.vm.box %>"
|
22
|
+
config.vm.box_url = "<%= options[:berkshelf_config].vagrant.vm.box_url %>"
|
48
23
|
|
49
24
|
# Boot with a GUI so you can see the screen. (Default is headless)
|
50
25
|
# config.vm.boot_mode = :gui
|
@@ -53,22 +28,27 @@ Vagrant::Config.run do |config|
|
|
53
28
|
# via the IP. Host-only networks can talk to the host machine as well as
|
54
29
|
# any other machines on the same network, but cannot be accessed (through this
|
55
30
|
# network interface) by any external networks.
|
31
|
+
<% if options[:berkshelf_config].vagrant.vm.network.hostonly.present? -%>
|
32
|
+
config.vm.network :hostonly, "<%= options[:berkshelf_config].vagrant.vm.network.hostonly %>"
|
33
|
+
<% else %>
|
56
34
|
# config.vm.network :hostonly, "33.33.33.10"
|
57
|
-
<% if options[:berkshelf_config][:vagrant][:vm][:network][:hostonly].present? -%>
|
58
|
-
config.vm.network :hostonly, "<%= options[:berkshelf_config][:vagrant][:vm][:network][:hostonly] %>"
|
59
35
|
<% end -%>
|
60
36
|
|
61
37
|
# Assign this VM to a bridged network, allowing you to connect directly to a
|
62
38
|
# network using the host's network device. This makes the VM appear as another
|
63
39
|
# physical device on your network.
|
64
|
-
|
40
|
+
<% if options[:berkshelf_config].vagrant.vm.network.bridged -%>
|
41
|
+
config.vm.network :bridged
|
42
|
+
<% else %>
|
43
|
+
# config.vm.network :bridged
|
44
|
+
<% end -%>
|
65
45
|
|
66
46
|
# Forward a port from the guest to the host, which allows for outside
|
67
47
|
# computers to access the VM, whereas host only networking does not.
|
68
48
|
# config.vm.forward_port 80, 8080
|
69
|
-
<% options[:berkshelf_config]
|
49
|
+
<% options[:berkshelf_config].vagrant.vm.forward_port.each do |guest, host| %>
|
70
50
|
config.vm.forward_port <%= guest %>, <%= host %>
|
71
|
-
<% end
|
51
|
+
<% end -%>
|
72
52
|
|
73
53
|
# Share an additional folder to the guest VM. The first argument is
|
74
54
|
# an identifier, the second is the path on the guest to mount the
|
@@ -78,18 +58,18 @@ Vagrant::Config.run do |config|
|
|
78
58
|
config.ssh.max_tries = 40
|
79
59
|
config.ssh.timeout = 120
|
80
60
|
|
81
|
-
<% if options[:berkshelf_config]
|
61
|
+
<% if options[:berkshelf_config].vagrant.vm.provision == "chef_client" -%>
|
82
62
|
config.vm.provision :chef_client do |chef|
|
83
|
-
chef.chef_server_url = "<%= options[:berkshelf_config]
|
84
|
-
chef.validation_client_name = "<%= options[:berkshelf_config]
|
85
|
-
chef.validation_key_path = "<%= options[:berkshelf_config]
|
63
|
+
chef.chef_server_url = "<%= options[:berkshelf_config].chef.chef_server_url %>"
|
64
|
+
chef.validation_client_name = "<%= options[:berkshelf_config].chef.validation_client_name %>"
|
65
|
+
chef.validation_key_path = "<%= options[:berkshelf_config].chef.validation_key_path %>"
|
86
66
|
|
87
67
|
chef.run_list = [
|
88
68
|
"recipe[<%= cookbook_name %>::default]"
|
89
69
|
]
|
90
70
|
end
|
91
|
-
<%
|
92
|
-
config.vm.provision :chef_solo do |chef|
|
71
|
+
<% elsif options[:berkshelf_config].vagrant.vm.provision == "chef_solo" -%>
|
72
|
+
config.vm.provision :chef_solo do |chef|
|
93
73
|
chef.json = {
|
94
74
|
:mysql => {
|
95
75
|
:server_root_password => 'rootpass',
|
data/lib/berkshelf.rb
CHANGED
@@ -25,7 +25,6 @@ require 'thor/monkies'
|
|
25
25
|
Chef::Config[:cache_options][:path] = Dir.mktmpdir
|
26
26
|
|
27
27
|
module Berkshelf
|
28
|
-
DEFAULT_CONFIG = File.expand_path(ENV["CHEF_CONFIG"] || "~/.chef/knife.rb")
|
29
28
|
DEFAULT_STORE_PATH = File.expand_path("~/.berkshelf").freeze
|
30
29
|
DEFAULT_FILENAME = 'Berksfile'.freeze
|
31
30
|
|
@@ -44,15 +43,12 @@ module Berkshelf
|
|
44
43
|
autoload :Uploader, 'berkshelf/uploader'
|
45
44
|
autoload :Resolver, 'berkshelf/resolver'
|
46
45
|
autoload :Config, 'berkshelf/config'
|
47
|
-
autoload :ConfigGenerator, 'berkshelf/config_generator'
|
48
|
-
autoload :ConfigValidator, 'berkshelf/config_validator'
|
49
46
|
|
50
47
|
require 'berkshelf/location'
|
51
48
|
|
52
49
|
class << self
|
53
50
|
attr_accessor :ui
|
54
51
|
|
55
|
-
attr_writer :config_path
|
56
52
|
attr_writer :cookbook_store
|
57
53
|
|
58
54
|
# @return [Pathname]
|
@@ -99,21 +95,6 @@ module Berkshelf
|
|
99
95
|
@cookbook_store ||= CookbookStore.new(cookbooks_dir)
|
100
96
|
end
|
101
97
|
|
102
|
-
# @return [String]
|
103
|
-
def config_path
|
104
|
-
@config_path ||= DEFAULT_CONFIG
|
105
|
-
end
|
106
|
-
|
107
|
-
# Load the config found at the given path as the Chef::Config. If no path is specified
|
108
|
-
# the value of Berkshelf.chef_config will be used.
|
109
|
-
#
|
110
|
-
# @param [String] path
|
111
|
-
def load_config(path = config_path)
|
112
|
-
Chef::Config.from_file(File.expand_path(path))
|
113
|
-
rescue Errno::ENOENT
|
114
|
-
raise KnifeConfigNotFound, "Attempted to load configuration from: '#{path}' but not found."
|
115
|
-
end
|
116
|
-
|
117
98
|
# Ascend the directory structure from the given path to find a
|
118
99
|
# metadata.rb file of a Chef Cookbook. If no metadata.rb file
|
119
100
|
# was found, nil is returned.
|
data/lib/berkshelf/cli.rb
CHANGED
@@ -14,7 +14,14 @@ module Berkshelf
|
|
14
14
|
|
15
15
|
def initialize(*args)
|
16
16
|
super(*args)
|
17
|
-
|
17
|
+
|
18
|
+
if @options[:config]
|
19
|
+
unless File.exist?(@options[:config])
|
20
|
+
raise BerksConfigNotFound, "You specified a path to a configuration file that did not exist: '#{@options[:config]}'"
|
21
|
+
end
|
22
|
+
Berkshelf::Config.path = @options[:config]
|
23
|
+
end
|
24
|
+
|
18
25
|
Berkshelf.set_format @options[:format]
|
19
26
|
@options = options.dup # unfreeze frozen options Hash from Thor
|
20
27
|
end
|
@@ -27,15 +34,9 @@ module Berkshelf
|
|
27
34
|
map 'ver' => :version
|
28
35
|
map 'book' => :cookbook
|
29
36
|
|
30
|
-
desc "config", "Generate a default Berkshelf configuration file"
|
31
|
-
def config
|
32
|
-
ConfigGenerator.new.invoke_all
|
33
|
-
end
|
34
|
-
|
35
37
|
class_option :config,
|
36
38
|
type: :string,
|
37
|
-
|
38
|
-
desc: "Path to Knife or Chef configuration to use.",
|
39
|
+
desc: "Path to Berkshelf configuration to use.",
|
39
40
|
aliases: "-c",
|
40
41
|
banner: "PATH"
|
41
42
|
class_option :format,
|
@@ -45,6 +46,51 @@ module Berkshelf
|
|
45
46
|
aliases: "-F",
|
46
47
|
banner: "FORMAT"
|
47
48
|
|
49
|
+
method_option :force,
|
50
|
+
type: :boolean,
|
51
|
+
default: false,
|
52
|
+
desc: "create a new configuration file even if one already exists."
|
53
|
+
desc "configure", "Create a new configuration file to customize Berkshelf's behavior"
|
54
|
+
def configure(path = Berkshelf::Config.path)
|
55
|
+
path = File.expand_path(path)
|
56
|
+
|
57
|
+
if File.exist?(path) && !options[:force]
|
58
|
+
raise Berkshelf::ConfigExists, "A configuration file already exists. Re-run with the --force flag if you wish to overwrite it."
|
59
|
+
end
|
60
|
+
|
61
|
+
@config = Berkshelf::Config.new(path)
|
62
|
+
|
63
|
+
[
|
64
|
+
"chef.chef_server_url",
|
65
|
+
"chef.node_name",
|
66
|
+
"chef.client_key",
|
67
|
+
"chef.validation_client_name",
|
68
|
+
"chef.validation_key_path",
|
69
|
+
"vagrant.vm.box",
|
70
|
+
"vagrant.vm.box_url",
|
71
|
+
].each do |attribute|
|
72
|
+
default = @config.get_attribute(attribute)
|
73
|
+
|
74
|
+
message = "Enter value for #{attribute}"
|
75
|
+
message << " (default: '#{default}')" if default
|
76
|
+
message << ": "
|
77
|
+
|
78
|
+
input = Berkshelf.ui.ask(message)
|
79
|
+
|
80
|
+
if input.present?
|
81
|
+
@config.set_attribute(attribute, input)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
unless @config.valid?
|
86
|
+
raise InvalidConfiguration.new(@config.errors)
|
87
|
+
end
|
88
|
+
|
89
|
+
@config.save
|
90
|
+
|
91
|
+
Berkshelf.formatter.msg "Config written to: '#{path}'"
|
92
|
+
end
|
93
|
+
|
48
94
|
method_option :except,
|
49
95
|
type: :array,
|
50
96
|
desc: "Exclude cookbooks that are in these groups.",
|
@@ -64,7 +110,7 @@ module Berkshelf
|
|
64
110
|
desc: "Path to install cookbooks to (i.e. vendor/cookbooks).",
|
65
111
|
aliases: "-p",
|
66
112
|
banner: "PATH"
|
67
|
-
desc "install", "Install the Cookbooks specified by a Berksfile or a Berksfile.lock
|
113
|
+
desc "install", "Install the Cookbooks specified by a Berksfile or a Berksfile.lock"
|
68
114
|
def install
|
69
115
|
berksfile = ::Berkshelf::Berksfile.from_file(options[:berksfile])
|
70
116
|
berksfile.install(options)
|
@@ -84,7 +130,7 @@ module Berkshelf
|
|
84
130
|
type: :array,
|
85
131
|
desc: "Only cookbooks that are in these groups.",
|
86
132
|
aliases: "-o"
|
87
|
-
desc "update", "Update all Cookbooks and their dependencies specified by a Berksfile to their latest versions
|
133
|
+
desc "update", "Update all Cookbooks and their dependencies specified by a Berksfile to their latest versions"
|
88
134
|
def update
|
89
135
|
Lockfile.remove!
|
90
136
|
invoke :install
|
@@ -116,19 +162,34 @@ module Berkshelf
|
|
116
162
|
type: :boolean,
|
117
163
|
default: true,
|
118
164
|
desc: "Disable/Enable SSL verification when uploading cookbooks"
|
119
|
-
desc "upload", "Upload the Cookbooks specified by a Berksfile or a Berksfile.lock to a Chef Server
|
165
|
+
desc "upload", "Upload the Cookbooks specified by a Berksfile or a Berksfile.lock to a Chef Server"
|
120
166
|
def upload
|
121
|
-
Berkshelf.load_config
|
122
167
|
berksfile = ::Berkshelf::Berksfile.from_file(options[:berksfile])
|
123
168
|
|
169
|
+
unless Berkshelf::Config.instance.chef.chef_server_url.present?
|
170
|
+
msg = "Could not upload cookbooks: Missing Chef server_url."
|
171
|
+
msg << " Generate or update your Berkshelf configuration that contains a valid Chef Server URL."
|
172
|
+
raise UploadFailure, msg
|
173
|
+
end
|
174
|
+
|
175
|
+
unless Berkshelf::Config.instance.chef.node_name.present?
|
176
|
+
msg = "Could not upload cookbooks: Missing Chef node_name."
|
177
|
+
msg << " Generate or update your Berkshelf configuration that contains a valid Chef node_name."
|
178
|
+
raise UploadFailure, msg
|
179
|
+
end
|
180
|
+
|
124
181
|
berksfile.upload(
|
125
|
-
server_url:
|
126
|
-
client_name:
|
127
|
-
client_key:
|
182
|
+
server_url: Berkshelf::Config.instance.chef.chef_server_url,
|
183
|
+
client_name: Berkshelf::Config.instance.chef.node_name,
|
184
|
+
client_key: Berkshelf::Config.instance.chef.client_key,
|
128
185
|
ssl: {
|
129
|
-
verify: options[:ssl_verify]
|
186
|
+
verify: (options[:ssl_verify] || Berkshelf::Config.instance.ssl.verify)
|
130
187
|
}
|
131
188
|
)
|
189
|
+
rescue Ridley::Errors::ClientKeyFileNotFound => e
|
190
|
+
msg = "Could not upload cookbooks: Missing Chef client key: '#{Berkshelf::Config.instance.chef.client_key}'."
|
191
|
+
msg << " Generate or update your Berkshelf configuration that contains a valid path to a Chef client key."
|
192
|
+
raise UploadFailure, msg
|
132
193
|
end
|
133
194
|
|
134
195
|
method_option :foodcritic,
|
@@ -152,7 +213,7 @@ module Berkshelf
|
|
152
213
|
method_option :skip_git,
|
153
214
|
type: :boolean,
|
154
215
|
desc: "Skips adding a .gitignore and running git init in the cookbook directory"
|
155
|
-
desc "init [PATH]", "Prepare a local path to have its Cookbook dependencies managed by Berkshelf
|
216
|
+
desc "init [PATH]", "Prepare a local path to have its Cookbook dependencies managed by Berkshelf"
|
156
217
|
def init(path = Dir.pwd)
|
157
218
|
Berkshelf.formatter.deprecation "--git is now the default" if options[:git]
|
158
219
|
Berkshelf.formatter.deprecation "--vagrant is now the default" if options[:vagrant]
|
@@ -213,6 +274,10 @@ module Berkshelf
|
|
213
274
|
Berkshelf.formatter.deprecation "--git is now the default" if options[:git]
|
214
275
|
Berkshelf.formatter.deprecation "--vagrant is now the default" if options[:vagrant]
|
215
276
|
|
277
|
+
unless Config.instance.valid?
|
278
|
+
raise InvalidConfiguration.new(Config.instance.errors)
|
279
|
+
end
|
280
|
+
|
216
281
|
::Berkshelf::CookbookGenerator.new([name, File.join(Dir.pwd, name)], options).invoke_all
|
217
282
|
end
|
218
283
|
|