lib/cicd/builder/manifest/mixlib/build.rb in manifest-builder-0.6.0 vs lib/cicd/builder/manifest/mixlib/build.rb in manifest-builder-0.6.2
- old
+ new
@@ -86,22 +86,23 @@
[version,build]
end
# ---------------------------------------------------------------------------------------------------------------
def getVersionBuild(path,artifact,comp)
+ cname,cdata = comp
version,build = File.split(path)
if build.match(%r'^\d+$') and version.match(%r'/?\d+\.\d+\.?\d*$') # Hole in one!
version = File.basename(version)
else
if build.match(VER_RGX)
version = build
build = ''
else
- version = comp[1][:build].nil? ? '' : ( comp[1][:build] > 0 ? build.to_s : '' )
+ version = cdata[:build].nil? ? '' : ( cdata[:build] > 0 ? build.to_s : '' )
end
unless version.match(VER_RGX)
- version = comp[1][:version] || ''
+ version = cdata[:version] || ''
end
ver,bld = getVersionBuildFromName(artifact)
if version.empty?
version,build = [ver,bld]
if version.empty?
@@ -145,11 +146,11 @@
build.gsub!(/^#{version}\.?/, '')
end
end
end
unless build.match(%r'^[1-9]\d*$')
- build = comp[1][:build]
+ build = cdata[:build]
build = @vars[:build_num] if (build.nil? or build.empty? or build.to_i == 0)
end
end
[version,build]
end
@@ -219,38 +220,71 @@
private
# ---------------------------------------------------------------------------------------------------------------
def processComponent(comp, lines)
artifact, path, version, build = parseComponent(comp)
+ cname,cdata = comp
require 'uri'
+ require 'digest'
begin
key, name, objects = getObjects(artifact, path)
- local_dir = File.join(@vars[:local_dirs]['artifacts'], comp[0], '')
+ local_dir = File.join(@vars[:local_dirs]['artifacts'], cname, '')
Dir.mkdir(local_dir, 0700) unless File.directory?(local_dir)
artifacts = []
+ sha256 = {}
changed = false
# 1 or more objects on the key/ path
if objects.size > 0
- lines << "#{comp[0]}:#{artifact} v#{version} b#{build} - #{path}"
+ lines << "#{cname}:#{artifact} v#{version} b#{build} - #{path}"
# When we start pulling the artifacts then everything that is build 0 get this build number, in fact all artifacts get this build number!
objects.each do |object|
@logger.info "\tchecking #{object.key}"
- local = File.join(local_dir, File.basename(object.key))
+ base = File.basename(object.key)
+ local = File.join(local_dir, base)
etag = object.etag.gsub(%r/['"]/, '')
download = shouldDownload?(etag, local, object)
if download
changed = doDownload(etag, local, object)
else
@logger.info "\t\tunchanged"
end
+ sha256[base] = nil
+ if cdata[:sha256]
+ hd = Digest::SHA256.file(local).hexdigest
+ sha256[base] = hd == cdata[:sha256] ? true : hd
+ end
+
artifacts << local
end
# The local file will be 1 artifact or an archive of the local artifacts when artifacts.size > 1
if artifacts.size > 0
- local = getLocalArtifact(artifacts, changed, comp, local_dir, version)
- addArtifact(@vars[:artifacts], local, local_dir, {module: comp[0], name: comp[0], build: build, version: version, file: local})
+ artifacts.each do |local|
+ base = File.basename(local)
+ if sha256[base].is_a?(String)
+ msg = "Artifact checksum is invalid or manifest is incorrect. Artifact: s3://#{name}/#{key}#{artifact}, SHA256: Manifest=#{cdata[:sha256]}, Actual=#{sha256[base]}"
+ if ENV['ENFORCE_CHECKSUMS'] and ENV['ENFORCE_CHECKSUMS'].downcase =~ %r/^(yes|on|set|1|enable|active|enforced?)$/
+ @logger.fatal msg
+ @vars[:return_code] = Errors::ARTIFACT_CHECKSUM_BAD
+ else
+ @logger.warn msg
+ end
+ end
+ end
+ if 0 == @vars[:return_code]
+ local = getLocalArtifact(artifacts, changed, comp, local_dir, version)
+ base = File.basename(local)
+ addArtifact(@vars[:artifacts], local, local_dir, {
+ component: cname,
+ module: cname,
+ name: cname,
+ build: build,
+ version: version,
+ file: local,
+ sha256: (sha256.keys.include?(base)) ? (sha256[base].is_a?(TrueClass) ? cdata[:sha256] : sha256[base]) : Digest::SHA256.file(local).hexdigest
+ })
+ end
end
else
@logger.fatal "Artifact not found: s3://#{name}/#{key}#{artifact}"
@vars[:return_code] = Errors::ARTIFACT_NOT_FOUND
end
@@ -310,13 +344,14 @@
end
end
# ---------------------------------------------------------------------------------------------------------------
def getLocalArtifact(artifacts, changed, comp, local_dir, version)
+ cname,cdata = comp
if artifacts.size > 1
begin
- file = File.join(local_dir, "#{comp[0]}-#{version}.zip")
+ file = File.join(local_dir, "#{cname}-#{version}.zip")
if changed or not File.exists?(file)
zipped_files = artifacts.map { |f| f.gsub(%r'^#{local_dir}', '') }.join(' ')
Dir.chdir(local_dir) do
res = %x(zip -o9X #{file} #{zipped_files} 2>&1)
@logger.info res
@@ -334,26 +369,27 @@
end
end
# ---------------------------------------------------------------------------------------------------------------
def parseComponent(comp)
- if comp[1][:url]
- path, artifact = File.split(comp[1][:url])
+ cname,cdata = comp
+ if cdata[:url]
+ path, artifact = File.split(cdata[:url])
version, build = getVersionBuild(path, artifact, comp)
- elsif comp[1][:base_url]
+ elsif cdata[:base_url]
artifact = ''
- if comp[1][:build].nil?
+ if cdata[:build].nil?
# noinspection RubyUnusedLocalVariable
- version, build = comp[1][:version].split(%r'-')
+ version, build = cdata[:version].split(%r'-')
# noinspection RubyUnusedLocalVariable
- path = File.join(comp[1][:base_url], comp[1][:version])
+ path = File.join(cdata[:base_url], cdata[:version])
else
- version, build = [comp[1][:version], comp[1][:build]]
- path = File.join(comp[1][:base_url], comp[1][:version], comp[1][:build])
+ version, build = [cdata[:version], cdata[:build]]
+ path = File.join(cdata[:base_url], cdata[:version], cdata[:build])
end
else
- path = ''
- artifact = ''
+ path = ''
+ artifact = ''
version, build = getVersionBuild(path, artifact, comp)
end
return artifact, path, version, build
end