Skip to content
Closed
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
2 changes: 1 addition & 1 deletion codedeploy_agent-1.1.0.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
18 changes: 13 additions & 5 deletions lib/instance_agent/platform/linux_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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`
Expand All @@ -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
Expand Down
26 changes: 16 additions & 10 deletions lib/instance_agent/plugins/codedeploy/command_executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down