vagrant-cookbooks 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7b94463afd00c0380aaf5592ded3a9009a2dc9c9
4
+ data.tar.gz: d66557fa165ee247d72d988a0a052e682f6ed851
5
+ SHA512:
6
+ metadata.gz: d4da996b05fba9402ef81d3a21ce7da404aef545b8eeddfcb286f0c905d72c5b121cf8be14224d51989d6e8d3085f58a7729b993341de9bf86d38d576888d741
7
+ data.tar.gz: 3c84039c93799fc1776f27ce9b6c63ca7a6359464d83acd077b6bfb4259fec44787314f1324fc10f526219c00b292ad6409a37a933108b79b76b4bf7dbdf2be3
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ vendor/
16
+ *.gem
17
+ .vagrant
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vagrant-cookbooks.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem "vagrant", git: "git@github.com:mitchellh/vagrant"
8
+ end
9
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Simon Eskildsen
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.md ADDED
@@ -0,0 +1,5 @@
1
+ # Vagrant::Cookbooks
2
+
3
+ Vagrant plugin for cloning down cookbooks before provisioning. It'll clone them
4
+ to the path configured in `cookbooks_path` (if there are multiple it'll choose
5
+ the first one).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/Vagrantfile ADDED
@@ -0,0 +1,8 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ require_relative "lib/vagrant-cookbooks"
5
+
6
+ Vagrant.configure(2) do |config|
7
+ config.vm.box = "ubuntu/trusty64"
8
+ end
@@ -0,0 +1 @@
1
+ require_relative "vagrant/cookbooks"
@@ -0,0 +1,117 @@
1
+ require_relative "cookbooks/version"
2
+
3
+ module Vagrant
4
+ module Cookbooks
5
+ class Plugin < Vagrant.plugin("2")
6
+ name "vagrant-cookbooks"
7
+ description "Clone down Chef cookbooks"
8
+
9
+ action_hook "vagrant_cookbooks" do |hook|
10
+ # If LibrarianChef is configured cookbooks need to be cloned before.
11
+ if defined?(VagrantPlugins::LibrarianChef)
12
+ hook.before VagrantPlugins::LibrarianChef::Action::Install,
13
+ Action
14
+ else
15
+ hook.before Vagrant::Action::Builtin::Provision, Action
16
+ end
17
+ end
18
+
19
+ config "cookbooks" do
20
+ Config
21
+ end
22
+ end
23
+
24
+ class Config < Vagrant.plugin(2, :config)
25
+ attr_accessor :git
26
+ attr_accessor :path
27
+
28
+ def initialize
29
+ @git = UNSET_VALUE
30
+ @path = UNSET_VALUE
31
+ end
32
+
33
+ def finalize!
34
+ @git = "git@github.com:Shopify/cookbooks" if @git == UNSET_VALUE
35
+ @path = ".vagrant/cookbooks" if @path == UNSET_VALUE
36
+ end
37
+ end
38
+
39
+ class Action
40
+ attr_reader :env, :app
41
+
42
+ def initialize(app, env)
43
+ @app = app
44
+ @env = env
45
+ end
46
+
47
+ def call(env)
48
+ if cookbooks?
49
+ update_cookbooks
50
+ else
51
+ clone_cookbooks
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ def on_cookbooks_branch?
58
+ cookbooks_branch != "master"
59
+ end
60
+
61
+ def cookbooks_branch
62
+ system!("cd #{escape(cookbooks_path)} && git rev-parse --abbrev-ref HEAD")
63
+ end
64
+
65
+ def cookbooks?
66
+ Dir.exists?(cookbooks_path)
67
+ end
68
+
69
+ def update_cookbooks
70
+ if on_cookbooks_branch?
71
+ env[:ui].warn "Cookbooks on branch `#{cookbooks_branch}`, skipping update"
72
+ else
73
+ env[:ui].info "Updating cookbooks"
74
+ system!("cd #{escape(cookbooks_path)}; git fetch origin; git rebase origin/master")
75
+ end
76
+ end
77
+
78
+ def clone_cookbooks
79
+ env[:ui].info "Cloning cookbooks"
80
+ system!("git clone git@github.com:Shopify/cookbooks #{escape(cookbooks_path)} 2>&1")
81
+ end
82
+
83
+ def escape(path)
84
+ Shellwords.shellescape(path)
85
+ end
86
+
87
+ def system!(command, timeout = 60 * 5)
88
+ result = nil
89
+
90
+ Timeout.timeout(timeout) do
91
+ result = `#{command}`.chomp
92
+ end
93
+
94
+ unless $?.success?
95
+ env[:ui].error "Failed to execute: #{command}: #{result}"
96
+ exit 1
97
+ end
98
+
99
+ result
100
+ rescue Timeout::Error
101
+ env[:ui].error "Timed out executing: #{command}: #{result}"
102
+ exit 1
103
+ end
104
+
105
+ def cookbooks_path
106
+ "#{cwd}/#{env[:machine].config.cookbooks.path}"
107
+ end
108
+
109
+ def cwd
110
+ pwd = ENV["VAGRANT_CWD"] || Dir.pwd
111
+ cwd = Pathname.new(pwd)
112
+ raise "#{pwd} is not a directory" unless cwd.directory?
113
+ cwd
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,5 @@
1
+ module Vagrant
2
+ module Cookbooks
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant/cookbooks/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vagrant-cookbooks"
8
+ spec.version = Vagrant::Cookbooks::VERSION
9
+ spec.authors = ["Simon Eskildsen"]
10
+ spec.email = ["sirup@sirupsen.com"]
11
+ spec.summary = %q{Clone cookbooks before provision}
12
+ spec.description = %q{Clone cookbooks before provision}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-cookbooks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Simon Eskildsen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Clone cookbooks before provision
42
+ email:
43
+ - sirup@sirupsen.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - Vagrantfile
54
+ - lib/vagrant-cookbooks.rb
55
+ - lib/vagrant/cookbooks.rb
56
+ - lib/vagrant/cookbooks/version.rb
57
+ - vagrant-cookbooks.gemspec
58
+ homepage: ''
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.2.2
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Clone cookbooks before provision
82
+ test_files: []