cookbook-omnifetch 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ae1460747cd8d56df8edb96f910ab7aedc7884d
4
- data.tar.gz: dfe8988c3227ccb3660a8e591b803596ebf0a4e9
3
+ metadata.gz: e7d091088a8d8bc3534633afc049408ec4b1ae98
4
+ data.tar.gz: c41001a64b00582c791a9161d9b65989897aea44
5
5
  SHA512:
6
- metadata.gz: 0da7ef63902761a5a0d8574d4fcfcd189845a3b9fe3968f4c60e68ce9556f4f9a2f19123001a2e89e5f87a4438bad8f8614c6da9d2bd9c57913add7943ed47ff
7
- data.tar.gz: 5f9d292cae9cf0ed321c1a288cfa6677b6223e90e6def07a86025cb52999ac72c7934f4421dffc6d375b2fd7ba4e1b0559f15b6415bb88c97ffb89d85cc450c0
6
+ metadata.gz: 206300e6648ef964968ab77535acbfd494df3f20ab36d4155ae9a2ddb7224b16d23cc95192aa6a7a02799c5c5c47fb386aa161f6e3ec3d022d9c45789d173899
7
+ data.tar.gz: 44b5ba6fdde4ff019d481e2709a8b5b592012193b0cdfb46d741719dafe7f4a5e70dec776175d7fc91120b287e57aba5154babd81f6aa430a556b24ebb24894d
data/.gitignore CHANGED
@@ -20,3 +20,4 @@ tmp
20
20
  *.o
21
21
  *.a
22
22
  mkmf.log
23
+ .idea/*
data/README.md CHANGED
@@ -1,10 +1,3 @@
1
- # WARNING
2
-
3
- This repository will be moved in the future. It possibly will not be
4
- transferred via github transfer mechanisms, so the git URL may break.
5
-
6
- Don't use this yet unless you're prepared to deal with some breakage.
7
-
8
1
  # CookbookOmnifetch
9
2
 
10
3
  `CookbookOmnifetch` provides library code for fetching Chef cookbooks
@@ -28,10 +21,63 @@ Or install it yourself as:
28
21
 
29
22
  ## Usage
30
23
 
31
- TODO: Write usage instructions here
24
+ #### Inject Dependencies and Configure
25
+
26
+ Cookbook Omnifetch is designed to work with utilities from both the
27
+ Berkshelf and Chef Software ecosystems, so you have to configure it
28
+ before you can use it. In ChefDK, we do this:
29
+
30
+ ```ruby
31
+ # Configure CookbookOmnifetch's dependency injection settings to use our classes and config.
32
+ CookbookOmnifetch.configure do |c|
33
+ c.cache_path = File.expand_path('~/.chefdk/cache')
34
+ c.storage_path = Pathname.new(File.expand_path('~/.chefdk/cache/cookbooks'))
35
+ c.shell_out_class = ChefDK::ShellOut
36
+ c.cached_cookbook_class = ChefDK::CookbookMetadata
37
+ end
38
+ ```
39
+
40
+ #### Fetching Cookbooks
41
+
42
+ To download a cookbook:
43
+
44
+ ```ruby
45
+ fetcher = CookbookOmnifetch.init(dependency, source_options)
46
+ fetcher.install
47
+ ```
48
+
49
+ To specify the cookbook you want, you give CookbookOmnifetch a
50
+ dependency object that responds to `#name` and `#version_constraint`,
51
+ e.g.:
52
+
53
+ ```ruby
54
+ require 'semverse'
55
+
56
+ Dependency = Struct.new(:name, :version_constraint)
57
+
58
+ my_dep = Dependency.new("apache2", Semverse::Constraint.new("~> 1.0"))
59
+ ```
60
+
61
+ The source options for the cookbook are given as a Hash; the keys and
62
+ values vary based on the kind of storage location. As with Bundler's
63
+ `gem` options, one key specifies the type of upstream service for the
64
+ cookbook while other keys specify other options specific to that type.
65
+ For example:
66
+
67
+ ```ruby
68
+ CookbookOmnifetch.init(dependency, artifact_server: "https://supermarket.chef.io/api/v1/cookbooks/apache2/versions/3.0.1/download")
69
+ CookbookOmnifetch.init(dependency, git: "git@github.com:svanzoest/apache2-cookbook.git", tag: "v3.0.1")
70
+ CookbookOmnifetch.init(dependency, github: "svanzoest/apache2-cookbook", tag: "v3.0.1")
71
+ CookbookOmnifetch.init(dependency, path: "~/chef-cookbooks/apache2")
72
+ ```
32
73
 
33
74
  ## Contributing
34
75
 
76
+ As with other Chef Software projects, in order to contribute you need to
77
+ [agree to the contributor license agreement.](https://supermarket.getchef.com/become-a-contributor)
78
+
79
+ After that:
80
+
35
81
  1. Fork it
36
82
  2. Create your feature branch (`git checkout -b my-new-feature`)
37
83
  3. Commit your changes (`git commit -am 'Add some feature'`)
@@ -46,7 +46,8 @@ module CookbookOmnifetch
46
46
  FileUtils.mv(tempfile.path, cache_path)
47
47
  end
48
48
 
49
- Dir.mktmpdir do |staging_dir|
49
+ FileUtils.mkdir_p(staging_root) unless staging_root.exist?
50
+ Dir.mktmpdir(nil, staging_root) do |staging_dir|
50
51
  Zlib::GzipReader.open(cache_path) do |gz_file|
51
52
  tar = Archive::Tar::Minitar::Input.new(gz_file)
52
53
  tar.each do |e|
@@ -90,8 +91,8 @@ module CookbookOmnifetch
90
91
 
91
92
  def lock_data
92
93
  out = {}
93
- out["artifactserver"] = uri
94
- out["version"] = cookbook_version
94
+ out['artifactserver'] = uri
95
+ out['version'] = cookbook_version
95
96
  out
96
97
  end
97
98
 
@@ -105,7 +106,7 @@ module CookbookOmnifetch
105
106
 
106
107
 
107
108
  def ==(other)
108
- raise "TODO"
109
+ raise 'TODO'
109
110
  other.is_a?(GitLocation) &&
110
111
  other.uri == uri &&
111
112
  other.branch == branch &&
@@ -114,10 +115,29 @@ module CookbookOmnifetch
114
115
  other.rel == rel
115
116
  end
116
117
 
118
+ # The path where all pristine tarballs from an artifactserver are held.
119
+ # Tarballs are moved/swapped into this location once they have been staged
120
+ # in a co-located staging directory.
121
+ #
122
+ # @return [Pathname]
117
123
  def cache_root
118
124
  Pathname.new(CookbookOmnifetch.cache_path).join('.cache', 'artifactserver')
119
125
  end
120
126
 
127
+ # The path where tarballs are downloaded to and unzipped. On certain platforms
128
+ # you have a better chance of getting an atomic move if your temporary working
129
+ # directory is on the same device/volume as the destination. To support this,
130
+ # we use a staging directory located under the cache path under the rather mild
131
+ # assumption that everything under the cache path is going to be on one device.
132
+ #
133
+ # Do not create anything under this directory that isn't randomly named and
134
+ # remember to release your files once you are done.
135
+ #
136
+ # @return [Pathname]
137
+ def staging_root
138
+ Pathname.new(CookbookOmnifetch.cache_path).join('.cache_tmp', 'artifactserver')
139
+ end
140
+
121
141
  # The path where the pristine tarball is cached
122
142
  #
123
143
  # @return [Pathname]
@@ -1,3 +1,3 @@
1
1
  module CookbookOmnifetch
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -16,7 +16,7 @@ module CookbookOmnifetch
16
16
 
17
17
  let(:options) { {artifactserver: url, version: cookbook_version } }
18
18
 
19
- subject(:public_repo_location) { ArtifactserverLocation.new(dependency, options) }
19
+ subject(:public_repo_location) { described_class.new(dependency, options) }
20
20
 
21
21
  it "has a URI" do
22
22
  expect(public_repo_location.uri).to eq(url)
@@ -56,6 +56,60 @@ module CookbookOmnifetch
56
56
  }
57
57
  expect(public_repo_location.lock_data).to eq(expected_data)
58
58
  end
59
+
60
+ context "when asked to install a new cookbook" do
61
+
62
+ let(:http_client) { double("Http Client") }
63
+
64
+ let(:test_root) { Dir.mktmpdir(nil) }
65
+
66
+ let(:storage_path) { File.join(test_root, "storage") }
67
+
68
+ let(:cache_path) { File.join(test_root, "cache") }
69
+
70
+ let(:cookbook_fixtures_path) { fixtures_path.join('cookbooks') }
71
+
72
+ let(:cookbook_name) { "example_cookbook" }
73
+
74
+ let(:cookbook_version) { "0.5.0" }
75
+
76
+ let(:cookbook_tarball_handle) do
77
+ gz_file_name = File.join(test_root, 'input.gz')
78
+ Zlib::GzipWriter.open(gz_file_name) do |gz|
79
+ # Minitar writes the full paths provided and doesn't seem to have a way to
80
+ # remove prefixes. So we chdir like barbarians.
81
+ Dir.chdir(cookbook_fixtures_path) do
82
+ Archive::Tar::Minitar.pack(cookbook_name, gz)
83
+ end
84
+ end
85
+ File.open(gz_file_name)
86
+ end
87
+
88
+ let(:cookbook_files) { %w". .. .gitignore .kitchen.yml Berksfile Berksfile.lock metadata.rb README.md recipes" }
89
+
90
+ before do
91
+ allow(CookbookOmnifetch).to receive(:storage_path).and_return(Pathname.new(storage_path))
92
+ allow(CookbookOmnifetch).to receive(:cache_path).and_return(cache_path)
93
+ FileUtils.mkdir_p(storage_path)
94
+ end
95
+
96
+ after do
97
+ FileUtils.rm_r(test_root)
98
+ end
99
+
100
+ it "installs the cookbook to the desired install path" do
101
+ expect(public_repo_location).to receive(:http_client).and_return(http_client)
102
+ expect(cookbook_tarball_handle).to receive(:close).and_call_original
103
+ expect(http_client).to receive(:streaming_request).with(nil).and_yield(cookbook_tarball_handle)
104
+ expect(public_repo_location).to receive(:validate_cached!)
105
+
106
+ public_repo_location.install
107
+
108
+ expect(File).to exist(public_repo_location.cache_path)
109
+ expect(Dir).to exist(public_repo_location.install_path)
110
+ expect(Dir.entries(public_repo_location.install_path)).to match_array(cookbook_files)
111
+ end
112
+ end
59
113
  end
60
114
  end
61
115
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cookbook-omnifetch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Winsor
@@ -13,48 +13,48 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2014-07-09 00:00:00.000000000 Z
16
+ date: 2015-03-26 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: minitar
20
20
  requirement: !ruby/object:Gem::Requirement
21
21
  requirements:
22
- - - ~>
22
+ - - "~>"
23
23
  - !ruby/object:Gem::Version
24
24
  version: 0.5.4
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
28
28
  requirements:
29
- - - ~>
29
+ - - "~>"
30
30
  - !ruby/object:Gem::Version
31
31
  version: 0.5.4
32
32
  - !ruby/object:Gem::Dependency
33
33
  name: rake
34
34
  requirement: !ruby/object:Gem::Requirement
35
35
  requirements:
36
- - - ~>
36
+ - - "~>"
37
37
  - !ruby/object:Gem::Version
38
38
  version: '10.3'
39
39
  type: :development
40
40
  prerelease: false
41
41
  version_requirements: !ruby/object:Gem::Requirement
42
42
  requirements:
43
- - - ~>
43
+ - - "~>"
44
44
  - !ruby/object:Gem::Version
45
45
  version: '10.3'
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: rspec
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  requirements:
50
- - - ~>
50
+ - - "~>"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '3.0'
53
53
  type: :development
54
54
  prerelease: false
55
55
  version_requirements: !ruby/object:Gem::Requirement
56
56
  requirements:
57
- - - ~>
57
+ - - "~>"
58
58
  - !ruby/object:Gem::Version
59
59
  version: '3.0'
60
60
  description:
@@ -69,8 +69,8 @@ executables: []
69
69
  extensions: []
70
70
  extra_rdoc_files: []
71
71
  files:
72
- - .gitignore
73
- - .rspec
72
+ - ".gitignore"
73
+ - ".rspec"
74
74
  - Gemfile
75
75
  - LICENSE
76
76
  - README.md
@@ -110,17 +110,17 @@ require_paths:
110
110
  - lib
111
111
  required_ruby_version: !ruby/object:Gem::Requirement
112
112
  requirements:
113
- - - '>='
113
+ - - ">="
114
114
  - !ruby/object:Gem::Version
115
115
  version: '0'
116
116
  required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  requirements:
118
- - - '>='
118
+ - - ">="
119
119
  - !ruby/object:Gem::Version
120
120
  version: '0'
121
121
  requirements: []
122
122
  rubyforge_project:
123
- rubygems_version: 2.0.3
123
+ rubygems_version: 2.2.2
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: Library code to fetch Chef cookbooks from a variety of sources to a local