knife-pinnings 1.1.1 → 1.2.0
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/.rubocop.yml +1 -1
- data/CHANGELOG.md +8 -0
- data/README.md +23 -15
- data/knife-pinnings.gemspec +4 -3
- data/lib/chef/knife/pinnings_compare.rb +1 -1
- data/lib/chef/knife/pinnings_list.rb +1 -1
- data/lib/chef/knife/pinnings_mixin.rb +3 -3
- data/lib/chef/knife/pinnings_promote.rb +1 -1
- data/lib/chef/knife/pinnings_set.rb +59 -0
- data/lib/chef/knife/pinnings_wipe.rb +3 -4
- data/lib/knife-pinnings/version.rb +1 -1
- metadata +23 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6a2699df0d80bdc794dd6fa4dd7ab5cd68b348b2
|
|
4
|
+
data.tar.gz: 028a425d3c3a9b10636d3e2b05a2f15d7869044e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 480d615869421a930ffd2d62dbb467004ec02964f2603d748733c27c990b7fe55440ed055413b141d8c81f549b550ec634047356b66671bf837e6b2a5793bd59
|
|
7
|
+
data.tar.gz: 87642ab2bddcc41a0d010a69b31adbcaf6ca26ec7f210e04077c4aac2db6505023ecfc13d6131d935c6c7cea3ead5b93a5351965447856e020997ab313df24e6
|
data/.rubocop.yml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# In these days of widescreen TV and big monitors
|
|
2
2
|
# a line length of 80 sounds a bit unreasonable
|
|
3
3
|
Metrics/LineLength:
|
|
4
|
-
Max:
|
|
4
|
+
Max: 150
|
|
5
5
|
|
|
6
6
|
# Actually, I don't like hash rockets as they look untidy
|
|
7
7
|
# If Rubocop doesn't use them in the config file, why should I ?
|
data/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,14 @@ Given a version xx.yy.zz
|
|
|
9
9
|
* A change in yy is a non-breaking change (usually a new feature)
|
|
10
10
|
* A change in zz is a major change which likely breaks stuff that depends on us.
|
|
11
11
|
|
|
12
|
+
## 1.1.2
|
|
13
|
+
* Use variable column spacing in grid (reduces width of grid)
|
|
14
|
+
|
|
15
|
+
## 1.1.1
|
|
16
|
+
* Fix documentation to show regex options
|
|
17
|
+
* Fix regex processing for display in pinnings wipe
|
|
18
|
+
* Fix banner text to display regex options
|
|
19
|
+
|
|
12
20
|
## 1.1.0
|
|
13
21
|
* Improved performance by using search instead of iteration to get environment detail.
|
|
14
22
|
* Added support for comparing pinnings between environments with color highlighting
|
data/README.md
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
# knife-pinnings
|
|
2
2
|
|
|
3
|
-
[](http://badge.fury.io/rb/knife-pinnings)
|
|
4
|
-
|
|
5
3
|
This gem extends Chef's knife command to manage version pinnings in your Chef environments
|
|
6
4
|
|
|
5
|
+
* Set a cookbook pinning explicitly or by using metadata.rb
|
|
7
6
|
* Get a list of all pinnings in all environments
|
|
8
7
|
* Compare pinnings across multiple environments
|
|
9
8
|
* Promote pinnings between environments
|
|
@@ -16,17 +15,26 @@ Pretty standard stuff....
|
|
|
16
15
|
|
|
17
16
|
## Usage
|
|
18
17
|
|
|
19
|
-
A lot of
|
|
18
|
+
A lot of knife-pinnings commands use ruby's regular expressions flexible filtering.
|
|
19
|
+
|
|
20
|
+
* You can learn about regular expressions here <http://www.tutorialspoint.com/ruby/ruby_regular_expressions.htm>
|
|
21
|
+
* You can try out regular expressions in this editor <http://rubular.com>
|
|
22
|
+
* Wildcards in regular expressions may need to be wrapped in single quotes to hide them from shell globbing.
|
|
23
|
+
|
|
24
|
+
### Set pinnings
|
|
25
|
+
To explicitly specify the cookbook name and version
|
|
26
|
+
|
|
27
|
+
$ knife pinnings set <environment> <cookbook> <version>
|
|
20
28
|
|
|
21
|
-
|
|
22
|
-
* You can learn about ruby REGEX here <http://www.tutorialspoint.com/ruby/ruby_regular_expressions.htm>
|
|
23
|
-
* REGEX with wildcards may need to be wrapped in single quotes to hide them from the shell
|
|
29
|
+
To take the name and version from the metadata.rb in the current directory use
|
|
24
30
|
|
|
25
|
-
|
|
31
|
+
$ knife pinnings set <environment>
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### List pinnings
|
|
26
35
|
In general you can use
|
|
27
|
-
|
|
28
|
-
$ knife pinnings list ['environment_regex'] ['cookbook_regex']
|
|
29
|
-
```
|
|
36
|
+
|
|
37
|
+
$ knife pinnings list ['environment_regex'] ['cookbook_regex']
|
|
30
38
|
|
|
31
39
|
To find cookbooks begining with app_ in any environment
|
|
32
40
|
|
|
@@ -40,8 +48,8 @@ To find cookbooks in acceptance or production with names beginning with app_
|
|
|
40
48
|
|
|
41
49
|
$ knife pinnings list '(^accept.*|^production$)' '^app_.*'
|
|
42
50
|
|
|
43
|
-
###
|
|
44
|
-
To get a color coded comparison grid showing
|
|
51
|
+
### Compare pinnings
|
|
52
|
+
To get a color coded comparison grid showing what's pinned in different environments
|
|
45
53
|
|
|
46
54
|
knife pinnings compare ['environmnet_regex'] ['cookbook_regex']
|
|
47
55
|
|
|
@@ -49,14 +57,14 @@ To compare the versions of skunk app cookbooks in dev, acceptance and production
|
|
|
49
57
|
|
|
50
58
|
knife pinnings compare '(^dev$|^acceptance$|^production$)' '^skunk_app.*'
|
|
51
59
|
|
|
52
|
-
###
|
|
53
|
-
Promote pinnings from one environment to another.
|
|
60
|
+
### Promote pinnings
|
|
61
|
+
Promote pinnings from one environment to another (eg. from acceptance to pre-prod).
|
|
54
62
|
|
|
55
63
|
knife pinnings promote ENV1 ENV2 ['cookbook_regex']
|
|
56
64
|
|
|
57
65
|
NOTE: Pinnings which are missing in the source environment will NOT be deleted from the target.
|
|
58
66
|
|
|
59
|
-
###
|
|
67
|
+
### Wipe pinnings
|
|
60
68
|
|
|
61
69
|
To wipe pinnings in a single environment
|
|
62
70
|
|
data/knife-pinnings.gemspec
CHANGED
|
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
|
8
8
|
spec.version = Knife::Pinnings::VERSION
|
|
9
9
|
spec.authors = ['Richard Nixon']
|
|
10
10
|
spec.email = ['richard.nixon@btinternet.com']
|
|
11
|
-
spec.summary = '
|
|
12
|
-
spec.description = '
|
|
11
|
+
spec.summary = 'Chef knife plugin to set, list, compare, copy and delete cookbook pinnings across environments'
|
|
12
|
+
spec.description = 'Chef knife plugin to set, list, compare, copy and delete cookbook pinnings across environments'
|
|
13
13
|
spec.homepage = 'https://github.com/trickyearlobe/knife-pinnings'
|
|
14
14
|
spec.license = 'Apache 2.0'
|
|
15
15
|
|
|
@@ -24,8 +24,9 @@ Gem::Specification.new do |spec|
|
|
|
24
24
|
spec.add_development_dependency 'rspec'
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
|
26
26
|
spec.add_development_dependency 'rake', '~> 10.0'
|
|
27
|
+
spec.add_development_dependency 'rubocop'
|
|
27
28
|
spec.add_development_dependency 'guard'
|
|
28
29
|
spec.add_development_dependency 'guard-rake'
|
|
29
30
|
spec.add_development_dependency 'guard-shell'
|
|
30
|
-
spec.add_development_dependency 'rubocop'
|
|
31
|
+
spec.add_development_dependency 'guard-rubocop'
|
|
31
32
|
end
|
|
@@ -17,7 +17,7 @@ class Chef
|
|
|
17
17
|
# This class implements knife pinnings list ['environment_regex'] ['cookbook_regex']
|
|
18
18
|
class PinningsCompare < Chef::Knife
|
|
19
19
|
require 'chef/knife/pinnings_mixin'
|
|
20
|
-
banner
|
|
20
|
+
banner 'knife pinnings compare [ENV_REGEX] [COOKBOOK_REGEX]'
|
|
21
21
|
|
|
22
22
|
def run
|
|
23
23
|
environment_regex = "#{name_args[0] || '.*'}"
|
|
@@ -17,7 +17,7 @@ class Chef
|
|
|
17
17
|
# This class implements knife pinnings list ['environment_regex'] ['cookbook_regex']
|
|
18
18
|
class PinningsList < Chef::Knife
|
|
19
19
|
require 'chef/knife/pinnings_mixin'
|
|
20
|
-
banner
|
|
20
|
+
banner 'knife pinnings list [ENVIRONMENT_REGEX] [COOKBOOK_REGEX]'
|
|
21
21
|
|
|
22
22
|
def run
|
|
23
23
|
environment_regex = "#{name_args[0] || '.*'}"
|
|
@@ -17,7 +17,7 @@ def version_strip(version_string)
|
|
|
17
17
|
version_string.match(/()[0-9]*\.[0-9]*\.[0-9]*/).to_s
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
# This method takes an array of environments and filters
|
|
20
|
+
# This method takes an array of environments and filters them using a REGEX
|
|
21
21
|
def filter_environments(environments, environment_regex)
|
|
22
22
|
filtered_environments = []
|
|
23
23
|
environments.each do |name, environment|
|
|
@@ -39,7 +39,7 @@ def display_pinnings_table(environments, cookbook_regex)
|
|
|
39
39
|
ui.msg(
|
|
40
40
|
ui.list(
|
|
41
41
|
build_pinnings_table(environments, cookbook_regex),
|
|
42
|
-
:
|
|
42
|
+
:uneven_columns_across,
|
|
43
43
|
environments.length + 1
|
|
44
44
|
)
|
|
45
45
|
)
|
|
@@ -100,5 +100,5 @@ def display_cookbooks(cookbooks, cookbook_regex)
|
|
|
100
100
|
filter_cookbooks(cookbooks, cookbook_regex).each do |name, version|
|
|
101
101
|
rows << " #{name}" << version_strip(version)
|
|
102
102
|
end
|
|
103
|
-
ui.msg(ui.list(rows, :
|
|
103
|
+
ui.msg(ui.list(rows, :uneven_columns_across, 2)) if rows.length > 0
|
|
104
104
|
end
|
|
@@ -17,7 +17,7 @@ class Chef
|
|
|
17
17
|
# This class copies cookbook pinnings between environments
|
|
18
18
|
class PinningsPromote < Chef::Knife
|
|
19
19
|
require 'chef/knife/pinnings_mixin'
|
|
20
|
-
banner
|
|
20
|
+
banner 'knife pinnings promote SOURCE_ENV TARGET_ENV [COOKBOOK_REGEX]'
|
|
21
21
|
|
|
22
22
|
def run
|
|
23
23
|
unless name_args.length > 1
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Copyright 2015 Richard Nixon
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
class Chef
|
|
16
|
+
class Knife
|
|
17
|
+
# This class implements knife pinnings list ['environment_regex'] ['cookbook_regex']
|
|
18
|
+
class PinningsSet < Chef::Knife
|
|
19
|
+
banner 'knife pinnings set ENVIRONMENT [COOKBOOK VERSION]'
|
|
20
|
+
|
|
21
|
+
def run
|
|
22
|
+
case name_args.length
|
|
23
|
+
when 1 # Just environment was specified so get name/version from metadata
|
|
24
|
+
@metadata = Chef::Cookbook::Metadata.new
|
|
25
|
+
@metadata.from_file(File.join(Dir.pwd,'metadata.rb'))
|
|
26
|
+
@cookbook_name = @metadata.name
|
|
27
|
+
@cookbook_version = @metadata.version
|
|
28
|
+
when 3 # Environment, Cookbook and Version explicitly specified so use those
|
|
29
|
+
@cookbook_name = name_args[1]
|
|
30
|
+
@cookbook_version = name_args[2]
|
|
31
|
+
else
|
|
32
|
+
ui.fatal('You must specify ENVIRONMENT (to take COOKBOOK/VERSION from matadata.rb) or ENVIRONMENT COOKBOOK VERSION')
|
|
33
|
+
exit 255
|
|
34
|
+
end
|
|
35
|
+
@environment_name = name_args[0]
|
|
36
|
+
@environment = Environment.load(@environment_name)
|
|
37
|
+
|
|
38
|
+
cookbook_data = rest.get_rest("/cookbooks/#{@cookbook_name}").to_hash
|
|
39
|
+
cookbook_version_exists = false
|
|
40
|
+
cookbook_data[@cookbook_name]['versions'].each do |item|
|
|
41
|
+
cookbook_version_exists = true if item['version'] == @cookbook_version
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
unless cookbook_version_exists
|
|
45
|
+
ui.fatal("Cookbook #{@cookbook_name} version #{@cookbook_version} is not on Chef server. Cannot pin in #{@environment_name}")
|
|
46
|
+
exit 127
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
if @environment.cookbook_versions[@cookbook_name]
|
|
50
|
+
ui.info("Existing pinning for #{@cookbook_name} in #{@environment_name } #{@environment.cookbook_versions[@cookbook_name]}")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
ui.info("Pinning #{@cookbook_name} to version #{@cookbook_version} in #{@environment_name}")
|
|
54
|
+
@environment.cookbook_versions[@cookbook_name] = "= #{@cookbook_version}"
|
|
55
|
+
@environment.save
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -17,7 +17,7 @@ class Chef
|
|
|
17
17
|
# This class implements knife pinnings list ['environment_regex'] ['cookbook_regex']
|
|
18
18
|
class PinningsWipe < Chef::Knife
|
|
19
19
|
require 'chef/knife/pinnings_mixin'
|
|
20
|
-
banner
|
|
20
|
+
banner 'knife pinnings wipe ENVIRONMENT [COOKBOOK_REGEX]'
|
|
21
21
|
|
|
22
22
|
def run
|
|
23
23
|
if name_args.length < 1
|
|
@@ -31,17 +31,16 @@ class Chef
|
|
|
31
31
|
ui.msg('')
|
|
32
32
|
ui.confirm("Do you want to wipe cookbooks in #{environment.name}")
|
|
33
33
|
ui.msg('')
|
|
34
|
-
wipe(environment,cookbook_regex)
|
|
34
|
+
wipe(environment, cookbook_regex)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def wipe(environment, cookbook_regex)
|
|
38
|
-
environment.cookbook_versions.delete_if do |name,
|
|
38
|
+
environment.cookbook_versions.delete_if do |name, _|
|
|
39
39
|
name =~ /#{cookbook_regex}/
|
|
40
40
|
end
|
|
41
41
|
environment.save
|
|
42
42
|
ui.msg('Done')
|
|
43
43
|
end
|
|
44
|
-
|
|
45
44
|
end
|
|
46
45
|
end
|
|
47
46
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: knife-pinnings
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Richard Nixon
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-
|
|
11
|
+
date: 2015-04-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: chef
|
|
@@ -66,6 +66,20 @@ dependencies:
|
|
|
66
66
|
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
68
|
version: '10.0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rubocop
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
69
83
|
- !ruby/object:Gem::Dependency
|
|
70
84
|
name: guard
|
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -109,7 +123,7 @@ dependencies:
|
|
|
109
123
|
- !ruby/object:Gem::Version
|
|
110
124
|
version: '0'
|
|
111
125
|
- !ruby/object:Gem::Dependency
|
|
112
|
-
name: rubocop
|
|
126
|
+
name: guard-rubocop
|
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
|
114
128
|
requirements:
|
|
115
129
|
- - ">="
|
|
@@ -122,8 +136,8 @@ dependencies:
|
|
|
122
136
|
- - ">="
|
|
123
137
|
- !ruby/object:Gem::Version
|
|
124
138
|
version: '0'
|
|
125
|
-
description:
|
|
126
|
-
|
|
139
|
+
description: Chef knife plugin to set, list, compare, copy and delete cookbook pinnings
|
|
140
|
+
across environments
|
|
127
141
|
email:
|
|
128
142
|
- richard.nixon@btinternet.com
|
|
129
143
|
executables: []
|
|
@@ -143,6 +157,7 @@ files:
|
|
|
143
157
|
- lib/chef/knife/pinnings_list.rb
|
|
144
158
|
- lib/chef/knife/pinnings_mixin.rb
|
|
145
159
|
- lib/chef/knife/pinnings_promote.rb
|
|
160
|
+
- lib/chef/knife/pinnings_set.rb
|
|
146
161
|
- lib/chef/knife/pinnings_wipe.rb
|
|
147
162
|
- lib/knife-pinnings/version.rb
|
|
148
163
|
homepage: https://github.com/trickyearlobe/knife-pinnings
|
|
@@ -165,10 +180,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
165
180
|
version: '0'
|
|
166
181
|
requirements: []
|
|
167
182
|
rubyforge_project:
|
|
168
|
-
rubygems_version: 2.4.
|
|
183
|
+
rubygems_version: 2.4.4
|
|
169
184
|
signing_key:
|
|
170
185
|
specification_version: 4
|
|
171
|
-
summary:
|
|
172
|
-
environments
|
|
186
|
+
summary: Chef knife plugin to set, list, compare, copy and delete cookbook pinnings
|
|
187
|
+
across environments
|
|
173
188
|
test_files: []
|
|
174
189
|
has_rdoc:
|