clc-promote 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +2 -0
- data/lib/promote.rb +1 -0
- data/lib/promote/rake_tasks.rb +89 -0
- data/lib/promote/versioner.rb +101 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: babb452554c75dbcc1254e447c2fb77ac7485afb
|
4
|
+
data.tar.gz: 0f62a4e131785fe1decfb58dd9586df9307d9db1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c8faef1b98bedb2842a6b23351497456c7c03408f4de07a738f7e27cfd98e5835caf16c7a01377785bb40135fa68ce43b58a44923b0ad9e095d8a643cdab6292
|
7
|
+
data.tar.gz: e924f00b488674b6c59defadbac589d544d64a2588c7f647c875adef6e626a5caef25febc8f28fe28851f2cf78ab545a492e89573cdc72919760f1f55ade00bc
|
data/README.md
ADDED
data/lib/promote.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'promote/versioner'
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'promote'
|
2
|
+
require "rake/tasklib"
|
3
|
+
|
4
|
+
module Promote
|
5
|
+
|
6
|
+
class RakeTasks < ::Rake::TaskLib
|
7
|
+
|
8
|
+
def initialize(repo_root)
|
9
|
+
@versioner = Versioner.new(repo_root)
|
10
|
+
yield self if block_given?
|
11
|
+
define_version_cookbook
|
12
|
+
define_version_cookbooks
|
13
|
+
define_version_environment
|
14
|
+
define_version_environments
|
15
|
+
define_version_data_bag
|
16
|
+
define_version_data_bags
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
|
22
|
+
def define_version_cookbook
|
23
|
+
namespace "Promote" do
|
24
|
+
desc "Version a cookbook"
|
25
|
+
task "version_cookbook", :cookbook do |task, args|
|
26
|
+
@versioner.version_cookbook(args.cookbook)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def define_version_cookbooks
|
32
|
+
namespace "Promote" do
|
33
|
+
desc "Version all cookbooks"
|
34
|
+
task "version_cookbooks" do
|
35
|
+
Dir.glob(File.join(@versioner.cookbook_directory, "*")) do |file|
|
36
|
+
cookbook = File.basename(file)
|
37
|
+
puts "versioning cookbook #{cookbook}"
|
38
|
+
@versioner.version_cookbook(cookbook)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def define_version_environment
|
45
|
+
namespace "Promote" do
|
46
|
+
desc "Version an environment"
|
47
|
+
task "version_environment", :environment do |task, args|
|
48
|
+
@versioner.version_environment(args.environment)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def define_version_environments
|
54
|
+
namespace "Promote" do
|
55
|
+
desc "Version all environments"
|
56
|
+
task "version_environments" do
|
57
|
+
Dir.glob(File.join(@versioner.environment_directory, "*.json")) do |file|
|
58
|
+
environment = File.basename(file ,File.extname(file))
|
59
|
+
puts "versioning environment #{environment}"
|
60
|
+
@versioner.version_environment(environment)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def define_version_data_bag
|
67
|
+
namespace "Promote" do
|
68
|
+
desc "Version a data_bag"
|
69
|
+
task "version_data_bag", :data_bag do |task, args|
|
70
|
+
@versioner.version_data_bag(args.data_bag)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def define_version_data_bags
|
76
|
+
namespace "Promote" do
|
77
|
+
desc "Version all data_bags"
|
78
|
+
task "version_data_bags" do
|
79
|
+
Dir.glob(File.join(@versioner.data_bag_directory, "*.json")) do |file|
|
80
|
+
data_bag = File.basename(file, File.extname(file))
|
81
|
+
puts "versioning data_bag #{data_bag}"
|
82
|
+
@versioner.version_data_bag(data_bag)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'git'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Promote
|
5
|
+
class Versioner
|
6
|
+
def initialize(repo_root = Dir.pwd)
|
7
|
+
@repo_root = repo_root
|
8
|
+
@git = Git.open(git_root(repo_root))
|
9
|
+
version_tags = @git.tags.select { |t| t.name[/^[0-9\.]+/] }
|
10
|
+
@current_tag = version_tags[-1]
|
11
|
+
@sha1 = @git.log(10000).between(current_tag.sha).first.sha
|
12
|
+
end
|
13
|
+
|
14
|
+
def version_cookbook(cookbook_name)
|
15
|
+
dir = File.join(cookbook_directory, cookbook_name)
|
16
|
+
cookbook_name = File.basename(dir)
|
17
|
+
version = version_number(current_tag, dir)
|
18
|
+
metadata_file = File.join(dir, "metadata.rb")
|
19
|
+
metadata_content = File.read(metadata_file)
|
20
|
+
version_line = metadata_content[/^\s*version\s.*$/]
|
21
|
+
current_version = version_line[/('|").*("|')/].gsub(/('|")/,"")
|
22
|
+
|
23
|
+
if current_version != version
|
24
|
+
metadata_content = metadata_content.gsub(current_version, version)
|
25
|
+
outdata = metadata_content.gsub(/#sha1.*$/, "#sha1 '#{sha1}'")
|
26
|
+
if outdata[/#sha1.*$/].nil?
|
27
|
+
outdata += "#sha1 '#{sha1}'"
|
28
|
+
end
|
29
|
+
File.open(metadata_file, 'w') do |out|
|
30
|
+
out << outdata
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def version_data_bag(data_bag_name)
|
36
|
+
version_json data_bag_directory, data_bag_name
|
37
|
+
end
|
38
|
+
|
39
|
+
def version_environment(environment_name)
|
40
|
+
version_json environment_directory, environment_name do | content |
|
41
|
+
content['override_attributes']
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def cookbook_directory
|
46
|
+
File.join(@repo_root, "cookbooks")
|
47
|
+
end
|
48
|
+
|
49
|
+
def environment_directory
|
50
|
+
File.join(@repo_root, "environments")
|
51
|
+
end
|
52
|
+
|
53
|
+
def data_bag_directory
|
54
|
+
File.join(@repo_root, "data_bags/datacenters")
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def version_json(parent_directory, file_name, &block)
|
60
|
+
version_string = "version"
|
61
|
+
file = "#{parent_directory}/#{file_name}.json"
|
62
|
+
version = version_number(current_tag, file)
|
63
|
+
content = JSON.parse(File.read(file))
|
64
|
+
current_version = '0.0'
|
65
|
+
|
66
|
+
if block_given?
|
67
|
+
content_hash = yield content
|
68
|
+
else
|
69
|
+
content_hash = content
|
70
|
+
end
|
71
|
+
|
72
|
+
if content_hash.has_key?(version_string)
|
73
|
+
current_version = content_hash[version_string]
|
74
|
+
end
|
75
|
+
|
76
|
+
if current_version != version
|
77
|
+
content_hash[version_string] = version
|
78
|
+
content_hash['sha1'] = sha1
|
79
|
+
File.open(file, 'w') do |out|
|
80
|
+
out << JSON.pretty_generate(content)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
attr_accessor :git
|
86
|
+
attr_accessor :current_tag
|
87
|
+
attr_accessor :sha1
|
88
|
+
|
89
|
+
def version_number(current_tag, ref)
|
90
|
+
all_commit_count = git.log(10000).object(ref).between(current_tag.sha).size
|
91
|
+
bump_commit_count = git.log(10000).object(ref).between(current_tag.sha).grep("CI:versioning chef artifacts").size
|
92
|
+
commit_count = all_commit_count - bump_commit_count
|
93
|
+
"#{current_tag.name}.#{commit_count}"
|
94
|
+
end
|
95
|
+
|
96
|
+
def git_root(start_leaf)
|
97
|
+
return start_leaf if File.exist?(File.join(start_leaf, '.git'))
|
98
|
+
git_root(File.expand_path('..', start_leaf))
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: clc-promote
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- CenturyLink Cloud
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: knife-spork
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.4'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.4.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.4'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.4.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: git
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.2'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.2.8
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.2'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.2.8
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rspec
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '3.0'
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 3.0.0
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.0'
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 3.0.0
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: rake
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - "~>"
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '10.3'
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 10.3.2
|
83
|
+
type: :development
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.3'
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 10.3.2
|
93
|
+
description: Provides versioning and promotion logic for chef artifacts.
|
94
|
+
email: matt.wrock@CenturyLinkCloud.com
|
95
|
+
executables: []
|
96
|
+
extensions: []
|
97
|
+
extra_rdoc_files:
|
98
|
+
- README.md
|
99
|
+
files:
|
100
|
+
- README.md
|
101
|
+
- lib/promote.rb
|
102
|
+
- lib/promote/rake_tasks.rb
|
103
|
+
- lib/promote/versioner.rb
|
104
|
+
homepage: https://github.com/tier3/DevOps/gems/clc-promote
|
105
|
+
licenses: []
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.2.1
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Provides versioning and promotion logic for chef artifacts.
|
127
|
+
test_files: []
|
128
|
+
has_rdoc:
|