builderator 0.3.10 → 0.3.11
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/VERSION +1 -1
- data/builderator.gemspec +1 -0
- data/lib/builderator/tasks/cookbook.rb +73 -6
- data/lib/builderator/util.rb +3 -1
- data/lib/builderator/util/cookbook.rb +54 -9
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f78cc9361223078843608c192a703626a438855
|
4
|
+
data.tar.gz: c1404434a5bffd2b5a4ed75e1162023cd978f04e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e337ea2b012c56e13778e3ad866636c84029a5df410bd38ff1ffc55b9ef2d5732d584277b37010ee70b9de053e2805ab476836707f548e410529f471e93a27b
|
7
|
+
data.tar.gz: a4d1dd644c7a958fbc2d08d55d226441874d51b0844ccea47c3613e5120e618da5d87904145208bc901899e6ad23e38cc5fbf089c069955bd3d86d57e85cffe5
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.11
|
data/builderator.gemspec
CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_dependency 'bundler', '~> 1.7.0'
|
25
25
|
spec.add_dependency 'berkshelf', '~> 3.2'
|
26
26
|
spec.add_dependency 'chef', '~> 12.0'
|
27
|
+
spec.add_dependency 'ignorefile'
|
27
28
|
spec.add_dependency 'thor', '~> 0.19.0'
|
28
29
|
spec.add_dependency 'thor-scmversion', '1.7.0'
|
29
30
|
end
|
@@ -1,5 +1,12 @@
|
|
1
|
+
require 'chef'
|
2
|
+
require 'chef/cookbook_site_streaming_uploader'
|
3
|
+
require 'rubygems/package'
|
1
4
|
require 'thor'
|
2
5
|
require 'thor/actions'
|
6
|
+
require 'thor-scmversion'
|
7
|
+
require 'zlib'
|
8
|
+
|
9
|
+
require_relative '../util'
|
3
10
|
require_relative '../util/cookbook'
|
4
11
|
|
5
12
|
module Builderator
|
@@ -13,22 +20,82 @@ module Builderator
|
|
13
20
|
desc 'metadata [PATH]', 'Use cookbook matadata file at PATH/metadata.rb to generate PATH/matadata.json'
|
14
21
|
def metadata(cookbook = nil)
|
15
22
|
Util::Cookbook.path(cookbook) unless cookbook.nil?
|
23
|
+
metadata = Util::Cookbook.metadata
|
24
|
+
|
16
25
|
invoke 'version:current', [], options if options['version']
|
26
|
+
say_status :metadata, "for cookbook #{ metadata.name }@#{ metadata.version }"
|
27
|
+
create_file Util::Cookbook.path.join('metadata.json').to_s, metadata.to_json, :force => true
|
17
28
|
|
18
|
-
|
19
|
-
Util::Cookbook.metadata.to_json, :force => true
|
29
|
+
metadata
|
20
30
|
end
|
21
31
|
|
22
|
-
desc '
|
23
|
-
def
|
32
|
+
desc 'build PATH', 'Package cookbook at PATH into a tarball'
|
33
|
+
def build(cookbook = nil)
|
24
34
|
Util::Cookbook.path(cookbook) unless cookbook.nil?
|
25
35
|
|
36
|
+
## Generate metadata.json
|
37
|
+
metadata = invoke(Tasks::Cookbook, :metadata, [], options)
|
38
|
+
|
39
|
+
## Create a gzipped tarball and add cookbook files to it. We avoid
|
40
|
+
## buffering this in memory (e.g. using StringIO) at all cost
|
41
|
+
## to keep large files from gumming things up.
|
42
|
+
say_status :package, "cookbook into #{ metadata.archive }"
|
43
|
+
metadata.archive.open('wb') do |package|
|
44
|
+
Zlib::GzipWriter.wrap(package) do |gz|
|
45
|
+
Gem::Package::TarWriter.new(gz) do |tar|
|
46
|
+
metadata.files.each do |f|
|
47
|
+
f_stat = File.stat(f)
|
48
|
+
|
49
|
+
## Add directories
|
50
|
+
next tar.mkdir(Util::Cookbook.archive_path(metadata, f).to_s, f_stat.mode) if File.directory?(f)
|
51
|
+
|
52
|
+
## Add files
|
53
|
+
tar.add_file_simple(Util::Cookbook.archive_path(metadata, f).to_s, f_stat.mode, f_stat.size) do |entry|
|
54
|
+
f.open('rb') { |h| entry.write(h.read) }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
metadata
|
26
62
|
end
|
27
63
|
|
28
|
-
desc '
|
29
|
-
|
64
|
+
desc 'push PATH', 'Publish cookbook at PATH to supermarket.chef.io'
|
65
|
+
option 'chef-config', :type => :string,
|
66
|
+
:aliases => :c,
|
67
|
+
:default => File.join(ENV['HOME'], '.chef/knife.rb')
|
68
|
+
option :site, :type => :string, :aliases => :s
|
69
|
+
option :user, :type => :string, :aliases => :u
|
70
|
+
option :key, :type => :string, :aliases => :k
|
71
|
+
def push(cookbook = nil)
|
72
|
+
Chef::Config.from_file(options['chef-config'])
|
30
73
|
Util::Cookbook.path(cookbook) unless cookbook.nil?
|
31
74
|
|
75
|
+
## Set defaults after Chef::Config is loaded
|
76
|
+
options['site'] ||= Chef::Config.knife['supermarket_site'] || 'https://supermarket.chef.io/'
|
77
|
+
options['user'] ||= Chef::Config.knife['supermarket_user'] || Chef::Config.node_name
|
78
|
+
options['key'] ||= Chef::Config.knife['supermarket_key'] || Chef::Config.client_key
|
79
|
+
|
80
|
+
## Build the cookbook taball
|
81
|
+
metadata = invoke(Tasks::Cookbook, :build, [cookbook], options)
|
82
|
+
say_status :upload, "cookbook #{ metadata.name }@#{ metadata.version } to #{ options['site'] }"
|
83
|
+
|
84
|
+
metadata.archive.open('rb') do |c|
|
85
|
+
http_resp = Chef::CookbookSiteStreamingUploader.post(
|
86
|
+
File.join(options['site'], '/api/v1/cookbooks'),
|
87
|
+
options['user'],
|
88
|
+
options['key'],
|
89
|
+
:tarball => c,
|
90
|
+
:cookbook => { :category => '' }.to_json
|
91
|
+
)
|
92
|
+
|
93
|
+
if http_resp.code.to_i != 201
|
94
|
+
say_status :error, "Error uploading cookbook: #{ http_resp.code } #{ http_resp.message }", :red
|
95
|
+
say http_resp.body
|
96
|
+
exit(1)
|
97
|
+
end
|
98
|
+
end
|
32
99
|
end
|
33
100
|
|
34
101
|
desc 'version COOKBOOK', 'Print the current version of a vendored cookbook'
|
data/lib/builderator/util.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
1
3
|
module Builderator
|
2
4
|
module Util
|
3
5
|
class << self
|
@@ -43,7 +45,7 @@ module Builderator
|
|
43
45
|
end
|
44
46
|
|
45
47
|
def working_dir(relative = '.')
|
46
|
-
|
48
|
+
Pathname.pwd.join(relative).expand_path
|
47
49
|
end
|
48
50
|
end
|
49
51
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'chef/cookbook/metadata'
|
2
|
-
require '
|
2
|
+
require 'ignorefile'
|
3
3
|
|
4
4
|
require_relative '../util'
|
5
5
|
|
@@ -8,28 +8,73 @@ module Builderator
|
|
8
8
|
module Cookbook
|
9
9
|
DEFAULT_VENDOR = Util.working_dir('vendor/chef/cookbooks')
|
10
10
|
|
11
|
+
## Don't vendor VCS files.
|
12
|
+
## Reference GNU tar --exclude-vcs: https://www.gnu.org/software/tar/manual/html_section/tar_49.html
|
13
|
+
## Boosted from https://github.com/berkshelf/berkshelf/blob/master/lib/berkshelf/berksfile.rb
|
14
|
+
EXCLUDED_VCS_FILES = [
|
15
|
+
'.arch-ids', '{arch}', '.bzr', '.bzrignore', '.bzrtags',
|
16
|
+
'CVS', '.cvsignore', '_darcs', '.git', '.hg', '.hgignore',
|
17
|
+
'.hgrags', 'RCS', 'SCCS', '.svn', '**/.git', '.temp'].freeze
|
18
|
+
|
19
|
+
class Metadata < Chef::Cookbook::Metadata
|
20
|
+
def files
|
21
|
+
return @files unless @files.nil?
|
22
|
+
|
23
|
+
@files ||= Pathname.glob(Util::Cookbook.path.join('**/{*,.*}'))
|
24
|
+
ignorefile.apply!(@files)
|
25
|
+
|
26
|
+
@files
|
27
|
+
end
|
28
|
+
|
29
|
+
def archive
|
30
|
+
Util.working_dir("#{ name }-#{ version }.tgz")
|
31
|
+
end
|
32
|
+
|
33
|
+
def chefignore
|
34
|
+
Util::Cookbook.path.join('chefignore')
|
35
|
+
end
|
36
|
+
|
37
|
+
def gitignore
|
38
|
+
Util.working_dir('.gitignore')
|
39
|
+
end
|
40
|
+
|
41
|
+
def ignorefile
|
42
|
+
return @ignorefile unless @ignorefile.nil?
|
43
|
+
|
44
|
+
## Construct an ignorefile
|
45
|
+
@ignorefile = IgnoreFile.new(Util::Cookbook::EXCLUDED_VCS_FILES)
|
46
|
+
@ignorefile.load_file(chefignore)
|
47
|
+
@ignorefile.load_file(gitignore)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
11
51
|
class << self
|
12
52
|
def path(arg = nil)
|
13
53
|
## Set an explicit path to a cookbook
|
14
|
-
return @path = arg unless arg.nil?
|
54
|
+
return @path = Pathname.new(arg) unless arg.nil?
|
15
55
|
return @path unless @path.nil?
|
16
56
|
|
17
57
|
## Check for an embedded cookbook? ('./cookbook')
|
18
|
-
return @path = Util.working_dir('cookbook') if
|
58
|
+
return @path = Util.working_dir('cookbook') if Util.working_dir('cookbook').exist?
|
59
|
+
|
19
60
|
@path = Util.working_dir
|
20
61
|
end
|
21
62
|
|
63
|
+
def archive_path(metadata, file)
|
64
|
+
Pathname.new(metadata.name).join(Pathname.new(file).relative_path_from(path))
|
65
|
+
end
|
66
|
+
|
22
67
|
def berksfile
|
23
|
-
|
68
|
+
path.join('Berksfile')
|
24
69
|
end
|
25
70
|
|
26
71
|
def metadata
|
27
|
-
|
28
|
-
if
|
29
|
-
c.from_file(
|
72
|
+
Metadata.new.tap do |c|
|
73
|
+
if path.join('metadata.rb').exist?
|
74
|
+
c.from_file(path.join('metadata.rb').to_s)
|
30
75
|
|
31
|
-
elsif
|
32
|
-
c.from_json(
|
76
|
+
elsif path.join('metadata.json').exist?
|
77
|
+
c.from_json(path.join('metadata.json').to_s)
|
33
78
|
|
34
79
|
else
|
35
80
|
fail IOError, 'Unable to read metadata.rb or metadata.json!'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: builderator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Manero
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '12.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: ignorefile
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: thor
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|