chefrepo-manifest-builder 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df3c16765552633333e05c472744b277346ab802
4
- data.tar.gz: 7997a73e0848b39c34427132b6aab7bc503629bb
3
+ metadata.gz: a455e3bc70be92556fb253128ad744fb40a88cf2
4
+ data.tar.gz: 6d2ff018739679612b997f2292d3e0d44405ddf4
5
5
  SHA512:
6
- metadata.gz: b2b4a7b98813e08e45721c2c4225e1fa8a3a3736912d80f048bf6b3e15a8ed1055d7a78e7a7ec4032e197b998e7c42c99bf5a5ff6179a147115c61fe2e264b86
7
- data.tar.gz: e3484d6a2005d32cdb79c330e29b78eaa0988a157bd39da745aaa77c7b1eec26cfd00f747e3bb571e418bdf9f84f212c9499350d32166f989ce3b24d045e07e0
6
+ metadata.gz: 6e24943165cdb4487ba49b7a7cbaf612abe688e5343c5239c8495b841bb35c2751b434ffe53d3a40db944d95bae82477c9d954ef580a21cfbbadd1b406234d76
7
+ data.tar.gz: ade7210e3d2209c5954dc9eb182300378b1f5a8e6eab410d8fb05f143e6bd637cebc904a429a438d49c2bdd5dee51e83c267e5f039a28e57101b24e204718716
data/.rakeTasks CHANGED
@@ -4,4 +4,4 @@ You are allowed to:
4
4
  1. Remove rake task
5
5
  2. Add existing rake tasks
6
6
  To add existing rake tasks automatically delete this file and reload the project.
7
- --><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Builds all packages" fullCmd="build" taksId="build" /><RakeTask description="Spawns an Interactive Ruby Console" fullCmd="console" taksId="console" /><RakeTask description="Run Cucumber features" fullCmd="cucumber" taksId="cucumber" /><RakeTask description="Installs all built gem packages" fullCmd="install" taksId="install" /><RakeTask description="Performs a release" fullCmd="release" taksId="release" /><RakeTask description="Run RSpec code examples" fullCmd="spec" taksId="spec" /><RakeGroup description="" fullCmd="" taksId="build"><RakeTask description="" fullCmd="build:chefrepo-manifest-builder" taksId="chefrepo-manifest-builder" /><RakeTask description="" fullCmd="build:gem" taksId="gem" /><RakeGroup description="" fullCmd="" taksId="gem"><RakeTask description="" fullCmd="build:gem:chefrepo-manifest-builder" taksId="chefrepo-manifest-builder" /></RakeGroup></RakeGroup><RakeGroup description="" fullCmd="" taksId="console"><RakeTask description="" fullCmd="console:chefrepo-manifest-builder" taksId="chefrepo-manifest-builder" /></RakeGroup><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="gem" taksId="gem" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="" fullCmd="install:chefrepo-manifest-builder" taksId="chefrepo-manifest-builder" /></RakeGroup><RakeTask description="" fullCmd="install_gem" taksId="install_gem" /><RakeTask description="" fullCmd="package" taksId="package" /><RakeTask description="" fullCmd="pkg" taksId="pkg" /><RakeTask description="" fullCmd="pkg/chefrepo-manifest-builder-0.1.0.gem" taksId="pkg/chefrepo-manifest-builder-0.1.0.gem" /><RakeTask description="" fullCmd="publish" taksId="publish" /><RakeTask description="" fullCmd="push" taksId="push" /><RakeGroup description="" fullCmd="" taksId="push"><RakeTask description="" fullCmd="push:chefrepo-manifest-builder" taksId="chefrepo-manifest-builder" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="scm"><RakeTask description="" fullCmd="scm:push" taksId="push" /><RakeTask description="" fullCmd="scm:status" taksId="status" /><RakeTask description="" fullCmd="scm:tag" taksId="tag" /></RakeGroup><RakeTask description="" fullCmd="test" taksId="test" /><RakeTask description="" fullCmd="validate" taksId="validate" /></RakeGroup></Settings>
7
+ --><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Builds all packages" fullCmd="build" taksId="build" /><RakeTask description="Spawns an Interactive Ruby Console" fullCmd="console" taksId="console" /><RakeTask description="Run Cucumber features" fullCmd="cucumber" taksId="cucumber" /><RakeTask description="Installs all built gem packages" fullCmd="install" taksId="install" /><RakeTask description="Performs a release" fullCmd="release" taksId="release" /><RakeTask description="Run RSpec code examples" fullCmd="spec" taksId="spec" /><RakeGroup description="" fullCmd="" taksId="build"><RakeTask description="" fullCmd="build:chefrepo-manifest-builder" taksId="chefrepo-manifest-builder" /><RakeTask description="" fullCmd="build:gem" taksId="gem" /><RakeGroup description="" fullCmd="" taksId="gem"><RakeTask description="" fullCmd="build:gem:chefrepo-manifest-builder" taksId="chefrepo-manifest-builder" /></RakeGroup></RakeGroup><RakeGroup description="" fullCmd="" taksId="console"><RakeTask description="" fullCmd="console:chefrepo-manifest-builder" taksId="chefrepo-manifest-builder" /></RakeGroup><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="gem" taksId="gem" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="" fullCmd="install:chefrepo-manifest-builder" taksId="chefrepo-manifest-builder" /></RakeGroup><RakeTask description="" fullCmd="install_gem" taksId="install_gem" /><RakeTask description="" fullCmd="package" taksId="package" /><RakeTask description="" fullCmd="pkg" taksId="pkg" /><RakeTask description="" fullCmd="pkg/chefrepo-manifest-builder-0.1.3.gem" taksId="pkg/chefrepo-manifest-builder-0.1.3.gem" /><RakeTask description="" fullCmd="publish" taksId="publish" /><RakeTask description="" fullCmd="push" taksId="push" /><RakeGroup description="" fullCmd="" taksId="push"><RakeTask description="" fullCmd="push:chefrepo-manifest-builder" taksId="chefrepo-manifest-builder" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="scm"><RakeTask description="" fullCmd="scm:push" taksId="push" /><RakeTask description="" fullCmd="scm:status" taksId="status" /><RakeTask description="" fullCmd="scm:tag" taksId="tag" /></RakeGroup><RakeTask description="" fullCmd="test" taksId="test" /><RakeTask description="" fullCmd="validate" taksId="validate" /></RakeGroup></Settings>
@@ -1,23 +1,23 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chefrepo-manifest-builder (0.1.3)
4
+ chefrepo-manifest-builder (0.1.4)
5
5
  archive-tar-minitar (= 0.5.2)
6
6
  json (>= 1.8.1, < 1.9)
7
- manifest-builder (>= 0.6.2, < 1.1)
7
+ manifest-builder (>= 0.6.4, < 1.1)
8
8
  s3etag (>= 0.0.1, < 0.1.0)
9
9
 
10
10
  PATH
11
11
  remote: ../chefrepo-builder
12
12
  specs:
13
- chefrepo-builder (0.9.32)
14
- cicd-builder (>= 0.9.47, < 1.1)
13
+ chefrepo-builder (0.9.34)
14
+ cicd-builder (>= 0.9.50, < 1.1)
15
15
  json (= 1.8.1)
16
16
 
17
17
  PATH
18
18
  remote: ../cicd-builder
19
19
  specs:
20
- cicd-builder (0.9.48)
20
+ cicd-builder (0.9.50)
21
21
  artifactory (>= 2.2.1, < 2.3)
22
22
  awesome_print (>= 1.6, < 2.0)
23
23
  aws-sdk (>= 2.0, < 2.1)
@@ -26,15 +26,17 @@ PATH
26
26
  inifile (>= 3.0.0, < 3.1)
27
27
  json (>= 1.8.1, < 1.9)
28
28
  logging (>= 1.8.2, < 1.9)
29
+ parallel (>= 1.4.1, < 1.5)
30
+ ruby-progressbar (>= 1.7.5, < 2)
29
31
  semverse (>= 1.2.1, < 1.3)
30
32
  yajl-ruby (>= 1.2.1, < 1.3)
31
33
 
32
34
  PATH
33
35
  remote: ../manifest-builder
34
36
  specs:
35
- manifest-builder (0.6.2)
37
+ manifest-builder (0.6.4)
36
38
  archive-tar-minitar (= 0.5.2)
37
- chefrepo-builder (>= 0.9.32, < 1.1)
39
+ chefrepo-builder (>= 0.9.34, < 1.1)
38
40
  json (>= 1.8.1, < 1.9)
39
41
  s3etag (>= 0.0.1, < 0.1.0)
40
42
 
@@ -44,14 +46,14 @@ GEM
44
46
  archive-tar-minitar (0.5.2)
45
47
  artifactory (2.2.1)
46
48
  awesome_print (1.6.1)
47
- aws-sdk (2.0.39)
48
- aws-sdk-resources (= 2.0.39)
49
- aws-sdk-core (2.0.39)
49
+ aws-sdk (2.0.41)
50
+ aws-sdk-resources (= 2.0.41)
51
+ aws-sdk-core (2.0.41)
50
52
  builder (~> 3.0)
51
53
  jmespath (~> 1.0)
52
54
  multi_json (~> 1.0)
53
- aws-sdk-resources (2.0.39)
54
- aws-sdk-core (= 2.0.39)
55
+ aws-sdk-resources (2.0.41)
56
+ aws-sdk-core (= 2.0.41)
55
57
  builder (3.2.2)
56
58
  chef (12.0.3)
57
59
  chef-zero (~> 3.2)
@@ -104,7 +106,7 @@ GEM
104
106
  little-plugger (>= 1.1.3)
105
107
  multi_json (>= 1.8.4)
106
108
  method_source (0.8.2)
107
- mime-types (2.4.3)
109
+ mime-types (2.5)
108
110
  mixlib-authentication (1.3.0)
109
111
  mixlib-log
110
112
  mixlib-cli (1.5.0)
@@ -118,7 +120,7 @@ GEM
118
120
  net-ssh-multi (1.2.1)
119
121
  net-ssh (>= 2.6.5)
120
122
  net-ssh-gateway (>= 1.2.0)
121
- ohai (8.2.0)
123
+ ohai (8.3.0)
122
124
  ffi (~> 1.9)
123
125
  ffi-yajl (>= 1.1, < 3.0)
124
126
  ipaddress
@@ -130,6 +132,7 @@ GEM
130
132
  rake (~> 10.1)
131
133
  systemu (~> 2.6.4)
132
134
  wmi-lite (~> 1.0)
135
+ parallel (1.4.1)
133
136
  plist (3.1.0)
134
137
  pry (0.10.1)
135
138
  coderay (~> 1.1.0)
@@ -145,6 +148,7 @@ GEM
145
148
  rspec-expectations (2.99.2)
146
149
  diff-lcs (>= 1.1.3, < 2.0)
147
150
  rspec-mocks (2.99.3)
151
+ ruby-progressbar (1.7.5)
148
152
  rubygems-tasks (0.2.4)
149
153
  s3etag (0.0.1)
150
154
  semverse (1.2.1)
@@ -17,9 +17,9 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ['lib']
19
19
 
20
- gem.add_dependency 'manifest-builder', '>= 0.6.2', '< 1.1'
20
+ gem.add_dependency 'manifest-builder', '>= 0.6.4', '< 1.1'
21
21
  # gem.add_dependency 'cicd-builder', '>= 0.9.48', '< 1.1'
22
- # gem.add_dependency 'chefrepo-builder', '>= 0.9.31', '< 1.1'
22
+ # gem.add_dependency 'chefrepo-builder', '>= 0.9.34', '< 1.1'
23
23
  gem.add_dependency 'json', '>= 1.8.1', '< 1.9'
24
24
  gem.add_dependency 's3etag', '>= 0.0.1', '< 0.1.0'
25
25
  gem.add_dependency 'archive-tar-minitar', '= 0.5.2'
@@ -9,10 +9,15 @@ module CiCd
9
9
 
10
10
  module ChefRepoManifest
11
11
  class Runner < Manifest::Runner
12
+ require 'cicd/builder/chefrepo-manifest/mixlib/build'
13
+ include CiCd::Builder::ChefRepoManifest::Build
14
+ require 'cicd/builder/chefrepo-manifest/mixlib/repo'
15
+ include CiCd::Builder::ChefRepoManifest::Repo
12
16
 
13
17
  # ---------------------------------------------------------------------------------------------------------------
14
18
  def initialize()
15
19
  super
20
+ @klass = 'CiCd::Builder::ChefRepoManifest'
16
21
  @default_options[:builder] = VERSION
17
22
  end
18
23
 
@@ -29,6 +34,9 @@ module CiCd
29
34
  # ---------------------------------------------------------------------------------------------------------------
30
35
  def setup()
31
36
  $stdout.write("ChefRepoManifestBuilder v#{CiCd::Builder::ChefRepoManifest::VERSION}\n")
37
+ @default_options[:env_keys].select{|key| key !~ /^CLASSES/} << %w(
38
+ REPO_PRODUCTS
39
+ )
32
40
  super
33
41
  end
34
42
 
@@ -3,54 +3,177 @@ module CiCd
3
3
  module Builder
4
4
  # noinspection RubySuperCallWithoutSuperclassInspection
5
5
  module ChefRepoManifest
6
+ CLASS = 'CiCd::Builder::ChefRepoManifest'
6
7
  module Build
7
8
 
8
9
  # ---------------------------------------------------------------------------------------------------------------
9
10
  # noinspection RubyHashKeysTypesInspection
10
11
  def prepareBuild()
12
+ @logger.step CLASS+'::'+__method__.to_s
11
13
  super
12
- if @vars[:return_code] == 0
13
- end
14
- @vars[:return_code]
15
- end
14
+ if 0 == @vars[:return_code]
15
+ # We throw away the Manifest builder's hard work on components because they don't apply to us]
16
+ # We still call super because the grandparent does useful things we don't want to duplicate ... ;)
17
+ @vars[:components] = {}
18
+ # Now we need to dig the URL for the latest build of this BRANCH out of the INVENTORY for each of the set of products ... :(
19
+ # Get the repo a little earlier than the typical build which uses it as a write target iso a read source
20
+ getRepoInstance('S3')
21
+ ENV['REPO_PRODUCTS'].split(/,\s+/).each do |product|
22
+ if 0 == @vars[:return_code]
23
+ key,json,over = @repo.pullInventory(product)
24
+ if json.nil?
25
+ @logger.error "Bad repo/inventory specified. s3://#{ENV['AWS_S3_BUCKET']}/#{key}"
26
+ @vars[:return_code] = Errors::PRUNE_BAD_REPO
27
+ else
28
+ if json['container'] and json['container']['variants']
29
+ # but does not have our variant ...
30
+ variants = json['container']['variants']
31
+ @logger.info "\tVariants: #{variants.keys.size} \n#{variants.keys.ai}"
32
+ variants.each do |variant,varianth|
33
+ # If the inventory 'latest' format is up to date ...
34
+ bmax, bmin, releases, versions, versrels = @repo.getVariantVersionsAndReleases(varianth)
35
+ s = "Variant: #{variant}
36
+ \t#{varianth['builds'].size} builds
37
+ \t#{varianth['branches'].size} branches:\n#{varianth['branches'].ai}
38
+ \tBuild numbers: #{bmin}-#{bmax}
39
+ \tVersions: #{versions.ai}
40
+ \tReleases: #{releases.ai}
41
+ \tVersions per Release: #{versrels.ai}
42
+ "
43
+ @logger.info s.gsub(/\n\s+/, "\n\t")
44
+ end
45
+ if variants[@vars[:variant]]
46
+ varianth = variants[@vars[:variant]]
47
+ if varianth['latest'] and varianth['latest'].is_a?(Hash)
48
+ latest = varianth['latest']['build']
49
+ builds = varianth['builds']
50
+ branches = varianth['branches']
51
+ versions = varianth['versions']
16
52
 
17
- # ---------------------------------------------------------------------------------------------------------------
18
- def packageBuild()
19
- @logger.step __method__.to_s
20
- if isSameDirectory(Dir.pwd, ENV['WORKSPACE'])
21
- if @vars.has_key?(:components) and not @vars[:components].empty?
22
- @vars[:return_code] = 0
53
+ drawer = if builds.size > latest
54
+ builds[latest]
55
+ else
56
+ nil
57
+ end
58
+ if drawer
59
+ ver = @repo._getVersion(@vars, drawer)
60
+ rel = @repo._getRelease(@vars, drawer)
61
+ bra = @repo._getBranch(@vars, drawer)
62
+ name = drawer['build_name'] rescue drawer['build']
63
+ var = @repo._getMatches(@vars, name, :variant)
64
+ num = @repo._getMatches(@vars, name, :build)
65
+ unless var == @vars[:variant] &&
66
+ ver == @vars[:version] &&
67
+ rel == @vars[:release] &&
68
+ bra == @vars[:branch]
69
+ drawer = nil
70
+ end
71
+ end
72
+ unless drawer
73
+ if branches.include?(@vars[:branch])
74
+ survivors = builds.select{ |drawer|
75
+ bra = @repo._getBranch(@vars, drawer)
76
+ bra == @vars[:branch]
77
+ }
78
+ builds = survivors
79
+ if versions.include?(@vars[:version])
80
+ survivors = builds.select{ |drawer|
81
+ ver = @repo._getVersion(@vars, drawer)
82
+ ver == @vars[:version]
83
+ }
84
+ builds = survivors
85
+ if versrels.include?("#{@vars[:version]}-#{@vars[:release]}")
86
+ survivors = builds.select{ |drawer|
87
+ rel = @repo._getRelease(@vars, drawer)
88
+ rel == @vars[:release]
89
+ }
90
+ builds = survivors
91
+ drawer = builds[-1]
92
+ else
93
+ @logger.error "Cannot manifest the version '#{@vars[:version]}' from variant '#{@vars[:variant]}'"
94
+ @vars[:return_code] = Errors::REPO_BAD_VERSION
95
+ end
96
+ else
97
+ @logger.error "Cannot manifest the version '#{@vars[:version]}' from variant '#{@vars[:variant]}'"
98
+ @vars[:return_code] = Errors::REPO_BAD_VERSION
99
+ end
100
+ else
101
+ @logger.error "Cannot manifest the branch '#{@vars[:branch]}' from variant '#{@vars[:variant]}'"
102
+ @vars[:return_code] = Errors::REPO_BAD_BRANCH
103
+ end
104
+ end
105
+ if drawer
106
+ # Get the artifacts ...
107
+ assembly = drawer['assembly'] || json['container']['assembly']
108
+ artifacts = drawer['artifacts'].select{|art|
109
+ art =~ /\.#{assembly['extension']}$/
110
+ }
111
+ if artifacts.size > 0
112
+ @logger.info "Found these artifacts: #{artifacts.ai}"
113
+ key = "#{product}/#{@vars[:variant]}/#{drawer['drawer']}/#{artifacts[0]}"
114
+ obj = @repo.maybeS3Object(key)
115
+ if obj
116
+ ver = @repo._getVersion(@vars, drawer)
117
+ rel = @repo._getRelease(@vars, drawer)
118
+ bra = @repo._getBranch(@vars, drawer)
119
+ name = drawer['build_name'] rescue drawer['build']
120
+ var = @repo._getMatches(@vars, name, :variant)
121
+ num = @repo._getMatches(@vars, name, :build)
23
122
 
24
- clazz = getRepoClass('S3')
25
- @logger.debug "Repo class == '#{clazz}'"
26
- if clazz.is_a?(Class) and not clazz.nil?
27
- @repo = clazz.new(self)
123
+ @vars[:components][product] = {
124
+ name: product,
125
+ url: obj.public_url,
126
+ version: ver,
127
+ release: rel,
128
+ branch: bra,
129
+ variant: var,
130
+ build: num,
131
+ s3_bucket: ENV['AWS_S3_BUCKET'],
132
+ s3_key: key,
133
+ file_name: product,
134
+ file_ext: assembly['extension'],
135
+ }
28
136
 
29
- if @vars[:return_code] == 0
30
- lines = []
31
- @vars[:artifacts] = []
32
- # Deal with all artifacts of each component
33
- @vars[:components].each { |comp|
34
- processComponent(comp, lines)
35
- }
36
- if @vars[:return_code] == 0
37
- cleanupAfterPackaging(lines)
137
+ chksms = drawer['artifacts'].select{|art|
138
+ art =~ /\.checksum$/
139
+ }
140
+ if chksms.size > 0
141
+ chk = "#{product}/#{@vars[:variant]}/#{drawer['drawer']}/#{chksms[0]}"
142
+ chk_obj = @repo.maybeS3Object(chk)
143
+ if chk_obj
144
+ out = chk_obj.get()
145
+ @vars[:components][product][:sha256] = (out[:body].is_a?(String) ? out[:body] : out[:body].read) if out
146
+ end
147
+ end
148
+ else
149
+ @logger.error "Cannot manifest for #{key} ???"
150
+ @vars[:return_code] = Errors::REPO_NO_BUILD
151
+ end
152
+ else
153
+ @logger.error "No artifacts to manifest for #{key} ???"
154
+ @vars[:return_code] = Errors::REPO_NO_BUILD
155
+ end
156
+ else
157
+ @logger.error "Cannot find a build to manifest for #{product}-#{@vars[:version]}-release-#{@vars[:release]}-#{@vars[:branch]}-#{@vars[:variant]}"
158
+ @vars[:return_code] = Errors::REPO_NO_BUILD
159
+ end
160
+ else
161
+ # Start over ... too old/ incompatible
162
+ @logger.error 'Repo too old or incompatible to manifest. No [container][variants][VARIANT][latest].'
163
+ @vars[:return_code] = Errors::PRUNE_TOO_OLD
164
+ end
165
+ else
166
+ @logger.error 'Our variant has not been built!?'
167
+ @vars[:return_code] = Errors::REPO_NO_VARIANT
168
+ end
169
+ else
170
+ # Start over ... too old/ incompatible
171
+ @logger.error 'Repo too old or incompatible to manifest. No [container][variants].'
172
+ @vars[:return_code] = Errors::PRUNE_TOO_OLD
38
173
  end
39
-
40
- else
41
- @logger.fatal "S3 repo error: Bucket #{ENV['AWS_S3_BUCKET']}"
42
174
  end
43
- else
44
- @logger.error "CiCd::Builder::Repo::#{type} is not a valid repo class"
45
- @vars[:return_code] = Errors::BUILDER_REPO_TYPE
46
175
  end
47
- else
48
- @logger.error 'No components found during preparation?'
49
- @vars[:return_code] = Errors::NO_COMPONENTS
50
176
  end
51
- else
52
- @logger.error "Not in WORKSPACE? '#{pwd}' does not match WORKSPACE='#{workspace}'"
53
- @vars[:return_code] = Errors::WORKSPACE_DIR
54
177
  end
55
178
 
56
179
  @vars[:return_code]
@@ -0,0 +1,49 @@
1
+ require 'json'
2
+
3
+ module CiCd
4
+ module Builder
5
+ # noinspection RubySuperCallWithoutSuperclassInspection
6
+ module ChefRepoManifest
7
+ module Repo
8
+ require 'cicd/builder/mixlib/repo/base'
9
+ require 'cicd/builder/mixlib/repo/S3'
10
+ # noinspection RubyResolve
11
+ if ENV.has_key?('REPO_TYPE') and (not ENV['REPO_TYPE'].capitalize.eql?('S3'))
12
+ require "cicd/builder/chefrepo-manifest/mixlib/repo/#{ENV['REPO_TYPE'].downcase}"
13
+ end
14
+
15
+ # ---------------------------------------------------------------------------------------------------------------
16
+ def getRepoClass(type = nil)
17
+ @logger.step CLASS+'::'+__method__.to_s
18
+ if type.nil?
19
+ type ||= 'S3'
20
+ if ENV.has_key?('REPO_TYPE')
21
+ type = ENV['REPO_TYPE']
22
+ end
23
+ end
24
+
25
+ @logger.info "#{type} repo interface"
26
+ clazz = begin
27
+ Object.const_get("#{self.class.name.gsub(%r'::\w+$', '')}::Repo::#{type}")
28
+ rescue NameError => e
29
+ begin
30
+ # Object.const_get("#{self.class.name.gsub(%r'::\w+$', '')}::Repo::#{type}")
31
+ Object.const_get("CiCd::Builder::Manifest::Repo::#{type}")
32
+ rescue NameError #=> e
33
+ Object.const_get("CiCd::Builder::Repo::#{type}")
34
+ end
35
+ end
36
+
37
+ if block_given?
38
+ if clazz.is_a?(Class) and not clazz.nil?
39
+ yield
40
+ end
41
+ end
42
+
43
+ clazz
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,323 +1,28 @@
1
1
  require 'artifactory'
2
2
  require 'tmpdir'
3
+ require "cicd/builder/manifest/mixlib/repo/artifactory"
3
4
 
4
5
  module CiCd
5
6
  module Builder
6
7
  # noinspection RubySuperCallWithoutSuperclassInspection
7
- module Manifest
8
+ module ChefRepoManifest
8
9
  module Repo
9
- class Artifactory < CiCd::Builder::Repo::Artifactory
10
- # include ::Artifactory::Resource
10
+ class Artifactory < CiCd::Builder::Manifest::Repo::Artifactory
11
+
12
+ # # ---------------------------------------------------------------------------------------------------------------
13
+ # def handleManifests()
14
+ # if @vars[:return_code] == 0
15
+ # # Preserve the manifest (maybeUploadArtifactoryObject will add everything we upload to the instance var)
16
+ # manifest = @manifest.dup
17
+ # # Create a manifest for each product and store it.
18
+ # createProductManifests(manifest)
19
+ # @manifest = manifest
20
+ # end
21
+ # @vars[:return_code]
22
+ # end
11
23
 
12
- # ---------------------------------------------------------------------------------------------------------------
13
- def initialize(builder)
14
- super
15
- end
16
-
17
- # ---------------------------------------------------------------------------------------------------------------
18
- def uploadToRepo(artifacts)
19
- @manifest = {}
20
- super
21
- if @vars[:return_code] == 0
22
- # Preserve the manifest (maybeUploadArtifactoryObject will add everything we upload to the instance var)
23
- manifest = @manifest.dup
24
- # Create a manifest for each product and store it.
25
- createProductManifests(manifest)
26
- # Get a super manifest of all products and store as learning-manifest
27
- createSuperManifest(manifest) # -#{@vars[:variant]}
28
- @manifest = manifest
29
- end
30
- # If we are asked to produce a PROJECTS_FILE then we do that from the manifest and components.
31
- unless ENV['PROJECTS_FILE'].nil?
32
- if @vars[:return_code] == 0
33
- if File.directory?(File.realdirpath(File.dirname(ENV['PROJECTS_FILE'])))
34
- createProjectsFile
35
- else
36
- @logger.error "The path to the PROJECTS_FILE (#{File.dirname(ENV['PROJECTS_FILE'])}) does not exist!"
37
- @vars[:return_code] = Errors::NO_PROJECTS_PATH
38
- end
39
- end
40
- end
41
- @vars[:artifacts].each do |art|
42
- if art[:data][:temp].is_a?(FalseClass)
43
- if File.exists?(art[:data][:file])
44
- File.unlink(art[:data][:file]) if File.exists?(art[:data][:file])
45
- art[:data].delete(:file)
46
- art[:data].delete(:temp)
47
- else
48
- @logger.warn "Temporary file disappeared: #{data.ai}"
49
- @vars[:return_code] = Errors::TEMP_FILE_MISSING
50
- end
51
- end
52
- end
53
- @vars[:return_code]
54
- end
55
-
56
- # ---------------------------------------------------------------------------------------------------------------
57
- def createProjectsFile
58
- @logger.info __method__.to_s
59
- projects = {}
60
- project_names = loadProjectNames()
61
- exts = {}
62
- exts = Hash[@vars[:artifacts].map { |a| [a[:data][:name], File.basename(a[:data][:file]).match(CiCd::Builder::Manifest::Build::EXT_RGX)[1]] }]
63
-
64
- createClassesFile()
65
-
66
- @vars[:artifacts].each do |art|
67
- prod = art[:data][:name]
68
- mod = art[:data][:module]
69
- projects[prod] = {
70
- name: project_names[prod] || prod,
71
- module: mod,
72
- ext: exts[prod],
73
- class_filter: @vars[:filters][prod] || @vars[:filters][prod.gsub(/-manifest$/, '')],
74
- }
75
- end
76
-
77
- require 'chef/mash'
78
- require 'chef/mixin/deep_merge'
79
-
80
- projects_hash = File.exists?(ENV['PROJECTS_FILE']) ? loadConfigFile(ENV['PROJECTS_FILE']) : {}
81
- old_projects = ::Chef::Mash.new(projects_hash)
82
- projects = ::Chef::Mash.new(projects)
83
- projects = ::Chef::Mash.new(::Chef::Mixin::DeepMerge.deep_merge(projects, old_projects))
84
- saveConfigFile(ENV['PROJECTS_FILE'], projects)
85
- data = {
86
- name: 'projects-file',
87
- module: 'projects-file',
88
- file: ENV['PROJECTS_FILE'],
89
- version: @vars[:build_ver],
90
- build: @vars[:build_num],
91
- properties: @properties_matrix,
92
- temp: false,
93
- sha1: Digest::SHA1.file(ENV['PROJECTS_FILE']).hexdigest,
94
- md5: Digest::MD5.file(ENV['PROJECTS_FILE']).hexdigest,
95
- }
96
-
97
- maybeUploadArtifactoryObject(
98
- data: data,
99
- artifact_module: data[:name],
100
- artifact_version: data[:version] || @vars[:version],
101
- file_name: '',
102
- file_ext: (ENV['PROJECTS_FILE'] and ENV['PROJECTS_FILE'].downcase.match(/\.ya?ml$/)) ? 'yaml' : 'json'
103
- )
104
- end
105
-
106
- # ---------------------------------------------------------------------------------------------------------------
107
- # noinspection RubyHashKeysTypesInspection
108
- def createClassesFile()
109
- @logger.info __method__.to_s
110
- project_names = loadProjectNames()
111
-
112
- @vars[:classes] = YAML.load(IO.read(ENV['CLASSES_MANIFEST_FILE']))
113
- # keys = Hash[classes.keys.map.with_index.to_a].keys.sort
114
-
115
- @vars[:filters] = {}
116
- filters = {}
117
- @vars[:classes].each do |role,apps|
118
- apps.map{ |app|
119
- filters[app] ||= []
120
- filters[app] << role
121
- }
122
- end
123
- filters.each do |app,roles|
124
- @vars[:filters][app] = Hash[roles.map.with_index.to_a].keys.join('|')
125
- end
126
-
127
- saveConfigFile(ENV['CLASSES_FILE'],@vars[:classes])
128
- data = {
129
- name: 'classes-file',
130
- module: 'classes-file',
131
- file: ENV['CLASSES_FILE'],
132
- version: @vars[:build_ver],
133
- build: @vars[:build_num],
134
- properties: @properties_matrix,
135
- temp: false,
136
- sha1: Digest::SHA1.file(ENV['CLASSES_FILE']).hexdigest,
137
- md5: Digest::MD5.file(ENV['CLASSES_FILE']).hexdigest,
138
- }
139
-
140
- maybeUploadArtifactoryObject(
141
- data: data,
142
- artifact_module: data[:name],
143
- artifact_version: data[:version] || @vars[:version],
144
- file_name: '',
145
- file_ext: 'yaml'
146
- )
147
- end
148
-
149
- def saveConfigFile(file, projects)
150
- @logger.info "Save config file: #{file}"
151
- ext = file.gsub(/\.(\w+)$/, '\1')
152
- IO.write(file, case ext.downcase
153
- when /ya?ml/
154
- projects.to_hash.to_yaml line_width: 1024, indentation: 4, canonical: false
155
- when /json|js/
156
- JSON.pretty_generate(projects.to_hash, {indent: "\t", space: ' '})
157
- else
158
- raise "Unsupported extension: #{ext}"
159
- end)
160
- end
161
-
162
- def loadConfigFile(file)
163
- ext = file.gsub(/\.(\w+)$/, '\1')
164
- hash = case ext.downcase
165
- when /ya?ml/
166
- YAML.load_file(ENV['PROJECTS_FILE'])
167
- when /json|js/
168
- JSON.load(IO.read(ENV['PROJECTS_FILE']))
169
- else
170
- raise "Unsupported extension: #{ext}"
171
- end
172
- end
173
-
174
- def loadProjectNames(fresh=false)
175
- if fresh
176
- @project_names = nil
177
- end
178
- unless @project_names
179
- @project_names = {}
180
- unless ENV['PROJECT_NAMES'].nil?
181
- if File.exists?(ENV['PROJECT_NAMES'])
182
- @logger.info "Load PROJECT_NAMES: #{ENV['PROJECT_NAMES']}"
183
- @project_names = JSON.load(IO.read(ENV['PROJECT_NAMES'])) || {}
184
- else
185
- @logger.error "The PROJECT_NAMES file (#{ENV['PROJECT_NAMES']}) does not exist!"
186
- @vars[:return_code] = Errors::NO_PROJECT_NAMES
187
- end
188
- end
189
- end
190
- @project_names
191
- end
192
-
193
- def createSuperManifest(manifest)
194
- manifest_data = ''
195
- manifest.each do |mod, man|
196
- man.each do |k, v|
197
- manifest_data += "#{k}=#{v}\n"
198
- end
199
- end
200
- amn = artifactory_manifest_name # Just using a local iso invoking method_missing repeatedly ... ;)
201
- data = {module: amn, data: manifest_data, version: @vars[:build_ver], build: @vars[:build_num], properties: @properties_matrix}
202
- # tempArtifactFile(amn, data)
203
-
204
- data[:file] = Dir::Tmpname.create(amn) do |tmpnam, n, opts|
205
- mode = File::RDWR|File::CREAT|File::EXCL
206
- perm = 0600
207
- opts = perm
208
- end + '.properties'
209
- IO.write(data[:file], data[:data])
210
- data[:temp] = false
211
- data[:sha1] = Digest::SHA1.file(data[:file]).hexdigest
212
- data[:md5] = Digest::MD5.file(data[:file]).hexdigest
213
- data[:name] = amn
214
- @vars[:artifacts] << {
215
- key: amn,
216
- data: data.dup,
217
- }
218
- # manifest[amn]={ amn => "#{@vars[:build_ver]}-#{@vars[:build_num]}" }
219
-
220
- maybeUploadArtifactoryObject(data: data, artifact_module: amn, artifact_version: data[:version] || @vars[:version], file_name: '', file_ext: 'properties')
221
- end
222
-
223
- # ---------------------------------------------------------------------------------------------------------------
224
- def createProductManifests(manifest)
225
- manifest.dup.each do |mod, man|
226
- manifest_data = ''
227
- man.each do |k, v|
228
- manifest_data += "#{k}=#{v}\n"
229
- end
230
- data = {
231
- name: "#{mod}-manifest",
232
- module: "#{mod}-manifest",
233
- component: mod,
234
- data: manifest_data,
235
- version: @vars[:build_ver],
236
- build: @vars[:build_num],
237
- properties: @properties_matrix
238
- }
239
- # tempArtifactFile("#{mod}-manifest", data)
240
-
241
- data[:file] = Dir::Tmpname.create("#{mod}-manifest") do |tmpnam, n, opts|
242
- mode = File::RDWR|File::CREAT|File::EXCL
243
- perm = 0600
244
- opts = perm
245
- end + '.properties'
246
- IO.write(data[:file], data[:data])
247
- data[:temp] = false
248
- data[:sha1] = Digest::SHA1.file(data[:file]).hexdigest
249
- data[:md5] = Digest::MD5.file(data[:file]).hexdigest
250
- @vars[:artifacts] << {
251
- key: "#{mod}-manifest",
252
- data: data.dup,
253
- }
254
- # noinspection RubyStringKeysInHashInspection
255
- # manifest["#{mod}-manifest"]={ "#{mod}-manifest" => "#{@vars[:build_ver]}-#{@vars[:build_num]}" }
256
-
257
- maybeUploadArtifactoryObject(data: data, artifact_module: data[:name], artifact_version: data[:version] || @vars[:version], file_name: '', file_ext: 'properties') # -#{@vars[:variant]}
258
- end
259
- end
260
-
261
- # ---------------------------------------------------------------------------------------------------------------
262
- def maybeUploadArtifactoryObject(args)
263
- super
264
- if @vars[:return_code] == 0
265
- data = args[:data]
266
- artifact_module = args[:artifact_module]
267
- artifact_version = args[:artifact_version]
268
- # file_ext = args[:file_ext]
269
- # file_name = args[:file_name]
270
- if @manifest[artifact_module].nil?
271
- @manifest[artifact_module] = {}
272
- file_name = artifact_module
273
- else
274
- file_name, _ = get_artifact_file_name_ext(data)
275
- if file_name.empty?
276
- file_name = artifact_module
277
- else
278
- file_name = "#{artifact_module}#{file_name}"
279
- end
280
- end
281
- @manifest[artifact_module][file_name] = artifact_version
282
- end
283
-
284
- @vars[:return_code]
285
- end
286
-
287
- private :createProductManifests, :createProjectsFile, :createSuperManifest
288
24
  end
289
25
  end
290
26
  end
291
27
  end
292
28
  end
293
-
294
- =begin
295
-
296
- {
297
- "test-project": {
298
- "name": "test-project",
299
- "module": "test-server",
300
- "ext": "war",
301
- "class_filter": "role.role-1"
302
- },
303
- "test-project-2": {
304
- "name": "test-project-2",
305
- "module": "test-server2",
306
- "ext": "zip",
307
- "class_filter": "role.role-2"
308
- },
309
- "test-manifest": {
310
- "name": "test-manifest",
311
- "module": "test-manifest",
312
- "ext": "properties",
313
- "class_filter": ""
314
- },
315
- "test-manifest2": {
316
- "name": "test-manifest2",
317
- "module": "test-manifest2",
318
- "ext": "properties",
319
- "class_filter": ""
320
- }
321
- }
322
-
323
- =end
@@ -2,7 +2,7 @@ module CiCd
2
2
  module Builder
3
3
  module ChefRepoManifest
4
4
  # chefrepo-manifest-builder version
5
- VERSION = '0.1.3'
5
+ VERSION = '0.1.4'
6
6
  MAJOR, MINOR, TINY = VERSION.split('.')
7
7
  PATCH = TINY
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chefrepo-manifest-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christo De Lange
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-28 00:00:00.000000000 Z
11
+ date: 2015-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: manifest-builder
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.6.2
19
+ version: 0.6.4
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '1.1'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 0.6.2
29
+ version: 0.6.4
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '1.1'
@@ -210,6 +210,7 @@ files:
210
210
  - features/step_definitions/manifestrepo-builder_steps.rb
211
211
  - lib/cicd/builder/chefrepo-manifest.rb
212
212
  - lib/cicd/builder/chefrepo-manifest/mixlib/build.rb
213
+ - lib/cicd/builder/chefrepo-manifest/mixlib/repo.rb
213
214
  - lib/cicd/builder/chefrepo-manifest/mixlib/repo/artifactory.rb
214
215
  - lib/cicd/builder/chefrepo-manifest/version.rb
215
216
  - openssl