knife-github 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/Chef.html +1 -1
- data/doc/Chef/Knife.html +1 -1
- data/doc/Chef/Knife/GithubBase.html +5 -5
- data/doc/Chef/Knife/GithubBaseList.html +11 -5
- data/doc/Chef/Knife/GithubClone.html +1 -1
- data/doc/Chef/Knife/GithubCompare.html +7 -7
- data/doc/Chef/Knife/GithubDeploy.html +4 -4
- data/doc/Chef/Knife/GithubDiff.html +26 -16
- data/doc/Chef/Knife/GithubList.html +2 -2
- data/doc/KnifeGithubCleanup.html +1 -1
- data/doc/KnifeGithubCleanup/GithubCleanup.html +1 -1
- data/doc/KnifeGithubSearch.html +1 -1
- data/doc/KnifeGithubSearch/GithubSearch.html +1 -1
- data/doc/_index.html +1 -1
- data/doc/file.README.html +1 -1
- data/doc/index.html +1 -1
- data/doc/top-level-namespace.html +1 -1
- data/knife-github.gemspec +5 -5
- data/lib/chef/knife/github_base.rb +49 -28
- data/lib/chef/knife/github_cleanup.rb +4 -4
- data/lib/chef/knife/github_clone.rb +13 -11
- data/lib/chef/knife/github_config.rb +11 -0
- data/lib/chef/knife/github_create.rb +236 -0
- data/lib/chef/knife/github_deploy.rb +20 -39
- data/lib/chef/knife/github_diff.rb +3 -3
- data/lib/chef/knife/github_pin.rb +138 -0
- data/lib/knife-github/version.rb +1 -1
- metadata +27 -5
@@ -0,0 +1,138 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Ian Southam (<isoutham@schubergphilis.com>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Sander Botman.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/knife'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Knife
|
23
|
+
|
24
|
+
# Pin a specific cookbook version to an environment
|
25
|
+
#
|
26
|
+
# Not specifically a github function but, sits nicely in with
|
27
|
+
# download, deploy and so on
|
28
|
+
# In some respects does duplicate some functionality that can be found
|
29
|
+
# in spork but, I want a single set of tools that would help people
|
30
|
+
# to get quickly up to speed with using chef in an industrialised environment
|
31
|
+
class GithubPin < Knife
|
32
|
+
deps do
|
33
|
+
require 'chef/knife/github_base'
|
34
|
+
require 'chef/knife/core/object_loader'
|
35
|
+
require "json"
|
36
|
+
include Chef::Knife::GithubBase
|
37
|
+
end
|
38
|
+
|
39
|
+
banner "knife github pin COOKBOOK [version] [environment]"
|
40
|
+
category "github"
|
41
|
+
|
42
|
+
def run
|
43
|
+
# The run method. The entry point into the class
|
44
|
+
|
45
|
+
# validate base options from base module.
|
46
|
+
validate_base_options
|
47
|
+
|
48
|
+
# Display information if debug mode is on.
|
49
|
+
display_debug_info
|
50
|
+
|
51
|
+
cookbook_version = nil
|
52
|
+
@cookbook_name = name_args.first unless name_args.empty?
|
53
|
+
@version = nil
|
54
|
+
@env = nil
|
55
|
+
|
56
|
+
if @cookbook_name.empty?
|
57
|
+
Chef::Log.error("You must specify a cookbook name to use this module")
|
58
|
+
end
|
59
|
+
|
60
|
+
# Parameter 2 can be a version or an environment (if version is not given) or nothing
|
61
|
+
arg1 = name_args[1] unless name_args[1].nil?
|
62
|
+
arg2 = name_args[2] unless name_args[2].nil?
|
63
|
+
|
64
|
+
if(!arg1.nil? && !arg2.nil?)
|
65
|
+
# we have a version and an environment
|
66
|
+
@version = arg1
|
67
|
+
@env = arg2
|
68
|
+
end
|
69
|
+
if(!arg1.nil? && arg2.nil?)
|
70
|
+
# we have a version or an environment
|
71
|
+
if Mixlib::Versioning.parse(arg1).nil?
|
72
|
+
@env = arg1
|
73
|
+
end
|
74
|
+
end
|
75
|
+
# If we have no version go and get it from the cookbook in the user's cookbooks path
|
76
|
+
if @version.nil?
|
77
|
+
unless @version = get_cookbook_version()
|
78
|
+
ui.error('Could not get the version of the cookbook');
|
79
|
+
exit 1;
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
@envs = list_environments()
|
84
|
+
if @env.nil?
|
85
|
+
ask_which_environment()
|
86
|
+
end
|
87
|
+
ui.confirm("Pin version #{@version} of cookbook #{@cookbook_name} in Environment #{@env}")
|
88
|
+
if @envs[@env].cookbook_versions.has_key?(@cookbook_name)
|
89
|
+
cval = @envs[@env].cookbook_versions[@cookbook_name]
|
90
|
+
if cval == @version
|
91
|
+
ui.error "#{@cookbook_name} is already pinned to version #{cval}. Nothibg to do!"
|
92
|
+
exit 1
|
93
|
+
end
|
94
|
+
end
|
95
|
+
@envs[@env].cookbook_versions[@cookbook_name] = @version
|
96
|
+
ui.info "Set version to #{@version} for environment #{@env}"
|
97
|
+
if ! File.directory? @github_tmp
|
98
|
+
Dir.mkdir(@github_tmp)
|
99
|
+
Chef::Log.debug("Creating temporary directory #{@github_tmp}")
|
100
|
+
end
|
101
|
+
File.open("#{@github_tmp}/#{@env}.json", 'w') {|f| f.write JSON.pretty_generate(@envs[@env]) }
|
102
|
+
Chef::Log.debug( "Json written to #{@github_tmp}/#{@env}.json" )
|
103
|
+
|
104
|
+
# Finally do the upload
|
105
|
+
args = ['environment', "from_file", "#{@github_tmp}/#{@env}.json" ]
|
106
|
+
upload = Chef::Knife::EnvironmentFromFile.new(args)
|
107
|
+
upload.run
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
def list_environments()
|
112
|
+
response = Hash.new
|
113
|
+
Chef::Search::Query.new.search(:environment) do |e|
|
114
|
+
response[e.name] = e unless e.nil?
|
115
|
+
end
|
116
|
+
response.delete('_default') if response.has_key?('_default');
|
117
|
+
response
|
118
|
+
end
|
119
|
+
|
120
|
+
def ask_which_environment
|
121
|
+
question = "Which environment do you wish to pin?\n"
|
122
|
+
valid_responses = {}
|
123
|
+
@envs.keys.each_with_index do |e, index|
|
124
|
+
valid_responses[(index + 1).to_s] = e
|
125
|
+
question << "#{index + 1}. #{e}\n"
|
126
|
+
end
|
127
|
+
question += "\n"
|
128
|
+
response = ask_question(question).strip
|
129
|
+
unless @env = valid_responses[response]
|
130
|
+
ui.error("'#{response}' is not a valid value.")
|
131
|
+
exit(1)
|
132
|
+
end
|
133
|
+
@env
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
data/lib/knife-github/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-github
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Sander Botman
|
9
|
+
- Ian Southam
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
+
date: 2013-11-17 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: mixlib-versioning
|
@@ -27,9 +28,26 @@ dependencies:
|
|
27
28
|
- - ! '>='
|
28
29
|
- !ruby/object:Gem::Version
|
29
30
|
version: 1.0.0
|
30
|
-
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: chef
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 10.0.0
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 10.0.0
|
47
|
+
description: Github interaction support for chef's knife cli tool
|
31
48
|
email:
|
32
49
|
- sbotman@schubergphilis.com
|
50
|
+
- isoutham@schubergphilis.com
|
33
51
|
executables: []
|
34
52
|
extensions: []
|
35
53
|
extra_rdoc_files:
|
@@ -73,13 +91,17 @@ files:
|
|
73
91
|
- lib/chef/knife/github_cleanup.rb
|
74
92
|
- lib/chef/knife/github_clone.rb
|
75
93
|
- lib/chef/knife/github_compare.rb
|
94
|
+
- lib/chef/knife/github_config.rb
|
95
|
+
- lib/chef/knife/github_create.rb
|
76
96
|
- lib/chef/knife/github_deploy.rb
|
77
97
|
- lib/chef/knife/github_diff.rb
|
78
98
|
- lib/chef/knife/github_list.rb
|
99
|
+
- lib/chef/knife/github_pin.rb
|
79
100
|
- lib/chef/knife/github_search.rb
|
80
101
|
- lib/knife-github/version.rb
|
81
102
|
homepage: https://github.com/schubergphilis/knife-github
|
82
|
-
licenses:
|
103
|
+
licenses:
|
104
|
+
- Apache 2.0
|
83
105
|
post_install_message:
|
84
106
|
rdoc_options: []
|
85
107
|
require_paths:
|
@@ -101,6 +123,6 @@ rubyforge_project:
|
|
101
123
|
rubygems_version: 1.8.25
|
102
124
|
signing_key:
|
103
125
|
specification_version: 3
|
104
|
-
summary: Github interaction support for
|
126
|
+
summary: Github interaction support for chef's knife cli tool
|
105
127
|
test_files: []
|
106
128
|
has_rdoc: false
|