lib/cicd/builder/manifest/mixlib/build.rb in manifest-builder-0.2.0 vs lib/cicd/builder/manifest/mixlib/build.rb in manifest-builder-0.3.0
- old
+ new
@@ -145,42 +145,41 @@
bucket.objects(prefix: key).each do |object|
if artifact.empty? or (not artifact.empty? and object.key =~ %r'#{key}#{artifact}')
objects << object
end
end
+ @logger.debug "S3://#{name}:#{key} has #{objects.size} objects"
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}"
+ @logger.info "\tchecking #{object.key}"
local = File.join(local_dir,File.basename(object.key))
etag = object.etag.gsub(%r/['"]/, '')
download = if File.exists?(local)
+ @logger.debug "\t\tchecking etag on #{local}"
stat = File.stat(local)
check = calcLocalETag(etag, local, stat.size)
if etag != check or object.size != stat.size or object.last_modified > stat.mtime
- @logger.info "\t#{etag} != \"#{check}\" #{object.size} != #{stat.size} #{object.last_modified} > #{stat.mtime}"
+ @logger.debug "\t\t#{etag} != \"#{check}\" #{object.size} != #{stat.size} #{object.last_modified} > #{stat.mtime}"
true
else
+ @logger.debug "\t\tmatched #{etag}"
false
end
else
true
end
if download
@logger.info "\t\tdownload #{object.size} bytes"
response = object.get(:response_target => local)
- # body = response.body
- # body = if body.is_a?(IO) or body.is_a?(StringIO)
- # body.read(nil)
- # end
- # IO.binwrite(local, body)
+ File.utime(response.last_modified, response.last_modified, local)
@logger.info "\t\tdone"
check = calcLocalETag(etag, local)
unless check.eql?(etag)
@logger.info "\tETag different: #{etag} != #{check}"
changed = true
@@ -192,32 +191,38 @@
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")
+ # require 'zlib'
+ # require 'archive/tar/minitar'
+ file = File.join(local_dir, "#{comp[0]}-#{version}.zip")
if changed or not File.exists?(file)
- output = File.open(file, 'wb')
- output = Zlib::GzipWriter.new(output, Zlib::BEST_COMPRESSION, Zlib::RLE)
+ # 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
+ zipped_files = artifacts.map{|f| f.gsub(%r'^#{local_dir}','')}.join(' ')
Dir.chdir(local_dir) do
- Archive::Tar::Minitar.pack(artifacts.map{|f| f.gsub(%r'^#{local_dir}','')}, output, false )
+ res = %x(zip -o9X #{file} #{zipped_files})
end
+ raise "Failed to zip #{file} containting #{zipped_files}" unless $?.exitstatus == 0
end
file
rescue Exception => e
@logger.error "Artifact error: #{file} #{e.class.name} #{e.message}"
+ File.unlink(file)
raise e
- ensure
- output.close if output and not output.closed?
+ # 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})
+ addArtifact(@vars[:artifacts], local, local_dir, { module: comp[0], 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