manifest-builder 0.6.0 → 0.6.2

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: ffd8bef49ca4e0886fd5532da54da27c4b6bfbd7
4
- data.tar.gz: 50f0f52111d62b9850957f4e498f181edb3e80c6
3
+ metadata.gz: 0b10b3d8ea6cfc58960b69110ceb02434f017b35
4
+ data.tar.gz: 1d2dc07ea272e2d8ffde9016586873cd5e834350
5
5
  SHA512:
6
- metadata.gz: e29f04b796c242f71f6feced462cf3d3a2f09228578b0ecfe0293967d984d09cc835687f7c96511fb5ec28843fc86f6861b3208bff13be9698009f3c008fe660
7
- data.tar.gz: 5a9d3cfc3e4eeffd30f9204850ff60f0aefdab23b9381fb426a60e7e9e0d5a3c69cd53a0239bd50ff1bf0871358ae96abf2f5b2b8d06584321841fbf721051b7
6
+ metadata.gz: f545e10d18b032a1c4f2de06f63f684cff93e2d1fd3d9ddea06e4c976a7f7192e73d6bce5be5b3ff76300f76ddda5a093308c55b472bbf1e287a43f5283781cd
7
+ data.tar.gz: 6e88d6c42454c00614ced3186896e6744682e451c8557e8f482b26c1b69f36664aa5c951cf75704873247dbb5ed67b69512c5594ab483f46cd285644a2ab8d1f
data/Gemfile.lock CHANGED
@@ -1,24 +1,23 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- manifest-builder (0.6.0)
4
+ manifest-builder (0.6.2)
5
5
  archive-tar-minitar (= 0.5.2)
6
- chefrepo-builder (>= 0.9.31, < 1.1)
7
- cicd-builder (>= 0.9.47, < 1.1)
6
+ chefrepo-builder (>= 0.9.32, < 1.1)
8
7
  json (>= 1.8.1, < 1.9)
9
8
  s3etag (>= 0.0.1, < 0.1.0)
10
9
 
11
10
  PATH
12
11
  remote: ../chefrepo-builder
13
12
  specs:
14
- chefrepo-builder (0.9.31)
13
+ chefrepo-builder (0.9.32)
15
14
  cicd-builder (>= 0.9.47, < 1.1)
16
15
  json (= 1.8.1)
17
16
 
18
17
  PATH
19
18
  remote: ../cicd-builder
20
19
  specs:
21
- cicd-builder (0.9.47)
20
+ cicd-builder (0.9.48)
22
21
  artifactory (>= 2.2.1, < 2.3)
23
22
  awesome_print (>= 1.6, < 2.0)
24
23
  aws-sdk (>= 2.0, < 2.1)
@@ -84,7 +83,7 @@ GEM
84
83
  json (>= 1.4.6)
85
84
  git (1.2.9.1)
86
85
  hashie (2.1.2)
87
- highline (1.7.1)
86
+ highline (1.7.2)
88
87
  inifile (3.0.0)
89
88
  ipaddress (0.8.0)
90
89
  jmespath (1.0.2)
@@ -35,6 +35,8 @@ module CiCd
35
35
  $stdout.write("ManifestBuilder v#{CiCd::Builder::Manifest::VERSION}\n")
36
36
  @default_options[:env_keys] << %w(
37
37
  MANIFEST_FILE
38
+ CLASSES_FILE
39
+ CLASSES_MANIFEST_FILE
38
40
  )
39
41
  super
40
42
  end
@@ -88,6 +88,7 @@ module CiCd
88
88
 
89
89
  # ---------------------------------------------------------------------------------------------------------------
90
90
  def getVersionBuild(path,artifact,comp)
91
+ cname,cdata = comp
91
92
  version,build = File.split(path)
92
93
  if build.match(%r'^\d+$') and version.match(%r'/?\d+\.\d+\.?\d*$') # Hole in one!
93
94
  version = File.basename(version)
@@ -96,10 +97,10 @@ module CiCd
96
97
  version = build
97
98
  build = ''
98
99
  else
99
- version = comp[1][:build].nil? ? '' : ( comp[1][:build] > 0 ? build.to_s : '' )
100
+ version = cdata[:build].nil? ? '' : ( cdata[:build] > 0 ? build.to_s : '' )
100
101
  end
101
102
  unless version.match(VER_RGX)
102
- version = comp[1][:version] || ''
103
+ version = cdata[:version] || ''
103
104
  end
104
105
  ver,bld = getVersionBuildFromName(artifact)
105
106
  if version.empty?
@@ -147,7 +148,7 @@ module CiCd
147
148
  end
148
149
  end
149
150
  unless build.match(%r'^[1-9]\d*$')
150
- build = comp[1][:build]
151
+ build = cdata[:build]
151
152
  build = @vars[:build_num] if (build.nil? or build.empty? or build.to_i == 0)
152
153
  end
153
154
  end
@@ -221,21 +222,25 @@ module CiCd
221
222
  # ---------------------------------------------------------------------------------------------------------------
222
223
  def processComponent(comp, lines)
223
224
  artifact, path, version, build = parseComponent(comp)
225
+ cname,cdata = comp
224
226
 
225
227
  require 'uri'
228
+ require 'digest'
226
229
  begin
227
230
  key, name, objects = getObjects(artifact, path)
228
- local_dir = File.join(@vars[:local_dirs]['artifacts'], comp[0], '')
231
+ local_dir = File.join(@vars[:local_dirs]['artifacts'], cname, '')
229
232
  Dir.mkdir(local_dir, 0700) unless File.directory?(local_dir)
230
233
  artifacts = []
234
+ sha256 = {}
231
235
  changed = false
232
236
  # 1 or more objects on the key/ path
233
237
  if objects.size > 0
234
- lines << "#{comp[0]}:#{artifact} v#{version} b#{build} - #{path}"
238
+ lines << "#{cname}:#{artifact} v#{version} b#{build} - #{path}"
235
239
  # When we start pulling the artifacts then everything that is build 0 get this build number, in fact all artifacts get this build number!
236
240
  objects.each do |object|
237
241
  @logger.info "\tchecking #{object.key}"
238
- local = File.join(local_dir, File.basename(object.key))
242
+ base = File.basename(object.key)
243
+ local = File.join(local_dir, base)
239
244
  etag = object.etag.gsub(%r/['"]/, '')
240
245
  download = shouldDownload?(etag, local, object)
241
246
  if download
@@ -243,12 +248,41 @@ module CiCd
243
248
  else
244
249
  @logger.info "\t\tunchanged"
245
250
  end
251
+ sha256[base] = nil
252
+ if cdata[:sha256]
253
+ hd = Digest::SHA256.file(local).hexdigest
254
+ sha256[base] = hd == cdata[:sha256] ? true : hd
255
+ end
256
+
246
257
  artifacts << local
247
258
  end
248
259
  # The local file will be 1 artifact or an archive of the local artifacts when artifacts.size > 1
249
260
  if artifacts.size > 0
250
- local = getLocalArtifact(artifacts, changed, comp, local_dir, version)
251
- addArtifact(@vars[:artifacts], local, local_dir, {module: comp[0], name: comp[0], build: build, version: version, file: local})
261
+ artifacts.each do |local|
262
+ base = File.basename(local)
263
+ if sha256[base].is_a?(String)
264
+ msg = "Artifact checksum is invalid or manifest is incorrect. Artifact: s3://#{name}/#{key}#{artifact}, SHA256: Manifest=#{cdata[:sha256]}, Actual=#{sha256[base]}"
265
+ if ENV['ENFORCE_CHECKSUMS'] and ENV['ENFORCE_CHECKSUMS'].downcase =~ %r/^(yes|on|set|1|enable|active|enforced?)$/
266
+ @logger.fatal msg
267
+ @vars[:return_code] = Errors::ARTIFACT_CHECKSUM_BAD
268
+ else
269
+ @logger.warn msg
270
+ end
271
+ end
272
+ end
273
+ if 0 == @vars[:return_code]
274
+ local = getLocalArtifact(artifacts, changed, comp, local_dir, version)
275
+ base = File.basename(local)
276
+ addArtifact(@vars[:artifacts], local, local_dir, {
277
+ component: cname,
278
+ module: cname,
279
+ name: cname,
280
+ build: build,
281
+ version: version,
282
+ file: local,
283
+ sha256: (sha256.keys.include?(base)) ? (sha256[base].is_a?(TrueClass) ? cdata[:sha256] : sha256[base]) : Digest::SHA256.file(local).hexdigest
284
+ })
285
+ end
252
286
  end
253
287
  else
254
288
  @logger.fatal "Artifact not found: s3://#{name}/#{key}#{artifact}"
@@ -312,9 +346,10 @@ module CiCd
312
346
 
313
347
  # ---------------------------------------------------------------------------------------------------------------
314
348
  def getLocalArtifact(artifacts, changed, comp, local_dir, version)
349
+ cname,cdata = comp
315
350
  if artifacts.size > 1
316
351
  begin
317
- file = File.join(local_dir, "#{comp[0]}-#{version}.zip")
352
+ file = File.join(local_dir, "#{cname}-#{version}.zip")
318
353
  if changed or not File.exists?(file)
319
354
  zipped_files = artifacts.map { |f| f.gsub(%r'^#{local_dir}', '') }.join(' ')
320
355
  Dir.chdir(local_dir) do
@@ -336,23 +371,24 @@ module CiCd
336
371
 
337
372
  # ---------------------------------------------------------------------------------------------------------------
338
373
  def parseComponent(comp)
339
- if comp[1][:url]
340
- path, artifact = File.split(comp[1][:url])
374
+ cname,cdata = comp
375
+ if cdata[:url]
376
+ path, artifact = File.split(cdata[:url])
341
377
  version, build = getVersionBuild(path, artifact, comp)
342
- elsif comp[1][:base_url]
378
+ elsif cdata[:base_url]
343
379
  artifact = ''
344
- if comp[1][:build].nil?
380
+ if cdata[:build].nil?
345
381
  # noinspection RubyUnusedLocalVariable
346
- version, build = comp[1][:version].split(%r'-')
382
+ version, build = cdata[:version].split(%r'-')
347
383
  # noinspection RubyUnusedLocalVariable
348
- path = File.join(comp[1][:base_url], comp[1][:version])
384
+ path = File.join(cdata[:base_url], cdata[:version])
349
385
  else
350
- version, build = [comp[1][:version], comp[1][:build]]
351
- path = File.join(comp[1][:base_url], comp[1][:version], comp[1][:build])
386
+ version, build = [cdata[:version], cdata[:build]]
387
+ path = File.join(cdata[:base_url], cdata[:version], cdata[:build])
352
388
  end
353
389
  else
354
- path = ''
355
- artifact = ''
390
+ path = ''
391
+ artifact = ''
356
392
  version, build = getVersionBuild(path, artifact, comp)
357
393
  end
358
394
  return artifact, path, version, build
@@ -57,36 +57,31 @@ module CiCd
57
57
  def createProjectsFile
58
58
  @logger.info __method__.to_s
59
59
  projects = {}
60
- project_names = {}
61
- unless ENV['PROJECT_NAMES'].nil?
62
- if File.exists?(ENV['PROJECT_NAMES'])
63
- @logger.info "Load PROJECT_NAMES: #{ENV['PROJECT_NAMES']}"
64
- project_names = JSON.load(IO.read(ENV['PROJECT_NAMES'])) || {}
65
- else
66
- @logger.error "The PROJECT_NAMES file (#{ENV['PROJECT_NAMES']}) does not exist!"
67
- @vars[:return_code] = Errors::NO_PROJECT_NAMES
68
- end
69
- end
60
+ project_names = loadProjectNames()
70
61
  exts = {}
71
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
+
72
66
  @vars[:artifacts].each do |art|
73
67
  prod = art[:data][:name]
74
68
  mod = art[:data][:module]
75
69
  projects[prod] = {
76
- name: project_names[prod] || prod,
77
- module: mod,
78
- ext: exts[prod],
79
- class_filter: '',
80
- }
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
+ }
81
75
  end
82
76
 
83
77
  require 'chef/mash'
84
78
  require 'chef/mixin/deep_merge'
85
- old_projects = Chef::Mash.new(File.exists?(ENV['PROJECTS_FILE']) ? JSON.load(IO.read(ENV['PROJECTS_FILE'])) : {})
86
- projects = Chef::Mash.new(projects)
87
- projects = Chef::Mash.new(Chef::Mixin::DeepMerge.deep_merge(projects, old_projects))
88
- @logger.info "Save PROJECTS_FILE: #{ENV['PROJECTS_FILE']}"
89
- IO.write(ENV['PROJECTS_FILE'], JSON.pretty_generate(projects.to_hash, {indent: "\t", space: ' '}))
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)
90
85
  data = {
91
86
  name: 'projects-file',
92
87
  module: 'projects-file',
@@ -99,7 +94,100 @@ module CiCd
99
94
  md5: Digest::MD5.file(ENV['PROJECTS_FILE']).hexdigest,
100
95
  }
101
96
 
102
- maybeUploadArtifactoryObject(data: data, artifact_module: data[:name], artifact_version: data[:version] || @vars[:version], file_name: '', file_ext: 'json')
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
103
191
  end
104
192
 
105
193
  def createSuperManifest(manifest)
@@ -142,6 +230,7 @@ module CiCd
142
230
  data = {
143
231
  name: "#{mod}-manifest",
144
232
  module: "#{mod}-manifest",
233
+ component: mod,
145
234
  data: manifest_data,
146
235
  version: @vars[:build_ver],
147
236
  build: @vars[:build_num],
@@ -2,7 +2,7 @@ module CiCd
2
2
  module Builder
3
3
  module Manifest
4
4
  # manifest-builder version
5
- VERSION = '0.6.0'
5
+ VERSION = '0.6.2'
6
6
  MAJOR, MINOR, TINY = VERSION.split('.')
7
7
  PATCH = TINY
8
8
  end
@@ -17,8 +17,8 @@ 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 'cicd-builder', '>= 0.9.47', '< 1.1'
21
- gem.add_dependency 'chefrepo-builder', '>= 0.9.31', '< 1.1'
20
+ # gem.add_dependency 'cicd-builder', '>= 0.9.48', '< 1.1'
21
+ gem.add_dependency 'chefrepo-builder', '>= 0.9.32', '< 1.1'
22
22
  gem.add_dependency 'json', '>= 1.8.1', '< 1.9'
23
23
  gem.add_dependency 's3etag', '>= 0.0.1', '< 0.1.0'
24
24
  gem.add_dependency 'archive-tar-minitar', '= 0.5.2'
metadata CHANGED
@@ -1,42 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manifest-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.2
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-27 00:00:00.000000000 Z
11
+ date: 2015-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: cicd-builder
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 0.9.47
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '1.1'
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: 0.9.47
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '1.1'
33
13
  - !ruby/object:Gem::Dependency
34
14
  name: chefrepo-builder
35
15
  requirement: !ruby/object:Gem::Requirement
36
16
  requirements:
37
17
  - - ">="
38
18
  - !ruby/object:Gem::Version
39
- version: 0.9.31
19
+ version: 0.9.32
40
20
  - - "<"
41
21
  - !ruby/object:Gem::Version
42
22
  version: '1.1'
@@ -46,7 +26,7 @@ dependencies:
46
26
  requirements:
47
27
  - - ">="
48
28
  - !ruby/object:Gem::Version
49
- version: 0.9.31
29
+ version: 0.9.32
50
30
  - - "<"
51
31
  - !ruby/object:Gem::Version
52
32
  version: '1.1'