guard-knife 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +21 -0
- data/README.md +63 -0
- data/Rakefile +154 -0
- data/guard-knife.gemspec +41 -0
- data/lib/guard/knife.rb +99 -0
- data/lib/guard/knife/templates/Guardfile +6 -0
- metadata +99 -0
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) Nikolay Sturm <github@erisiandiscord.de>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
Guard::Knife
|
2
|
+
============
|
3
|
+
|
4
|
+
Knife guard allows to update cookbooks, data bags, environments, and roles
|
5
|
+
automatically when files are modified.
|
6
|
+
|
7
|
+
Install
|
8
|
+
-------
|
9
|
+
|
10
|
+
Please be sure to have [Guard](https://github.com/guard/guard) installed before
|
11
|
+
continueing.
|
12
|
+
|
13
|
+
Install the gem:
|
14
|
+
|
15
|
+
$ gem install guard-knife
|
16
|
+
|
17
|
+
Add it to your Gemfile
|
18
|
+
|
19
|
+
``` ruby
|
20
|
+
gem 'guard-knife'
|
21
|
+
```
|
22
|
+
|
23
|
+
Add guard definition to your Guardfile by running this command:
|
24
|
+
|
25
|
+
$ guard init knife
|
26
|
+
|
27
|
+
Guardfile
|
28
|
+
---------
|
29
|
+
|
30
|
+
``` ruby
|
31
|
+
guard 'knife' do
|
32
|
+
watch(%r{^cookbooks/.+$})
|
33
|
+
watch(%r{^data_bags/.+$})
|
34
|
+
watch(%r{^environments/.+$})
|
35
|
+
watch(%r{^roles/.+$})
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
Options
|
40
|
+
-------
|
41
|
+
|
42
|
+
By default Guard::Knife uses your `~/.chef/knife.rb`. To use a different
|
43
|
+
configuration file, use the `:config` option:
|
44
|
+
|
45
|
+
``` ruby
|
46
|
+
guard 'knife', :config => '~/.chef/other_knife_config.rb' do
|
47
|
+
# ...
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
Development
|
52
|
+
-----------
|
53
|
+
|
54
|
+
* Source hosted at [GitHub](https://github.com/nistude/guard-knife)
|
55
|
+
* Report Issues/Questions/Feature requests on [GitHub Issues](https://github.com/nistude/guard-knife/issues)
|
56
|
+
|
57
|
+
Pull requests are very welcome! Make sure your patches are well tested. Please
|
58
|
+
create a topic branch for every separate change you make.
|
59
|
+
|
60
|
+
Author
|
61
|
+
------
|
62
|
+
|
63
|
+
[Nikolay Sturm](http://blog.nistu.de/)
|
data/Rakefile
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
#############################################################################
|
6
|
+
#
|
7
|
+
# Helper functions
|
8
|
+
#
|
9
|
+
#############################################################################
|
10
|
+
|
11
|
+
def name
|
12
|
+
@name ||= Dir['*.gemspec'].first.split('.').first
|
13
|
+
end
|
14
|
+
|
15
|
+
def shortname
|
16
|
+
@shortname ||= name.split('-')[1]
|
17
|
+
end
|
18
|
+
|
19
|
+
def version
|
20
|
+
line = File.read("lib/guard/#{shortname}.rb")[/^\s*VERSION\s*=\s*.*/]
|
21
|
+
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
22
|
+
end
|
23
|
+
|
24
|
+
def date
|
25
|
+
Date.today.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
def rubyforge_project
|
29
|
+
name
|
30
|
+
end
|
31
|
+
|
32
|
+
def gemspec_file
|
33
|
+
"#{name}.gemspec"
|
34
|
+
end
|
35
|
+
|
36
|
+
def gem_file
|
37
|
+
"#{name}-#{version}.gem"
|
38
|
+
end
|
39
|
+
|
40
|
+
def replace_header(head, header_name)
|
41
|
+
head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
|
42
|
+
end
|
43
|
+
|
44
|
+
#############################################################################
|
45
|
+
#
|
46
|
+
# Standard tasks
|
47
|
+
#
|
48
|
+
#############################################################################
|
49
|
+
|
50
|
+
task :default => :test
|
51
|
+
|
52
|
+
require 'rake/testtask'
|
53
|
+
Rake::TestTask.new(:test) do |test|
|
54
|
+
test.libs << 'lib' << 'test'
|
55
|
+
test.pattern = 'test/**/test_*.rb'
|
56
|
+
test.verbose = true
|
57
|
+
end
|
58
|
+
|
59
|
+
desc "Generate RCov test coverage and open in your browser"
|
60
|
+
task :coverage do
|
61
|
+
require 'rcov'
|
62
|
+
sh "rm -fr coverage"
|
63
|
+
sh "rcov test/test_*.rb"
|
64
|
+
sh "open coverage/index.html"
|
65
|
+
end
|
66
|
+
|
67
|
+
require 'rake/rdoctask'
|
68
|
+
Rake::RDocTask.new do |rdoc|
|
69
|
+
rdoc.rdoc_dir = 'rdoc'
|
70
|
+
rdoc.title = "#{name} #{version}"
|
71
|
+
rdoc.rdoc_files.include('README*')
|
72
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
73
|
+
end
|
74
|
+
|
75
|
+
desc "Open an irb session preloaded with this library"
|
76
|
+
task :console do
|
77
|
+
sh "irb -rubygems -r ./lib/guard/#{shortname}.rb"
|
78
|
+
end
|
79
|
+
|
80
|
+
#############################################################################
|
81
|
+
#
|
82
|
+
# Custom tasks (add your own tasks here)
|
83
|
+
#
|
84
|
+
#############################################################################
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
#############################################################################
|
89
|
+
#
|
90
|
+
# Packaging tasks
|
91
|
+
#
|
92
|
+
#############################################################################
|
93
|
+
|
94
|
+
desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
|
95
|
+
task :release => :build do
|
96
|
+
unless `git branch` =~ /^\* master$/
|
97
|
+
puts "You must be on the master branch to release!"
|
98
|
+
exit!
|
99
|
+
end
|
100
|
+
sh "git commit --allow-empty -a -m 'Release #{version}'"
|
101
|
+
sh "git tag v#{version}"
|
102
|
+
sh "git push origin master"
|
103
|
+
sh "git push origin v#{version}"
|
104
|
+
sh "gem push pkg/#{name}-#{version}.gem"
|
105
|
+
end
|
106
|
+
|
107
|
+
desc "Build #{gem_file} into the pkg directory"
|
108
|
+
task :build => :gemspec do
|
109
|
+
sh "mkdir -p pkg"
|
110
|
+
sh "gem build #{gemspec_file}"
|
111
|
+
sh "mv #{gem_file} pkg"
|
112
|
+
end
|
113
|
+
|
114
|
+
desc "Generate #{gemspec_file}"
|
115
|
+
task :gemspec => :validate do
|
116
|
+
# read spec file and split out manifest section
|
117
|
+
spec = File.read(gemspec_file)
|
118
|
+
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
119
|
+
|
120
|
+
# replace name version and date
|
121
|
+
replace_header(head, :name)
|
122
|
+
replace_header(head, :version)
|
123
|
+
replace_header(head, :date)
|
124
|
+
#comment this out if your rubyforge_project has a different name
|
125
|
+
#replace_header(head, :rubyforge_project)
|
126
|
+
|
127
|
+
# determine file list from git ls-files
|
128
|
+
files = `git ls-files`.
|
129
|
+
split("\n").
|
130
|
+
sort.
|
131
|
+
reject { |file| file =~ /^\./ }.
|
132
|
+
reject { |file| file =~ /^(rdoc|pkg)/ }.
|
133
|
+
map { |file| " #{file}" }.
|
134
|
+
join("\n")
|
135
|
+
|
136
|
+
# piece file back together and write
|
137
|
+
manifest = " s.files = %w[\n#{files}\n ]\n"
|
138
|
+
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
|
139
|
+
File.open(gemspec_file, 'w') { |io| io.write(spec) }
|
140
|
+
puts "Updated #{gemspec_file}"
|
141
|
+
end
|
142
|
+
|
143
|
+
desc "Validate #{gemspec_file}"
|
144
|
+
task :validate do
|
145
|
+
libfiles = Dir['lib/guard/*'] - ["lib/guard/#{shortname}.rb", "lib/guard/#{shortname}"]
|
146
|
+
unless libfiles.empty?
|
147
|
+
puts "Directory `lib/guard` should only contain a `#{shortname}.rb` file and `#{shortname}` dir."
|
148
|
+
exit!
|
149
|
+
end
|
150
|
+
unless Dir['VERSION*'].empty?
|
151
|
+
puts "A `VERSION` file at root level violates Gem best practices."
|
152
|
+
exit!
|
153
|
+
end
|
154
|
+
end
|
data/guard-knife.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
## http://docs.rubygems.org/read/chapter/20
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.specification_version = 2 if s.respond_to? :specification_version=
|
4
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
5
|
+
s.rubygems_version = '1.3.5'
|
6
|
+
|
7
|
+
s.name = 'guard-knife'
|
8
|
+
s.version = '0.0.1'
|
9
|
+
s.date = '2012-03-09'
|
10
|
+
s.rubyforge_project = ''
|
11
|
+
|
12
|
+
s.summary = "Guard for Chef using knife"
|
13
|
+
s.description = "Guard for Chef using knife to upload files"
|
14
|
+
|
15
|
+
s.authors = ["Nikolay Sturm"]
|
16
|
+
s.email = 'github@erisiandiscord.de'
|
17
|
+
s.homepage = 'https://github.com/nistude/guard-knife'
|
18
|
+
|
19
|
+
s.require_paths = %w[lib]
|
20
|
+
|
21
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
22
|
+
s.extra_rdoc_files = %w[README.md LICENSE]
|
23
|
+
|
24
|
+
s.add_dependency('guard')
|
25
|
+
s.add_dependency('chef', '>= 0.10')
|
26
|
+
|
27
|
+
#s.add_development_dependency('DEVDEPNAME', [">= 1.1.0", "< 2.0.0"])
|
28
|
+
|
29
|
+
# = MANIFEST =
|
30
|
+
s.files = %w[
|
31
|
+
LICENSE
|
32
|
+
README.md
|
33
|
+
Rakefile
|
34
|
+
guard-knife.gemspec
|
35
|
+
lib/guard/knife.rb
|
36
|
+
lib/guard/knife/templates/Guardfile
|
37
|
+
]
|
38
|
+
# = MANIFEST =
|
39
|
+
|
40
|
+
#s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
|
41
|
+
end
|
data/lib/guard/knife.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'guard'
|
2
|
+
require 'guard/guard'
|
3
|
+
|
4
|
+
module Guard
|
5
|
+
class Knife < Guard
|
6
|
+
VERSION = '0.0.1'
|
7
|
+
|
8
|
+
# Initialize a Guard.
|
9
|
+
# @param [Array<Guard::Watcher>] watchers the Guard file watchers
|
10
|
+
# @param [Hash] options the custom Guard options
|
11
|
+
def initialize(watchers = [], options = {})
|
12
|
+
super
|
13
|
+
@options = {
|
14
|
+
:config => '~/.chef/knife.rb'
|
15
|
+
}.update(options)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Call once when Guard starts. Please override initialize method to init stuff.
|
19
|
+
# @raise [:task_has_failed] when start has failed
|
20
|
+
def start
|
21
|
+
end
|
22
|
+
|
23
|
+
# Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
|
24
|
+
# @raise [:task_has_failed] when stop has failed
|
25
|
+
def stop
|
26
|
+
end
|
27
|
+
|
28
|
+
# Called when `reload|r|z + enter` is pressed.
|
29
|
+
# This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
|
30
|
+
# @raise [:task_has_failed] when reload has failed
|
31
|
+
def reload
|
32
|
+
end
|
33
|
+
|
34
|
+
# Called when just `enter` is pressed
|
35
|
+
# This method should be principally used for long action like running all specs/tests/...
|
36
|
+
# @raise [:task_has_failed] when run_all has failed
|
37
|
+
def run_all
|
38
|
+
end
|
39
|
+
|
40
|
+
# Called on file(s) modifications that the Guard watches.
|
41
|
+
# @param [Array<String>] paths the changes files or paths
|
42
|
+
# @raise [:task_has_failed] when run_on_change has failed
|
43
|
+
def run_on_change(paths)
|
44
|
+
paths.each do |path|
|
45
|
+
next if path.match(/\.swp$/) # vim swap file
|
46
|
+
|
47
|
+
upload(path)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Called on file(s) deletions that the Guard watches.
|
52
|
+
# @param [Array<String>] paths the deleted files or paths
|
53
|
+
# @raise [:task_has_failed] when run_on_change has failed
|
54
|
+
def run_on_deletion(paths)
|
55
|
+
end
|
56
|
+
|
57
|
+
def upload(path)
|
58
|
+
if path.match(/^cookbooks\/([^\/]*)\//)
|
59
|
+
upload_cookbook($1)
|
60
|
+
elsif path.match(/^data_bags\/(.*)\/(.*)$/)
|
61
|
+
data_bag = $1
|
62
|
+
item = $2
|
63
|
+
upload_databag(data_bag, item)
|
64
|
+
elsif path.match(/^(environments\/.*\.rb)$/)
|
65
|
+
upload_environment($1)
|
66
|
+
elsif path.match(/^(roles\/.*.rb)$/)
|
67
|
+
upload_role($1)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def knife_options
|
72
|
+
options = ''
|
73
|
+
@options.each do |key, value|
|
74
|
+
case key
|
75
|
+
when :config
|
76
|
+
options += "-c #{value} "
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
options
|
81
|
+
end
|
82
|
+
|
83
|
+
def upload_cookbook(cookbook)
|
84
|
+
system("knife cookbook upload #{cookbook} #{knife_options}")
|
85
|
+
end
|
86
|
+
|
87
|
+
def upload_databag(data_bag, item)
|
88
|
+
system("knife data bag from file #{data_bag} #{item} #{knife_options}")
|
89
|
+
end
|
90
|
+
|
91
|
+
def upload_environment(environment)
|
92
|
+
system("knife environment from file #{environment} #{knife_options}")
|
93
|
+
end
|
94
|
+
|
95
|
+
def upload_role(role)
|
96
|
+
system("knife role from file #{role} #{knife_options}")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guard-knife
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Nikolay Sturm
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-03-09 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: guard
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: chef
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 31
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
- 10
|
46
|
+
version: "0.10"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
description: Guard for Chef using knife to upload files
|
50
|
+
email: github@erisiandiscord.de
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files:
|
56
|
+
- README.md
|
57
|
+
- LICENSE
|
58
|
+
files:
|
59
|
+
- LICENSE
|
60
|
+
- README.md
|
61
|
+
- Rakefile
|
62
|
+
- guard-knife.gemspec
|
63
|
+
- lib/guard/knife.rb
|
64
|
+
- lib/guard/knife/templates/Guardfile
|
65
|
+
homepage: https://github.com/nistude/guard-knife
|
66
|
+
licenses: []
|
67
|
+
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- --charset=UTF-8
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
requirements: []
|
92
|
+
|
93
|
+
rubyforge_project: ""
|
94
|
+
rubygems_version: 1.8.17
|
95
|
+
signing_key:
|
96
|
+
specification_version: 2
|
97
|
+
summary: Guard for Chef using knife
|
98
|
+
test_files: []
|
99
|
+
|