knife_cookbook_dependencies_over_http 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +25 -0
  2. data/.rbenv-version +1 -0
  3. data/Gemfile +3 -0
  4. data/Guardfile +17 -0
  5. data/LICENSE +22 -0
  6. data/README.rdoc +107 -0
  7. data/Rakefile +76 -0
  8. data/features/clean.feature +29 -0
  9. data/features/error_messages.feature +16 -0
  10. data/features/install.feature +24 -0
  11. data/features/lockfile.feature +25 -0
  12. data/features/step_definitions/cli_steps.rb +30 -0
  13. data/features/support/env.rb +33 -0
  14. data/features/update.feature +38 -0
  15. data/features/without.feature +27 -0
  16. data/knife_cookbook_dependencies_over_http.gemspec +38 -0
  17. data/lib/chef/knife/cookbook_dependencies_clean.rb +19 -0
  18. data/lib/chef/knife/cookbook_dependencies_install.rb +22 -0
  19. data/lib/chef/knife/cookbook_dependencies_update.rb +21 -0
  20. data/lib/kcd.rb +1 -0
  21. data/lib/kcd/cookbook.rb +237 -0
  22. data/lib/kcd/cookbookfile.rb +39 -0
  23. data/lib/kcd/core_ext/kernel.rb +33 -0
  24. data/lib/kcd/dsl.rb +13 -0
  25. data/lib/kcd/error_messages.rb +13 -0
  26. data/lib/kcd/git.rb +86 -0
  27. data/lib/kcd/knife_utils.rb +13 -0
  28. data/lib/kcd/lockfile.rb +40 -0
  29. data/lib/kcd/metacookbook.rb +18 -0
  30. data/lib/kcd/shelf.rb +100 -0
  31. data/lib/kcd/version.rb +3 -0
  32. data/lib/knife_cookbook_dependencies.rb +53 -0
  33. data/spec/fixtures/cookbooks/example_cookbook/README.md +12 -0
  34. data/spec/fixtures/cookbooks/example_cookbook/metadata.rb +6 -0
  35. data/spec/fixtures/cookbooks/example_cookbook/recipes/default.rb +8 -0
  36. data/spec/fixtures/lockfile_spec/with_lock/Cookbookfile +1 -0
  37. data/spec/fixtures/lockfile_spec/without_lock/Cookbookfile.lock +5 -0
  38. data/spec/lib/kcd/cookbook_spec.rb +135 -0
  39. data/spec/lib/kcd/cookbookfile_spec.rb +26 -0
  40. data/spec/lib/kcd/dsl_spec.rb +56 -0
  41. data/spec/lib/kcd/git_spec.rb +58 -0
  42. data/spec/lib/kcd/lockfile_spec.rb +54 -0
  43. data/spec/lib/kcd/shelf_spec.rb +81 -0
  44. data/spec/spec_helper.rb +78 -0
  45. data/todo.txt +13 -0
  46. metadata +301 -0
data/.gitignore ADDED
@@ -0,0 +1,25 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ cookbooks
19
+ *~
20
+ *.tar*
21
+ \#*
22
+ ^Cookbookfile*
23
+ .DS_Store
24
+ spec/fixtures/vcr_cassettes/*
25
+ *.sw[op]
data/.rbenv-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3-p125
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,17 @@
1
+ guard 'spork' do
2
+ watch('Gemfile')
3
+ watch('spec/spec_helper.rb') { :rspec }
4
+ watch(%r{^features/support/}) { :cucumber }
5
+ end
6
+
7
+ guard 'rspec', :version => 2, :cli => "--color --drb --format Fuubar", :all_on_start => false, :all_after_pass => false, :notification => false do
8
+ watch(%r{^spec/.+_spec\.rb$})
9
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
10
+ watch('spec/spec_helper.rb') { "spec" }
11
+ end
12
+
13
+ guard 'cucumber', :cli => "--drb --format pretty", :all_on_start => false, :all_after_pass => false, :notification => false do
14
+ watch(%r{^features/.+\.feature$})
15
+ watch(%r{^features/support/.+$}) { 'features' }
16
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
17
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Riot Games
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,107 @@
1
+ = Knife Cookbook Dependencies
2
+
3
+ A knife plugin to retrieve cookbook dependencies.
4
+
5
+ == Getting Started
6
+
7
+ === Install
8
+
9
+ $ gem install knife_cookbook_dependencies
10
+
11
+ === Use
12
+
13
+ ==== Cookbookfile
14
+
15
+ Dependencies are managed via a `Cookbookfile` in the directory where you want the cookbooks to be installed. The Cookbookfile, like Bundler's Gemfile, contains which cookbooks are needed and, optionally, where to find them:
16
+
17
+ cookbook 'memcached'
18
+ cookbook 'nginx'
19
+ cookbook 'my_app', path: '/path/to/cookbook'
20
+ cookbook 'mysql', git: 'git://github.com/opscode-cookbooks/mysql.git'
21
+
22
+ ==== CLI
23
+
24
+ The CLI consists of 3 commands: install, update, clean
25
+
26
+ $ knife cookbook dependencies (install|update) [(--without|-W) group_to_exclude]
27
+ $ knife cookbook dependencies clean
28
+
29
+ note::
30
+
31
+ `knife cookbook dependencies` subcommands can be used by its alias `knife cookbook deps`
32
+
33
+ [install] Installs the from the Cookbookfile.lock, or Cookbookfile if the the lockfile does not exist.
34
+
35
+ [update] Skips the lockfile and installs fresh
36
+
37
+ [clean] Removes all of the files managed by the `Cookbookfile`, including the `Cookbookfile.lock`, temp directory used for downloads and extractions and the cookbooks directory.
38
+
39
+ == The Cookbookfile
40
+
41
+ Cookbooks are defined as dependencies by declaring them in the `Cookbookfile`
42
+
43
+ cookbook 'nginx'
44
+
45
+ Cookbooks without additional options are assumed to come from the Opscode Community site at the latest available version: http://community.opscode.com/cookbooks
46
+
47
+ Options available include:
48
+
49
+ version constraint
50
+
51
+ cookbook "nginx", "= 0.101.2" # precisely 0.101.2
52
+ cookbook "mysql", "< 1.2.4" # less than and not including 1.2.4
53
+ cookbook "openssl", "~> 1.0.0" # greater than 1.0.0, and up to but not including 1.1.0
54
+
55
+ git
56
+
57
+ # ref can be a branch name, tag, or commit hash. If ref is not provided, HEAD is used.
58
+ cookbook "mysql", git: "https://github.com/opscode-cookbooks/mysql.git", ref: "<any git ref>"
59
+
60
+ path
61
+
62
+ # knife cookbook dependencies will look in /path/to/location/of/my_application for the cookbook
63
+ cookbook "my_application", path: "/path/to/location/of"
64
+
65
+ === Groups
66
+
67
+ Groups can be defined via blocks or inline as an option:
68
+
69
+ group :solo do
70
+ cookbook 'base'
71
+ end
72
+
73
+ cookbook 'base', :group => 'solo'
74
+
75
+ When using install or update, groups can be excluded with the --without GROUP_NAME or -W GROUP_NAME flags.
76
+
77
+ = Contributing
78
+
79
+ == Running tests
80
+
81
+ === Install prerequisites
82
+
83
+ Install the latest version of {Bundler}[http://gembundler.com]
84
+
85
+ $ gem install bundler
86
+
87
+ Clone the project
88
+
89
+ $ git clone git://github.com/RiotGames/knife_cookbook_dependencies.git
90
+
91
+ and run:
92
+
93
+ $ cd knife_cookbook_dependencies
94
+ $ bundle install
95
+
96
+ Bundler will install all gems and their dependencies required for testing and developing.
97
+
98
+ === Running unit (RSpec) and acceptance (Cucumber) tests
99
+
100
+ $ bundle exec guard start
101
+
102
+ = Authors and Contributors
103
+
104
+ * Josiah Kiehl (<josiah@skirmisher.net>)
105
+ * Jamie Winsor (<jamie@vialstudios.com>)
106
+ * Erik Hollensbe (<erik@hollensbe.org>)
107
+ * Michael Ivey (<ivey@gweezlebur.com>)
data/Rakefile ADDED
@@ -0,0 +1,76 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rdoc/task'
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc "clean VCR cassettes"
6
+ task "vcr:clean" do
7
+ sh "rm -rf spec/fixtures/vcr_cassettes/*"
8
+ end
9
+
10
+ desc "check documentation coverage"
11
+ task "rdoc:check" do
12
+ sh "rdoc -C " + Dir["lib/**/*.rb"].join(" ")
13
+ end
14
+
15
+ desc "clean up doco/coverage"
16
+ task :clean do
17
+ sh "rm -fr rdoc coverage"
18
+ end
19
+
20
+ desc "generate documentation"
21
+ RDoc::Task.new :rdoc do |r|
22
+ r.main = "README.rdoc"
23
+ r.rdoc_files.include("README.rdoc", "lib/**/*.rb")
24
+ r.rdoc_dir = "rdoc"
25
+ end
26
+
27
+ desc "Run specs"
28
+ RSpec::Core::RakeTask.new do |t|
29
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
30
+ # Put spec opts in a file named .rspec in root
31
+ end
32
+
33
+ task :check => [:default, "rdoc:check"]
34
+ task :default => [:clean, :spec]
35
+
36
+ begin
37
+ require 'rspec/core/rake_task'
38
+
39
+ desc "Run specs"
40
+ RSpec::Core::RakeTask.new(:spec) do |r|
41
+ r.rspec_path = "bundle exec rspec"
42
+ end
43
+ rescue LoadError
44
+ desc 'RSpec rake task not available'
45
+ task :spec do
46
+ abort 'RSpec rake task is not available. Be sure to install rspec.'
47
+ end
48
+ end
49
+
50
+ begin
51
+ require 'cucumber'
52
+ require 'cucumber/rake/task'
53
+
54
+ Cucumber::Rake::Task.new(:features) do |t|
55
+ t.cucumber_opts = "--format progress --tags ~@wip --tags ~@live"
56
+ end
57
+
58
+ namespace :features do
59
+ Cucumber::Rake::Task.new(:wip) do |t|
60
+ t.cucumber_opts = "--format progress --tags @wip"
61
+ end
62
+
63
+ Cucumber::Rake::Task.new(:current) do |t|
64
+ t.cucumber_opts = "--format progress --tags @current"
65
+ end
66
+
67
+ Cucumber::Rake::Task.new(:tag) do |t|
68
+ t.cucumber_opts = "--format progress --tags @#{ENV['tag']}"
69
+ end
70
+ end
71
+ rescue LoadError
72
+ desc 'Cucumber rake task not available'
73
+ task :features do
74
+ abort 'Cucumber rake task is not available. Be sure to install cucumber.'
75
+ end
76
+ end
@@ -0,0 +1,29 @@
1
+ Feature: Clean
2
+ As a user
3
+ I want to be able to clean all the files downloaded/created by kcd
4
+ So that I can be sure previous runs are not messing up my current action
5
+ and so I can get rid of installations I don't want any more
6
+
7
+ Scenario: knife cookbook dependencies clean
8
+ Given I write to "Cookbookfile" with:
9
+ """
10
+ cookbook "mysql"
11
+ """
12
+ When I run `knife cookbook dependencies install`
13
+ And I run `knife cookbook dependencies clean`
14
+ Then the following directories should not exist:
15
+ | cookbooks |
16
+ And the file "Cookbookfile.lock" should not exist
17
+ And the temp directory should not exist
18
+
19
+ Scenario: knife cookbook deps clean
20
+ Given I write to "Cookbookfile" with:
21
+ """
22
+ cookbook "mysql"
23
+ """
24
+ When I run `knife cookbook deps install`
25
+ And I run `knife cookbook deps clean`
26
+ Then the following directories should not exist:
27
+ | cookbooks |
28
+ And the file "Cookbookfile.lock" should not exist
29
+ And the temp directory should not exist
@@ -0,0 +1,16 @@
1
+ Feature: Friendly error messages
2
+ As a CLI user
3
+ I want to have friendly human readable error messages
4
+ So I can identify what went wrong without ambiguity
5
+
6
+ Scenario: running without a Cookbookfile
7
+ When I run `knife cookbook dependencies install`
8
+ Then the output should contain "FATAL: There is no Cookbookfile in "
9
+
10
+ Scenario: when missing a cookbook
11
+ Given I write to "Cookbookfile" with:
12
+ """
13
+ cookbook "doesntexist"
14
+ """
15
+ When I run `knife cookbook dependencies install`
16
+ Then the output should contain "FATAL: The cookbook doesntexist was not found on the Opscode Community site. Provide a git or path key for doesntexist if it is unpublished."
@@ -0,0 +1,24 @@
1
+ Feature: install cookbooks from a Cookbookfile
2
+ As a user with a Cookbookfile
3
+ I want to be able to run knife cookbook dependencies install to install my cookbooks
4
+ So that I don't have to download my cookbooks and their dependencies manually
5
+
6
+ Scenario: install cookbooks
7
+ Given I write to "Cookbookfile" with:
8
+ """
9
+ cookbook "mysql"
10
+ """
11
+ When I run `knife cookbook dependencies install`
12
+ Then the following directories should exist:
13
+ | cookbooks/mysql |
14
+ | cookbooks/openssl |
15
+
16
+ Scenario: install cookbooks with the alias
17
+ Given I write to "Cookbookfile" with:
18
+ """
19
+ cookbook "mysql"
20
+ """
21
+ When I run `knife cookbook deps install`
22
+ Then the following directories should exist:
23
+ | cookbooks/mysql |
24
+ | cookbooks/openssl |
@@ -0,0 +1,25 @@
1
+ Feature: Cookbookfile.lock
2
+ As a user
3
+ I want my versions to be locked even when I don't specify versions in my Cookbookfile
4
+ So when I share my repository, all other developers get the same versions that I did when I installed.
5
+
6
+ @slow_process
7
+ Scenario: Writing the Cookbookfile.lock
8
+ Given I write to "Cookbookfile" with:
9
+ """
10
+ cookbook 'ntp'
11
+ cookbook 'mysql', git: 'https://github.com/opscode-cookbooks/mysql.git', :ref => '190c0c2267785b7b9b303369b8a64ed04364d5f9'
12
+ cookbook 'example_cookbook', path: File.join(KCD.root, 'spec', 'fixtures', 'cookbooks')
13
+ """
14
+ When I run `knife cookbook dependencies install`
15
+ When I sleep
16
+ Then a file named "Cookbookfile.lock" should exist in the current directory
17
+ And the file "Cookbookfile.lock" should contain in the current directory:
18
+ """
19
+ cookbook 'mysql', :git => 'https://github.com/opscode-cookbooks/mysql.git', :ref => '190c0c2267785b7b9b303369b8a64ed04364d5f9'
20
+ cookbook 'example_cookbook', :path => .*
21
+ cookbook 'ntp', :locked_version => '1.1.8'
22
+ cookbook 'openssl', :locked_version => '1.0.0'
23
+ cookbook 'windows', :locked_version => '1.2.12'
24
+ cookbook 'chef_handler', :locked_version => '1.0.6'
25
+ """
@@ -0,0 +1,30 @@
1
+ require 'aruba/api'
2
+
3
+ World(Aruba::Api)
4
+
5
+ Then /^I trace$/ do
6
+ end
7
+
8
+ When /^I sleep$/ do
9
+ sleep 10
10
+ end
11
+
12
+ Then /^a file named "(.*?)" should exist in the current directory$/ do |filename|
13
+ in_current_dir do
14
+ File.exists?(filename).should be_true # not sure why Aruba's
15
+ # #check_file_presence
16
+ # doesn't work here. It
17
+ # looks in the wrong
18
+ # directory.
19
+ end
20
+ end
21
+
22
+ Then /^the file "(.*?)" should contain in the current directory:$/ do |filename, string|
23
+ in_current_dir do
24
+ File.read(filename).should match(Regexp.new(string))
25
+ end
26
+ end
27
+
28
+ Then /^the temp directory should not exist$/ do
29
+ File.exists?(KCD::TMP_DIRECTORY).should be_false
30
+ end
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup
4
+ require 'spork'
5
+
6
+ Spork.prefork do
7
+ require 'rspec'
8
+ require 'pp'
9
+ require 'aruba/cucumber'
10
+ require 'vcr'
11
+
12
+ After do
13
+ KCD.clean
14
+ end
15
+
16
+ Around do |scenario, block|
17
+ VCR.use_cassette(scenario.title) do
18
+ block.call
19
+ end
20
+ end
21
+
22
+ Before do
23
+ @aruba_io_wait_seconds = 5
24
+ end
25
+
26
+ Before('@slow_process') do
27
+ @aruba_io_wait_seconds = 10
28
+ end
29
+ end
30
+
31
+ Spork.each_run do
32
+ require 'kcd'
33
+ end
@@ -0,0 +1,38 @@
1
+ Feature: update
2
+ As a user
3
+ I want a way to update the versions without clearing out the files I've downloaded
4
+ So that I can update faster than a clean install
5
+
6
+ Scenario: knife cookbook dependencies update
7
+ Given I write to "Cookbookfile" with:
8
+ """
9
+ cookbook "mysql"
10
+ """
11
+ Given I write to "Cookbookfile.lock" with:
12
+ """
13
+ cookbook 'mysql', :locked_version => '0.0.1'
14
+ cookbook 'openssl', :locked_version => '0.0.1'
15
+ """
16
+ When I run `knife cookbook dependencies update`
17
+ Then the file "Cookbookfile.lock" should contain exactly:
18
+ """
19
+ cookbook 'mysql', :locked_version => '1.2.4'
20
+ cookbook 'openssl', :locked_version => '1.0.0'
21
+ """
22
+
23
+ Scenario: knife cookbook deps update
24
+ Given I write to "Cookbookfile" with:
25
+ """
26
+ cookbook "mysql"
27
+ """
28
+ Given I write to "Cookbookfile.lock" with:
29
+ """
30
+ cookbook 'mysql', :locked_version => '0.0.1'
31
+ cookbook 'openssl', :locked_version => '0.0.1'
32
+ """
33
+ When I run `knife cookbook deps update`
34
+ Then the file "Cookbookfile.lock" should contain exactly:
35
+ """
36
+ cookbook 'mysql', :locked_version => '1.2.4'
37
+ cookbook 'openssl', :locked_version => '1.0.0'
38
+ """