lib/cicd/builder/manifest/mixlib/build.rb in manifest-builder-0.1.5 vs lib/cicd/builder/manifest/mixlib/build.rb in manifest-builder-0.2.0
- old
+ new
@@ -97,10 +97,17 @@
else
version.gsub!(%r'^[a-zA-Z\-.]+','')
end
if version.empty?
version = @vars[:build_ver]
+ else
+ uri,ver = File.split(path)
+ if version =~ %r'^#{ver}' and version =~ %r'^(\d+\.){3}'
+ build = version.dup
+ version = ver
+ build = build.gsub(%r'^#{version}(\.|-)*','')
+ end
end
if build == 0 or build.empty?
build = @vars[:build_num]
end
else
@@ -121,10 +128,11 @@
@repo = clazz.new(self)
if @vars[:return_code] == 0
lines = []
@vars[:artifacts] = []
+ # Deal with all artifacts of each component
@vars[:components].each { |comp|
artifact, path, version, build = parseComponent(comp)
require 'uri'
begin
@@ -137,17 +145,20 @@
bucket.objects(prefix: key).each do |object|
if artifact.empty? or (not artifact.empty? and object.key =~ %r'#{key}#{artifact}')
objects << object
end
end
+ local_dir = File.join(@vars[:local_dirs]['artifacts'],comp[0], '')
+ Dir.mkdir(local_dir, 0700) unless File.directory?(local_dir)
+ artifacts = []
+ changed = false
+ # 1 or more objects on the key/ path
if objects.size > 0
lines << "#{comp[0]}:#{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 "\t#{object.key}"
- local_dir = File.join(@vars[:local_dirs]['artifacts'],comp[0], '')
- Dir.mkdir(local_dir, 0700) unless File.directory?(local_dir)
local = File.join(local_dir,File.basename(object.key))
etag = object.etag.gsub(%r/['"]/, '')
download = if File.exists?(local)
stat = File.stat(local)
check = calcLocalETag(etag, local, stat.size)
@@ -168,15 +179,45 @@
# body.read(nil)
# end
# IO.binwrite(local, body)
@logger.info "\t\tdone"
check = calcLocalETag(etag, local)
- @logger.error "\tETag different: #{etag} != #{check}" unless check == etag
+ unless check.eql?(etag)
+ @logger.info "\tETag different: #{etag} != #{check}"
+ changed = true
+ end
else
@logger.info "\t\tunchanged"
end
- addArtifact(@vars[:artifacts], local, local_dir, { name: comp[0], build: build, version: version, file: local})
+ artifacts << local
end
+ # The local file will be 1 artifact or an archive of the local artifacts when artifacts.size > 1
+ local = if artifacts.size > 0
+ if artifacts.size > 1
+ begin
+ require 'zlib'
+ require 'archive/tar/minitar'
+ file = File.join(local_dir, "#{comp[0]}-#{version}.tar.gz")
+ if changed or not File.exists?(file)
+ output = File.open(file, 'wb')
+ output = Zlib::GzipWriter.new(output, Zlib::BEST_COMPRESSION, Zlib::RLE)
+ Dir.chdir(local_dir) do
+ Archive::Tar::Minitar.pack(artifacts.map{|f| f.gsub(%r'^#{local_dir}','')}, output, false )
+ end
+ end
+ file
+ rescue Exception => e
+ @logger.error "Artifact error: #{file} #{e.class.name} #{e.message}"
+ raise e
+ ensure
+ output.close if output and not output.closed?
+ end
+ else
+ artifacts[0]
+ end
+ else
+ end
+ addArtifact(@vars[:artifacts], local, local_dir, { name: comp[0], build: build, version: version, file: local})
else
@logger.fatal "Artifact not found: s3://#{name}/#{key}#{artifact}"
@vars[:return_code] = Errors::ARTIFACT_NOT_FOUND
end
# rescue Aws::S3::Errors::NotFound => e