bellboy 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/README.md +19 -0
- data/bellboy.gemspec +2 -3
- data/lib/bellboy.rb +11 -4
- data/lib/bellboy/installer.rb +14 -9
- data/lib/bellboy/mixin/berkshelf.rb +11 -3
- data/lib/bellboy/uploader.rb +2 -2
- data/lib/bellboy/versioner.rb +3 -3
- data/spec/cli_spec.rb +23 -11
- data/spec/installer_spec.rb +14 -5
- data/spec/spec-helpers.rb +30 -0
- data/spec/uploader_spec.rb +13 -5
- data/spec/versioner_spec.rb +13 -5
- metadata +5 -21
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -124,3 +124,22 @@ $PWD/config.json
|
|
124
124
|
You can also specify the path to the Berkshelf configuration file with the ```-c``` option:
|
125
125
|
|
126
126
|
bellboy install -c /path/to/berkshelf/config.json
|
127
|
+
|
128
|
+
### Databags API
|
129
|
+
|
130
|
+
Bellboy requires a working API server which it uses to download databag items. Normally Bellboy expects this API to run alongside your existing Berkshelf API, and Bellboy will use the existing `site` directive from the Berksfile to find the API.
|
131
|
+
|
132
|
+
For example, if your Berksfile contains
|
133
|
+
|
134
|
+
site "https://example.com"
|
135
|
+
|
136
|
+
then Bellboy assumes that the databag API is running at `https://example.com/databags`
|
137
|
+
|
138
|
+
It is also possible to run the databag API at a different location. You can specify the URL to the API with the Bellboy specific `databags` directive in your Berksfile. However, Berkshelf will not understand this directive, so using `databags` in your Berksfile is slightly more complicated
|
139
|
+
|
140
|
+
site "https://example.com"
|
141
|
+
databags "https://databags.example.com" if Object.constants.include? :Bellboy
|
142
|
+
|
143
|
+
The `if` clause ensures that Berkshelf will ignore the new directive, but that it will be processed if the Berksfile is loaded by Bellboy.
|
144
|
+
|
145
|
+
The databag API is a simple Sinatra application. See [the Githib page](https://github.com/dyninc/databagapi) for the source and documentation.
|
data/bellboy.gemspec
CHANGED
@@ -7,15 +7,14 @@ Gem::Specification.new do |g|
|
|
7
7
|
g.description = "Version, install & upload data bag items that are stored alongside your Berkshelf Cookbooks"
|
8
8
|
g.authors = ["Kristian Van Der Vliet"]
|
9
9
|
g.email = 'kvandervliet@dyn.com'
|
10
|
-
g.homepage = ''
|
10
|
+
g.homepage = 'https://github.com/Vanders/bellboy'
|
11
11
|
g.license = 'Apache-2.0'
|
12
12
|
|
13
13
|
g.files = `git ls-files`.split($\)
|
14
14
|
g.executables = g.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
15
|
|
16
16
|
g.add_runtime_dependency 'thor', '~> 0.18.0'
|
17
|
-
g.add_runtime_dependency 'berkshelf', '~> 2.0.10'
|
18
17
|
g.add_runtime_dependency 'faraday', '~> 0.8.0'
|
19
|
-
g.add_runtime_dependency 'ridley', '~>
|
18
|
+
g.add_runtime_dependency 'ridley', '~> 2.3'
|
20
19
|
g.add_runtime_dependency 'knife-data-bag-version', '~> 1.1.1'
|
21
20
|
end
|
data/lib/bellboy.rb
CHANGED
@@ -42,8 +42,15 @@ module Bellboy
|
|
42
42
|
attr_accessor :logger
|
43
43
|
|
44
44
|
def berks_sources(berksfile)
|
45
|
-
|
46
|
-
|
45
|
+
sources = Array.new
|
46
|
+
|
47
|
+
dependencies = berksfile.list
|
48
|
+
dependencies.each do |dependency|
|
49
|
+
Bellboy.logger.debug "Adding source for #{dependency.name}"
|
50
|
+
sources << berksfile.retrieve_locked(dependency)
|
51
|
+
end
|
52
|
+
|
53
|
+
sources
|
47
54
|
end
|
48
55
|
|
49
56
|
def ridley_connection(options = {})
|
@@ -74,9 +81,9 @@ module Bellboy
|
|
74
81
|
local_sources = Bellboy.berks_sources(berksfile)
|
75
82
|
|
76
83
|
local_sources.each do |source|
|
77
|
-
Bellboy.logger.debug "Source: #{source.
|
84
|
+
Bellboy.logger.debug "Source: #{source.path}"
|
78
85
|
|
79
|
-
path = File.join(source.
|
86
|
+
path = File.join(source.path, 'data_bags')
|
80
87
|
Dir.foreach(path) do |dir|
|
81
88
|
subdir = File.join(path, dir)
|
82
89
|
|
data/lib/bellboy/installer.rb
CHANGED
@@ -26,25 +26,30 @@ module Bellboy
|
|
26
26
|
def install(berksfile, options = {})
|
27
27
|
@bellboyfile = options[:bellboyfile]
|
28
28
|
|
29
|
+
# Make sure no one (E.g. rspec) did anything silly
|
30
|
+
abort if @bellboyfile.nil?
|
31
|
+
|
29
32
|
local_sources = Bellboy.berks_sources(berksfile)
|
30
33
|
|
31
34
|
local_sources.each do |source|
|
32
|
-
Bellboy.logger.debug "Source: #{source.
|
35
|
+
Bellboy.logger.debug "Source: #{source.path}"
|
33
36
|
|
34
|
-
if File.exists?(File.join(source.
|
35
|
-
site = berksfile.
|
37
|
+
if File.exists?(File.join(source.path, @bellboyfile))
|
38
|
+
site = berksfile.databags_source
|
36
39
|
|
37
40
|
if site.nil?
|
38
|
-
# Try the
|
39
|
-
site = berksfile.
|
41
|
+
# Try the first source
|
42
|
+
site = berksfile.sources.first
|
40
43
|
|
41
44
|
fail Berkshelf::InvalidChefAPILocation if site.nil?
|
42
45
|
|
43
|
-
location = "#{site
|
46
|
+
location = "#{site.uri}/databags"
|
44
47
|
else
|
45
|
-
location = site
|
48
|
+
location = site.uri
|
46
49
|
end
|
47
50
|
|
51
|
+
Bellboy.logger.debug "Using #{site} for databags API location"
|
52
|
+
|
48
53
|
download_databags(source, location)
|
49
54
|
end
|
50
55
|
|
@@ -54,9 +59,9 @@ module Bellboy
|
|
54
59
|
private
|
55
60
|
|
56
61
|
def download_databags(source, site)
|
57
|
-
Bellboy.logger.log "Downloading databags for #{source.
|
62
|
+
Bellboy.logger.log "Downloading databags for #{source.name}"
|
58
63
|
|
59
|
-
path = source.
|
64
|
+
path = source.path
|
60
65
|
containerpath = File.join(path, 'data_bags')
|
61
66
|
|
62
67
|
begin
|
@@ -4,6 +4,7 @@ module Bellboy
|
|
4
4
|
def self.included(base)
|
5
5
|
base.class_eval do
|
6
6
|
expose_method :databags
|
7
|
+
expose_method :databags_source
|
7
8
|
end
|
8
9
|
end
|
9
10
|
|
@@ -14,9 +15,16 @@ module Bellboy
|
|
14
15
|
#
|
15
16
|
# @param [String] value
|
16
17
|
#
|
17
|
-
# @return [
|
18
|
-
def databags(
|
19
|
-
|
18
|
+
# @return [Berkshelf::Source]
|
19
|
+
def databags(api_url)
|
20
|
+
@databags = Berkshelf::Source.new(api_url)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Get the 'Databags' location which will be used to resolve databag sources.
|
24
|
+
#
|
25
|
+
# @return [Berkshelf::Source]
|
26
|
+
def databags_source
|
27
|
+
@databags
|
20
28
|
end
|
21
29
|
|
22
30
|
end
|
data/lib/bellboy/uploader.rb
CHANGED
@@ -29,9 +29,9 @@ module Bellboy
|
|
29
29
|
conn = Bellboy.ridley_connection(options)
|
30
30
|
|
31
31
|
local_sources.each do |source|
|
32
|
-
Bellboy.logger.debug "Source: #{source.
|
32
|
+
Bellboy.logger.debug "Source: #{source.path}"
|
33
33
|
|
34
|
-
upload_databags(source
|
34
|
+
upload_databags(source, conn)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
data/lib/bellboy/versioner.rb
CHANGED
@@ -26,10 +26,10 @@ module Bellboy
|
|
26
26
|
local_sources = Bellboy.berks_sources(berksfile)
|
27
27
|
|
28
28
|
local_sources.each do |source|
|
29
|
-
Bellboy.logger.debug "Source: #{source.
|
29
|
+
Bellboy.logger.debug "Source: #{source.path}"
|
30
30
|
|
31
|
-
DatabagVersion.process_all(options[:verbose], "#{source.
|
32
|
-
Dir.exists?("#{source.
|
31
|
+
DatabagVersion.process_all(options[:verbose], "#{source.path}/data_bags") if
|
32
|
+
Dir.exists?("#{source.path}/data_bags")
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
data/spec/cli_spec.rb
CHANGED
@@ -5,6 +5,8 @@ require 'bellboy'
|
|
5
5
|
require_relative 'spec-helpers'
|
6
6
|
|
7
7
|
describe 'cli' do
|
8
|
+
include UsesTempFiles
|
9
|
+
|
8
10
|
it 'should output help information if run with no arguments' do
|
9
11
|
content = capture(:stdout) { Bellboy::Cli.start(%w[]) }
|
10
12
|
expect(content).to match(/Commands:/)
|
@@ -30,20 +32,30 @@ describe 'cli' do
|
|
30
32
|
expect(content).to match(/Upload all databags for all Cookbooks known by Berkshelf/)
|
31
33
|
end
|
32
34
|
|
33
|
-
it 'should
|
34
|
-
Bellboy::Cli.start(%w[version -b /
|
35
|
+
it 'should fail to run with an invalid Berksfile' do
|
36
|
+
content = capture(:stdout) { lambda{ Bellboy::Cli.start(%w[version -b /i/dont/exist]) }.should exit_with_code(0) }
|
37
|
+
expect(content).to match(/could not be found/)
|
35
38
|
end
|
36
39
|
|
37
|
-
|
38
|
-
Bellboy::Cli.start(%w[install -b /dev/null])
|
39
|
-
end
|
40
|
+
context "with non-empty Berksfile" do
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
42
|
+
in_directory_with_file('Berksfile')
|
43
|
+
|
44
|
+
before (:each) do
|
45
|
+
content_for_file("source 'http://example.com'")
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should not fail to run the \'version\' command' do
|
49
|
+
Bellboy::Cli.start(%w[version -b Berksfile])
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should not fail to run the \'install\' command' do
|
53
|
+
Bellboy::Cli.start(%w[install -b Berksfile])
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should not fail to run the \'upload\' command' do
|
57
|
+
Bellboy::Cli.start(%w[upload -b Berksfile])
|
58
|
+
end
|
44
59
|
|
45
|
-
it 'should fail to run with an invalid Berksfile' do
|
46
|
-
content = capture(:stdout) { lambda{ Bellboy::Cli.start(%w[version -b /i/dont/exist]) }.should exit_with_code(0) }
|
47
|
-
expect(content).to match(/could not be found/)
|
48
60
|
end
|
49
61
|
end
|
data/spec/installer_spec.rb
CHANGED
@@ -4,11 +4,20 @@ $LOAD_PATH.push File.expand_path('../../lib', __FILE__)
|
|
4
4
|
require 'bellboy'
|
5
5
|
|
6
6
|
describe 'installer' do
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
include UsesTempFiles
|
8
|
+
|
9
|
+
context "with non-empty Berksfile" do
|
10
|
+
|
11
|
+
in_directory_with_file('Berksfile')
|
12
|
+
|
13
|
+
before (:each) do
|
14
|
+
content_for_file("source 'http://example.com'")
|
15
|
+
@berksfile = Bellboy.berks_from_file('Berksfile')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should not throw any exceptions' do
|
19
|
+
Bellboy::Installer.install(@berksfile, {:bellboyfile => '/dev/null'})
|
20
|
+
end
|
10
21
|
|
11
|
-
it 'should not throw any exceptions' do
|
12
|
-
Bellboy::Installer.install(@berksfile)
|
13
22
|
end
|
14
23
|
end
|
data/spec/spec-helpers.rb
CHANGED
@@ -19,3 +19,33 @@ RSpec::Matchers.define :exit_with_code do |exp_code|
|
|
19
19
|
"expect block to call exit(#{exp_code})"
|
20
20
|
end
|
21
21
|
end
|
22
|
+
|
23
|
+
module UsesTempFiles
|
24
|
+
def self.included(example_group)
|
25
|
+
example_group.extend(self)
|
26
|
+
end
|
27
|
+
|
28
|
+
def in_directory_with_file(file)
|
29
|
+
before do
|
30
|
+
@pwd = Dir.pwd
|
31
|
+
@tmp_dir = File.join(File.dirname(__FILE__), 'tmp')
|
32
|
+
FileUtils.mkdir_p(@tmp_dir)
|
33
|
+
Dir.chdir(@tmp_dir)
|
34
|
+
|
35
|
+
FileUtils.mkdir_p(File.dirname(file))
|
36
|
+
FileUtils.touch(file)
|
37
|
+
end
|
38
|
+
|
39
|
+
define_method(:content_for_file) do |content|
|
40
|
+
f = File.new(File.join(@tmp_dir, file), 'a+')
|
41
|
+
f.write(content)
|
42
|
+
f.flush
|
43
|
+
f.close
|
44
|
+
end
|
45
|
+
|
46
|
+
after do
|
47
|
+
Dir.chdir(@pwd)
|
48
|
+
FileUtils.rm_rf(@tmp_dir)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/uploader_spec.rb
CHANGED
@@ -4,11 +4,19 @@ $LOAD_PATH.push File.expand_path('../../lib', __FILE__)
|
|
4
4
|
require 'bellboy'
|
5
5
|
|
6
6
|
describe 'uploader' do
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
include UsesTempFiles
|
8
|
+
|
9
|
+
context "with non-empty Berksfile" do
|
10
|
+
|
11
|
+
in_directory_with_file('Berksfile')
|
12
|
+
|
13
|
+
before (:each) do
|
14
|
+
content_for_file("source 'http://example.com'")
|
15
|
+
@berksfile = Bellboy.berks_from_file('Berksfile')
|
16
|
+
end
|
10
17
|
|
11
|
-
|
12
|
-
|
18
|
+
it 'should not throw any exceptions' do
|
19
|
+
Bellboy::Uploader.upload(@berksfile)
|
20
|
+
end
|
13
21
|
end
|
14
22
|
end
|
data/spec/versioner_spec.rb
CHANGED
@@ -4,11 +4,19 @@ $LOAD_PATH.push File.expand_path('../../lib', __FILE__)
|
|
4
4
|
require 'bellboy'
|
5
5
|
|
6
6
|
describe 'versioner' do
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
include UsesTempFiles
|
8
|
+
|
9
|
+
context "with non-empty Berksfile" do
|
10
|
+
|
11
|
+
in_directory_with_file('Berksfile')
|
12
|
+
|
13
|
+
before (:each) do
|
14
|
+
content_for_file("source 'http://example.com'")
|
15
|
+
@berksfile = Bellboy.berks_from_file('Berksfile')
|
16
|
+
end
|
10
17
|
|
11
|
-
|
12
|
-
|
18
|
+
it 'should not throw any exceptions' do
|
19
|
+
Bellboy::Versioner.version(@berksfile)
|
20
|
+
end
|
13
21
|
end
|
14
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bellboy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-03-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
@@ -27,22 +27,6 @@ dependencies:
|
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 0.18.0
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: berkshelf
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ~>
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: 2.0.10
|
38
|
-
type: :runtime
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 2.0.10
|
46
30
|
- !ruby/object:Gem::Dependency
|
47
31
|
name: faraday
|
48
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +50,7 @@ dependencies:
|
|
66
50
|
requirements:
|
67
51
|
- - ~>
|
68
52
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
53
|
+
version: '2.3'
|
70
54
|
type: :runtime
|
71
55
|
prerelease: false
|
72
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -74,7 +58,7 @@ dependencies:
|
|
74
58
|
requirements:
|
75
59
|
- - ~>
|
76
60
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
61
|
+
version: '2.3'
|
78
62
|
- !ruby/object:Gem::Dependency
|
79
63
|
name: knife-data-bag-version
|
80
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -121,7 +105,7 @@ files:
|
|
121
105
|
- spec/spec-helpers.rb
|
122
106
|
- spec/uploader_spec.rb
|
123
107
|
- spec/versioner_spec.rb
|
124
|
-
homepage:
|
108
|
+
homepage: https://github.com/Vanders/bellboy
|
125
109
|
licenses:
|
126
110
|
- Apache-2.0
|
127
111
|
post_install_message:
|