diff --git a/codedeploy_agent-1.1.0.gemspec b/codedeploy_agent-1.1.0.gemspec index f86b6d25..567bac07 100644 --- a/codedeploy_agent-1.1.0.gemspec +++ b/codedeploy_agent-1.1.0.gemspec @@ -12,7 +12,7 @@ Gem::Specification.new do |spec| spec.add_dependency('gli', '~> 2.5') spec.add_dependency('json_pure', '~> 1.6') spec.add_dependency('archive-tar-minitar', '~> 0.5.2') - spec.add_dependency('rubyzip', '~> 1.1.0') + spec.add_dependency('rubyzip', '~> 1.2.1') spec.add_dependency('rake', '~> 0.9') spec.add_dependency('logging', '~> 1.8') spec.add_dependency('aws-sdk-core', '~> 2.7.1') diff --git a/lib/instance_agent/platform/linux_util.rb b/lib/instance_agent/platform/linux_util.rb index 602d7e34..49dac028 100644 --- a/lib/instance_agent/platform/linux_util.rb +++ b/lib/instance_agent/platform/linux_util.rb @@ -25,7 +25,7 @@ def self.prepare_script_command(script, absolute_cmd_path) end # If neither sudo or runas is specified, execute the - # command as the code deploy agent user + # command as the code deploy agent user absolute_cmd_path end @@ -50,7 +50,15 @@ def self.extract_tgz(bundle_file, dst) FileUtils.mkdir_p(dst) working_dir = FileUtils.pwd() FileUtils.cd(dst) - execute_tar_command("/bin/tar -zxpsf #{bundle_file}") + execute_command("/bin/tar -zxpsf #{bundle_file}") + FileUtils.cd(working_dir) + end + + def self.extract_zip(bundle_file, dst) + FileUtils.mkdir_p(dst) + working_dir = FileUtils.pwd() + FileUtils.cd(dst) + execute_command("/usr/sbin/unzip #{bundle_file}") FileUtils.cd(working_dir) end @@ -65,9 +73,9 @@ def self.codedeploy_version_file def self.fallback_version_file "/opt/codedeploy-agent" end - + private - def self.execute_tar_command(cmd) + def self.execute_command(cmd) log(:debug, "Executing #{cmd}") output = `#{cmd} 2>&1` @@ -77,7 +85,7 @@ def self.execute_tar_command(cmd) log(:debug, "Command output: #{output}") if exit_status != 0 - msg = "Error extracting tar archive: #{exit_status}" + msg = "Error extracting archive: #{exit_status}" log(:error, msg) raise msg end diff --git a/lib/instance_agent/plugins/codedeploy/command_executor.rb b/lib/instance_agent/plugins/codedeploy/command_executor.rb index 216b6ec5..918d8aab 100644 --- a/lib/instance_agent/plugins/codedeploy/command_executor.rb +++ b/lib/instance_agent/plugins/codedeploy/command_executor.rb @@ -166,7 +166,7 @@ def last_successful_deployment_dir(deployment_group) return unless File.exist? last_successful_install_file_location File.open last_successful_install_file_location do |f| return f.read.chomp - end + end end private @@ -175,7 +175,7 @@ def most_recent_deployment_dir(deployment_group) return unless File.exist? most_recent_install_file_location File.open most_recent_install_file_location do |f| return f.read.chomp - end + end end private @@ -199,7 +199,7 @@ def most_recent_install_file_path(deployment_group) def download_from_s3(deployment_spec, bucket, key, version, etag) log(:debug, "Downloading artifact bundle from bucket '#{bucket}' and key '#{key}', version '#{version}', etag '#{etag}'") region = ENV['AWS_REGION'] || InstanceMetadata.region - + proxy_uri = nil if InstanceAgent::Config.config[:proxy_uri] proxy_uri = URI(InstanceAgent::Config.config[:proxy_uri]) @@ -314,12 +314,18 @@ 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 + # First try to unzip with pure Ruby. + 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 + rescue + # Fallback to platform-specific tools. + InstanceAgent::Platform.util.extract_zip(bundle_file, dst) end else # If the bundle was a generated through a Sabini Repository @@ -362,7 +368,7 @@ def update_most_recent_install(deployment_spec) File.open(most_recent_install_file_path(deployment_spec.deployment_group_id), 'w+') do |f| f.write deployment_root_dir(deployment_spec) end - end + end private def cleanup_old_archives(deployment_spec) @@ -374,7 +380,7 @@ def cleanup_old_archives(deployment_spec) full_path_deployment_archives = deployment_archives.map{ |f| File.join(ProcessManager::Config.config[:root_dir], deployment_group, f)} full_path_deployment_archives.delete(deployment_root_dir(deployment_spec)) - + extra = full_path_deployment_archives.size - @archives_to_retain + 1 return unless extra > 0