Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions lib/instance_agent/platform/linux_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def self.script_executable?(path)
end

def self.extract_tar(bundle_file, dst)
log(:debug, "extract_tar - dst : #{dst}")
FileUtils.mkdir_p(dst)
working_dir = FileUtils.pwd()
absolute_bundle_path = File.expand_path(bundle_file)
Expand All @@ -47,7 +48,18 @@ def self.extract_tar(bundle_file, dst)
FileUtils.cd(working_dir)
end

def self.extract_zip(bundle_file, dst)
log(:debug, "extract_zip - dst : #{dst}")
FileUtils.mkdir_p(dst)
working_dir = FileUtils.pwd()
absolute_bundle_path = File.expand_path(bundle_file)
FileUtils.cd(dst)
execute_zip_command("unzip -qo #{absolute_bundle_path}")
FileUtils.cd(working_dir)
end

def self.extract_tgz(bundle_file, dst)
log(:debug, "extract_tgz - dst : #{dst}")
FileUtils.mkdir_p(dst)
working_dir = FileUtils.pwd()
absolute_bundle_path = File.expand_path(bundle_file)
Expand Down Expand Up @@ -110,6 +122,23 @@ def self.execute_tar_command(cmd)
raise msg
end
end

private
def self.execute_zip_command(cmd)
log(:debug, "Executing #{cmd}")

output = `#{cmd} 2>&1`
exit_status = $?.exitstatus

log(:debug, "Command status: #{$?}")
log(:debug, "Command output: #{output}")

if exit_status != 0
msg = "Error extracting zip archive: #{exit_status}"
log(:error, msg)
raise msg
end
end

private
def self.log(severity, message)
Expand Down
25 changes: 25 additions & 0 deletions lib/instance_agent/platform/windows_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ def self.extract_tgz(bundle_file, dst)
Minitar.unpack(compressed, dst)
end

def self.extract_zip(bundle_file, dst)
log(:debug, "extract_zip - dst : #{dst}")
FileUtils.mkdir_p(dst)
working_dir = FileUtils.pwd()
absolute_bundle_path = File.expand_path(bundle_file)
execute_zip_command("powershell [System.Reflection.Assembly]::LoadWithPartialName(‘System.IO.Compression.FileSystem’); [System.IO.Compression.ZipFile]::ExtractToDirectory(‘#{absolute_bundle_path}’, ‘#{dst}’)")
end

def self.supports_process_groups?()
false
end
Expand Down Expand Up @@ -80,6 +88,23 @@ def self.delete_folder (dir)
end
end

private
def self.execute_zip_command(cmd)
log(:debug, "Executing #{cmd}")

output = `#{cmd} 2>&1`
exit_status = $?.exitstatus

log(:debug, "Command status: #{$?}")
log(:debug, "Command output: #{output}")

if exit_status != 0
msg = "Error extracting zip archive: #{exit_status}"
log(:debug, msg)
raise msg
end
end

private
def self.log(severity, message)
raise ArgumentError, "Unknown severity #{severity.inspect}" unless InstanceAgent::Log::SEVERITIES.include?(severity.to_s)
Expand Down
14 changes: 9 additions & 5 deletions lib/instance_agent/plugins/codedeploy/command_executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,15 @@ def unpack_bundle(cmd, bundle_file, deployment_spec)
elsif "tgz".eql? deployment_spec.bundle_type
InstanceAgent::Platform.util.extract_tgz(bundle_file, dst)
elsif "zip".eql? deployment_spec.bundle_type
Zip::File.open(bundle_file) do |zipfile|
zipfile.each do |f|
file_dst = File.join(dst, f.name)
FileUtils.mkdir_p(File.dirname(file_dst))
zipfile.extract(f, file_dst)
begin
InstanceAgent::Platform.util.extract_zip(bundle_file, dst)
rescue
Zip::File.open(bundle_file) do |zipfile|
zipfile.each do |f|
file_dst = File.join(dst, f.name)
FileUtils.mkdir_p(File.dirname(file_dst))
zipfile.extract(f, file_dst)
end
end
end
else
Expand Down