clc-promote 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/promote.rb +3 -1
- data/lib/promote/config.rb +23 -0
- data/lib/promote/rake_tasks.rb +15 -2
- data/lib/promote/uploader.rb +47 -0
- data/lib/promote/versioner.rb +13 -24
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe800d49579f78d5f25faf255f23d48415f153c0
|
4
|
+
data.tar.gz: bf16f163d2d0e64d93988d66164e4acdaacc9b81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95aab19d63d79dddfbe748a8ed13f295a2d13951740b8c28ecfb780c1cd58ff2c04ecf7f25a6ed522545e197cb25dc8d2123cb80bf0b662cefd335578fdf996c
|
7
|
+
data.tar.gz: d578a8370523bf53ca4b32bec9c4167b6b44b760434f56d2cfb86440cedf723d05f9677e8a4db90ccc5f59d84b15d33564bd65666d9d28ba63c4d445e800b955
|
data/lib/promote.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Promote
|
2
|
+
class Config
|
3
|
+
def initialize(options = {})
|
4
|
+
options.each do |k, v|
|
5
|
+
self.send("#{k}=", v) if self.respond_to?(k)
|
6
|
+
end
|
7
|
+
self.repo_root ||= Dir.pwd
|
8
|
+
self.cookbook_directory ||= File.join(repo_root, "cookbooks")
|
9
|
+
self.environment_directory ||= File.join(repo_root, "environments")
|
10
|
+
self.data_bag_directory ||= File.join(repo_root, "data_bags")
|
11
|
+
self.temp_directory ||= "/tmp/promote"
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_accessor :repo_root
|
15
|
+
attr_accessor :cookbook_directory
|
16
|
+
attr_accessor :environment_directory
|
17
|
+
attr_accessor :data_bag_directory
|
18
|
+
attr_accessor :temp_directory
|
19
|
+
attr_accessor :node_name
|
20
|
+
attr_accessor :client_key
|
21
|
+
attr_accessor :chef_server_url
|
22
|
+
end
|
23
|
+
end
|
data/lib/promote/rake_tasks.rb
CHANGED
@@ -5,8 +5,10 @@ module Promote
|
|
5
5
|
|
6
6
|
class RakeTasks < ::Rake::TaskLib
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
|
8
|
+
def initialize(config)
|
9
|
+
config = Config.new(config) if config.is_a?(Hash)
|
10
|
+
config = Config.new({ :repo_root => config }) if config.is_a?(String)
|
11
|
+
@versioner = Versioner.new(config)
|
10
12
|
yield self if block_given?
|
11
13
|
define_version_cookbook
|
12
14
|
define_version_cookbooks
|
@@ -79,5 +81,16 @@ module Promote
|
|
79
81
|
end
|
80
82
|
end
|
81
83
|
|
84
|
+
def define_upload_cookbooks
|
85
|
+
namespace "Promote" do
|
86
|
+
desc "Upload all cookbooks to chef server"
|
87
|
+
task "upload_cookbooks" do
|
88
|
+
@uploader.upload_cookbooks.each do |result|
|
89
|
+
#puts "Versioned cookbook: #{result[:cookbook]} v#{result[:version]}"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
82
95
|
end
|
83
96
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'chef'
|
2
|
+
require 'chef/knife/cookbook_upload'
|
3
|
+
|
4
|
+
module Promote
|
5
|
+
class Uploader
|
6
|
+
def initialize(config)
|
7
|
+
@config = config
|
8
|
+
validate_config
|
9
|
+
end
|
10
|
+
|
11
|
+
def upload_cookbook(cookbook_name)
|
12
|
+
berks_name = File.join(config.cookbook_directory, cookbook_name, "Berksfile")
|
13
|
+
upload_dir = config.cookbook_directory
|
14
|
+
if File.exist?(berks_name)
|
15
|
+
FileUtils.rm_rf(config.temp_directory) if Dir.exist?(config.temp_directory)
|
16
|
+
berksfile = Berkshelf::Berksfile.from_file(berks_name)
|
17
|
+
berksfile.vendor(config.temp_directory)
|
18
|
+
upload_dir = config.temp_directory
|
19
|
+
end
|
20
|
+
|
21
|
+
knife = Chef::Knife::CookbookUpload.new()
|
22
|
+
Chef::Config.reset
|
23
|
+
Chef::Config[:client_key] = config.client_key
|
24
|
+
Chef::Config[:chef_server_url] = config.chef_server_url
|
25
|
+
Chef::Config[:node_name] = config.node_name
|
26
|
+
knife.config[:all] = true
|
27
|
+
knife.config[:cookbook_path] = upload_dir
|
28
|
+
knife.run
|
29
|
+
end
|
30
|
+
|
31
|
+
attr_accessor :config
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def validate_config
|
36
|
+
required_keys = [:client_key, :chef_server_url, :node_name]
|
37
|
+
missing_keys = []
|
38
|
+
required_keys.each do |key|
|
39
|
+
missing_keys << key if config.send(key).nil?
|
40
|
+
end
|
41
|
+
|
42
|
+
unless missing_keys.empty?
|
43
|
+
raise "missing required config options: #{missing_keys.join(', ')}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/promote/versioner.rb
CHANGED
@@ -4,16 +4,16 @@ require 'json'
|
|
4
4
|
|
5
5
|
module Promote
|
6
6
|
class Versioner
|
7
|
-
def initialize(
|
8
|
-
@
|
9
|
-
@git = Git.open(git_root(repo_root))
|
7
|
+
def initialize(config = Config.new)
|
8
|
+
@config = config
|
9
|
+
@git = Git.open(git_root(config.repo_root))
|
10
10
|
version_tags = @git.tags.select { |t| t.name[/^[0-9\.]+/] }
|
11
11
|
@current_tag = version_tags[-1]
|
12
12
|
@sha1 = @git.log(10000).between(current_tag.sha).first.sha
|
13
13
|
end
|
14
14
|
|
15
15
|
def version_cookbook(cookbook_name)
|
16
|
-
dir = File.join(cookbook_directory, cookbook_name)
|
16
|
+
dir = File.join(config.cookbook_directory, cookbook_name)
|
17
17
|
cookbook_name = File.basename(dir)
|
18
18
|
version = version_number(current_tag, dir)
|
19
19
|
metadata_file = File.join(dir, "metadata.rb")
|
@@ -35,7 +35,7 @@ module Promote
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def version_cookbooks
|
38
|
-
cookbooks = Dir.glob(File.join(cookbook_directory, "*"))
|
38
|
+
cookbooks = Dir.glob(File.join(config.cookbook_directory, "*"))
|
39
39
|
results = []
|
40
40
|
cookbooks.each do |file|
|
41
41
|
cookbook = File.basename(file)
|
@@ -45,7 +45,7 @@ module Promote
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
cookbooks.each do |cookbook|
|
48
|
-
berks_name = File.join(cookbook_directory, File.basename(cookbook), "Berksfile")
|
48
|
+
berks_name = File.join(config.cookbook_directory, File.basename(cookbook), "Berksfile")
|
49
49
|
if File.exist?(berks_name)
|
50
50
|
berksfile = Berkshelf::Berksfile.from_file(berks_name)
|
51
51
|
berksfile.install
|
@@ -54,15 +54,14 @@ module Promote
|
|
54
54
|
results
|
55
55
|
end
|
56
56
|
|
57
|
-
def version_data_bag(
|
58
|
-
version_json
|
57
|
+
def version_data_bag(data_bag_path)
|
58
|
+
version_json File.dirname(data_bag_path), File.basename(data_bag_path, File.extname(data_bag_path))
|
59
59
|
end
|
60
60
|
|
61
61
|
def version_data_bags
|
62
62
|
results = []
|
63
|
-
Dir.glob(File.join(data_bag_directory, "**", "*.json")).each do |file|
|
64
|
-
|
65
|
-
result = version_data_bag(data_bag)
|
63
|
+
Dir.glob(File.join(config.data_bag_directory, "**", "*.json")).each do |file|
|
64
|
+
result = version_data_bag(file)
|
66
65
|
if !result.nil?
|
67
66
|
results << result
|
68
67
|
end
|
@@ -71,14 +70,14 @@ module Promote
|
|
71
70
|
end
|
72
71
|
|
73
72
|
def version_environment(environment_name)
|
74
|
-
version_json environment_directory, environment_name do | content |
|
73
|
+
version_json config.environment_directory, environment_name do | content |
|
75
74
|
content['override_attributes']
|
76
75
|
end
|
77
76
|
end
|
78
77
|
|
79
78
|
def version_environments
|
80
79
|
results = []
|
81
|
-
Dir.glob(File.join(environment_directory, "*.json")).each do |file|
|
80
|
+
Dir.glob(File.join(config.environment_directory, "*.json")).each do |file|
|
82
81
|
environment = File.basename(file ,File.extname(file))
|
83
82
|
result = version_environment(environment)
|
84
83
|
if !result.nil?
|
@@ -88,17 +87,7 @@ module Promote
|
|
88
87
|
results
|
89
88
|
end
|
90
89
|
|
91
|
-
|
92
|
-
File.join(@repo_root, "cookbooks")
|
93
|
-
end
|
94
|
-
|
95
|
-
def environment_directory
|
96
|
-
File.join(@repo_root, "environments")
|
97
|
-
end
|
98
|
-
|
99
|
-
def data_bag_directory
|
100
|
-
File.join(@repo_root, "data_bags/datacenters")
|
101
|
-
end
|
90
|
+
attr_accessor :config
|
102
91
|
|
103
92
|
private
|
104
93
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clc-promote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CenturyLink Cloud
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: knife-spork
|
@@ -119,7 +119,9 @@ extra_rdoc_files:
|
|
119
119
|
files:
|
120
120
|
- README.md
|
121
121
|
- lib/promote.rb
|
122
|
+
- lib/promote/config.rb
|
122
123
|
- lib/promote/rake_tasks.rb
|
124
|
+
- lib/promote/uploader.rb
|
123
125
|
- lib/promote/versioner.rb
|
124
126
|
homepage: https://github.com/tier3/DevOps/gems/clc-promote
|
125
127
|
licenses: []
|