Skip to content

Commit

Permalink
Merge pull request #361 from aws/1.6.0
Browse files Browse the repository at this point in the history
1.6.0
  • Loading branch information
t0shiii authored Apr 19, 2023
2 parents 0efb955 + 4580c70 commit 3ba4279
Show file tree
Hide file tree
Showing 28 changed files with 483 additions and 251 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ name: Ruby

on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.6', '2.7']
ruby-version: ['2.7']
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
Expand All @@ -28,7 +28,3 @@ jobs:
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Run tests
run: bundle exec rake
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ source 'http://rubygems.org'
gemspec
gem "process_manager", "0.0.13", :path => "#{File.expand_path(__FILE__)}/../vendor/gems/process_manager-0.0.13"
gem "codedeploy-commands", "1.0.0", :path => "#{File.expand_path(__FILE__)}/../vendor/gems/codedeploy-commands-1.0.0"
gem "simple_pid", "0.2.1", :path => "#{File.expand_path(__FILE__)}/../vendor/gems/simple_pid-0.2.1"

group :test do
gem 'test-unit'
Expand Down
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ Rake::TestTask.new(:test) do |t|
t.libs << ['test', 'lib', 'test/helpers']

test_files = FileList.new("test/**/*_test.rb")
test_files.exclude("test/instance_agent/plugins/windows/*_test.rb")
t.test_files = test_files
t.verbose = true
end
task :default => [:version_tracking, :test]
task :release => [:version_tracking, :test]

desc "Run unit tests in spec/"
RSpec::Core::RakeTask.new(:spec)
RSpec::Core::RakeTask.new({:exclude_pattern =>'spec/aws/codedeploy/local/deployer_spec.rb'})
task :test => :spec

begin
Expand Down
2 changes: 1 addition & 1 deletion bin/codedeploy-agent
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

$:.unshift File.join(File.dirname(File.expand_path('..', __FILE__)), 'lib')

ruby_versions = ["3.0", "2.7", "2.6", "2.5", "2.4", "2.3", "2.2", "2.1", "2.0"]
ruby_versions = ["3.2", "3.1", "3.0", "2.7", "2.6", "2.5", "2.4", "2.3", "2.2", "2.1", "2.0"]
actual_ruby_version = RUBY_VERSION.split('.').map{|s|s.to_i}
left_bound = '2.0.0'.split('.').map{|s|s.to_i}
ruby_bin = nil
Expand Down
2 changes: 1 addition & 1 deletion bin/codedeploy-local
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ begin
rescue Docopt::Exit => e
puts e.message
exit(false)
rescue AWS::CodeDeploy::Local::CLIValidator::ValidationError,InstanceMetadata::InstanceMetadataError,SystemCallError,ArgumentError => e
rescue AWS::CodeDeploy::Local::CLIValidator::ValidationError,SystemCallError,ArgumentError => e
puts "ERROR: #{e.message}"
exit(false)
rescue Aws::Errors::MissingCredentialsError => e
Expand Down
70 changes: 39 additions & 31 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,39 @@
# than 2.0. Testing on multiple Ruby versions is required for
# changes to this part of the code.
##################################################################
class Proxy
instance_methods.each do |m|
undef_method m unless m =~ /(^__|^send$|^object_id$)/

class LoggerWrapper
def initialize(loggers)
@loggers = loggers
end

def initialize(*targets)
@targets = targets
def debug(message)
@loggers.each do |logger|
logger.debug(message)
end
end

def path
@targets.map do |target|
if target.respond_to?(:path)
target.__send__(:path)
else
# default to to_s since it's just used as a label for log statements.
target.__send__(:to_s)
end
def error(message)
@loggers.each do |logger|
logger.error(message)
end
end

protected
def info(message)
@loggers.each do |logger|
logger.info(message)
end
end

def method_missing(name, *args, &block)
@targets.map do |target|
target.__send__(name, *args, &block)
def level(message)
@loggers.each do |logger|
logger.level = message
end
end

def warn(message)
@loggers.each do |logger|
logger.warn(message)
end
end
end
Expand All @@ -40,17 +48,17 @@ require 'logger'

if($stdout.isatty)
# if we are being run in a terminal, log to stdout and the log file.
@log = Logger.new(Proxy.new(File.open(log_file_path, 'a+'), $stdout))
@log = LoggerWrapper.new([Logger.new(log_file_path), Logger.new($stdout)])
@log.level(Logger::INFO)
else
# keep at most 2MB of old logs rotating out 1MB at a time
@log = Logger.new(log_file_path, 2, 1048576)
@log.level = Logger::INFO
# make sure anything coming out of ruby ends up in the log file
$stdout.reopen(log_file_path, 'a+')
$stderr.reopen(log_file_path, 'a+')
end

@log.level = Logger::INFO

require 'net/http'

# This class is copied (almost directly) from lib/instance_metadata.rb
Expand Down Expand Up @@ -128,7 +136,7 @@ class IMDS
Net::HTTP.start(IP_ADDRESS, 80, :read_timeout => 10, :open_timeout => 10) do |http|
response = http.request(request)
if block_given?
yield(response)
yield(response)
elsif response.kind_of? Net::HTTPSuccess
response.body
else
Expand All @@ -153,7 +161,7 @@ class IMDS
end

class S3Bucket
# Split out as older versions of ruby dont like multi entry attr
# Split out as older versions of ruby dont like multi entry attr
attr :domain
attr :region
attr :bucket
Expand Down Expand Up @@ -203,8 +211,8 @@ to check for a running agent.
To use a HTTP proxy, specify --proxy followed by the proxy server
defined by http://hostname:port
This install script needs Ruby version 2.x installed as a prerequisite.
Currently recommended Ruby versions are 2.0.0, 2.1.8, 2.2.4, 2.3, 2.4, 2.5, 2.6 and 2.7.
This install script needs Ruby versions 2.x or 3.x installed as a prerequisite.
Currently recommended Ruby versions are 2.0.0, 2.1.8, 2.2.4, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, and 3.2
If multiple Ruby versions are installed, the default ruby version will be used.
If the default ruby version does not satisfy requirement, the newest version will be used.
If you do not have a supported Ruby version installed, please install one of them first.
Expand All @@ -213,7 +221,7 @@ EOF
end

def supported_ruby_versions
['3.0', '2.7', '2.6', '2.5', '2.4', '2.3', '2.2', '2.1', '2.0']
['3.2','3.1','3.0', '2.7', '2.6', '2.5', '2.4', '2.3', '2.2', '2.1', '2.0']
end

# check ruby version, only version 2.x 3.x works
Expand All @@ -231,8 +239,8 @@ EOF
if(File.exist?("/usr/bin/ruby#{version}"))
return "/usr/bin/ruby#{version}"
elsif (File.symlink?("/usr/bin/ruby#{version}"))
@log.error("The symlink /usr/bin/ruby#{version} exists, but it's linked to a non-existent directory or non-executable file.")
exit(1)
@log.error("The symlink /usr/bin/ruby#{version} exists, but it's linked to a non-existent directory or non-executable file.")
exit(1)
end
end

Expand Down Expand Up @@ -299,10 +307,10 @@ EOF
# change interpreter when symlink /usr/bin/ruby2.x exists, but running with non-supported ruby version
actual_ruby_version = RUBY_VERSION.split('.').map{|s|s.to_i}
left_bound = '2.0.0'.split('.').map{|s|s.to_i}
right_bound = '3.0.0'.split('.').map{|s|s.to_i}
right_bound = '3.2.1'.split('.').map{|s|s.to_i}
if (actual_ruby_version <=> left_bound) < 0
if(!@reexeced)
@log.info("The current Ruby version is not 2.x or 3.0.x! Restarting the installer with #{ruby_interpreter_path}")
@log.info("The current Ruby version is not 2.x or 3.x! Restarting the installer with #{ruby_interpreter_path}")
exec("#{ruby_interpreter_path}", __FILE__, '--re-execed' , *@args)
else
unsupported_ruby_version_error
Expand Down Expand Up @@ -393,7 +401,7 @@ EOF
exceptions = [OpenURI::HTTPError, OpenSSL::SSL::SSLError]
begin
uri.open(:ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER, :redirect => true, :read_timeout => 120, :proxy => @http_proxy) do |s3|
package_file.write(s3.read)
package_file.write(s3.read)
end
rescue *exceptions => e
@log.warn("Could not find package to download at '#{uri.to_s}' - Retrying... Attempt: '#{retries.to_s}'")
Expand All @@ -406,7 +414,7 @@ EOF
exit(1)
end
end
end
end

def get_version_file_from_s3(s3_bucket, key)
@log.info("Downloading version file from bucket #{s3_bucket.bucket} and key #{key}...")
Expand Down
7 changes: 3 additions & 4 deletions codedeploy_agent.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = 'aws_codedeploy_agent'
spec.version = '1.5.0'
spec.version = '1.6.0'
spec.summary = 'Packages AWS CodeDeploy agent libraries'
spec.description = 'AWS CodeDeploy agent is responsible for doing the actual work of deploying software on an individual EC2 instance'
spec.author = 'Amazon Web Services'
Expand All @@ -9,16 +9,15 @@ Gem::Specification.new do |spec|
spec.bindir = ['bin']
spec.require_paths = ['lib']
spec.license = 'Apache-2.0'
spec.required_ruby_version = '~> 2.0'
spec.required_ruby_version = '>= 2.7.0'

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.3.0')
spec.add_dependency('logging', '~> 1.8')
spec.add_dependency('logging', '~> 2.2')
spec.add_dependency('aws-sdk-core', '~> 3')
spec.add_dependency('aws-sdk-s3', '~> 1')
spec.add_dependency('simple_pid', '~> 0.2.1')
spec.add_dependency('docopt', '~> 0.5.0')
spec.add_dependency('concurrent-ruby', '~> 1.1.9')

Expand Down
6 changes: 3 additions & 3 deletions lib/aws/codedeploy/local/cli_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def validate(args)
raise ValidationError.new("location #{location} cannot be http, only encrypted (https) url endpoints supported")
end

if (uri.scheme != 'https' && uri.scheme != 's3' && !File.exists?(location))
if (uri.scheme != 'https' && uri.scheme != 's3' && !File.exist?(location))
raise ValidationError.new("location #{location} is specified as a file or directory which does not exist")
end

Expand All @@ -41,10 +41,10 @@ def validate(args)

if (type == 'directory' && (uri.scheme != 'https' && uri.scheme != 's3' && File.directory?(location)))
appspec_filename = args['--appspec-filename']
if !appspec_filename.nil? && !File.exists?("#{location}/#{appspec_filename}")
if !appspec_filename.nil? && !File.exist?("#{location}/#{appspec_filename}")
raise ValidationError.new("Expecting appspec file at location #{location}/#{appspec_filename} but it is not found there. Please either run the CLI from within a directory containing the #{appspec_filename} file or specify a bundle location containing an #{appspec_filename} file in its root directory")
end
if appspec_filename.nil? && !File.exists?("#{location}/appspec.yml") && !File.exists?("#{location}/appspec.yaml")
if appspec_filename.nil? && !File.exist?("#{location}/appspec.yml") && !File.exist?("#{location}/appspec.yaml")
raise ValidationError.new("Expecting appspec file at location #{location}/appspec.yml or #{location}/appspec.yaml but it is not found there. Please either run the CLI from within a directory containing the appspec.yml or appspec.yaml file or specify a bundle location containing an appspec.yml or appspec.yaml file in its root directory")
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/instance_agent/log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class InstanceAgent::DeploymentLog

def initialize
deployment_logs_dir = File.join(InstanceAgent::Config.config[:root_dir], 'deployment-logs')
FileUtils.mkdir_p(deployment_logs_dir) unless File.exists? deployment_logs_dir
FileUtils.mkdir_p(deployment_logs_dir) unless File.exist? deployment_logs_dir
@deployment_log ||= Logger.new(File.join(deployment_logs_dir, "#{InstanceAgent::Config.config[:program_name]}-deployments.log"), 8, 64 * 1024 * 1024)
@deployment_log.formatter = proc do |severity, datetime, progname, msg|
"[#{datetime.strftime('%Y-%m-%d %H:%M:%S.%L')}] #{msg}\n"
Expand Down
6 changes: 3 additions & 3 deletions lib/instance_agent/plugins/codedeploy/hook_executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def script_error_prefix(script_location, script_run_as_user)
private
def create_script_log_file_if_needed
script_log_file_location = File.join(@current_deployment_root_dir, ScriptLog::SCRIPT_LOG_FILE_RELATIVE_LOCATION)
if(!File.exists?(script_log_file_location))
if(!File.exist?(script_log_file_location))
unless File.directory?(File.dirname(script_log_file_location))
FileUtils.mkdir_p(File.dirname(script_log_file_location))
end
Expand All @@ -232,7 +232,7 @@ def script_absolute_path(script)
def parse_app_spec
app_spec_location = File.join(@deployment_archive_dir, @app_spec_path)
log(:debug, "Checking for app spec in #{app_spec_location}")
unless File.exists?(app_spec_location)
unless File.exist?(app_spec_location)
raise <<-MESSAGE.gsub(/^[\s\t]*/, '').gsub(/\s*\n/, ' ').strip
The CodeDeploy agent did not find an AppSpec file within the unpacked revision directory at revision-relative path "#{@app_spec_path}".
The revision was unpacked to directory "#{@deployment_archive_dir}", and the AppSpec file was expected but not found at path
Expand All @@ -249,7 +249,7 @@ def select_correct_deployment_root_dir(current_deployment_root_dir, last_success
hook_deployment_mapping = mapping_between_hooks_and_deployments
if(select_correct_mapping_for_hooks == LAST_SUCCESSFUL_DEPLOYMENT && !File.exist?(File.join(@deployment_root_dir, 'deployment-archive')))
@deployment_root_dir = last_successful_deployment_root_dir
elsif(select_correct_mapping_for_hooks == MOST_RECENT_DEPLOYMENT && !File.exists?(File.join(@deployment_root_dir, 'deployment-archive')))
elsif(select_correct_mapping_for_hooks == MOST_RECENT_DEPLOYMENT && !File.exist?(File.join(@deployment_root_dir, 'deployment-archive')))
@deployment_root_dir = most_recent_deployment_dir
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/instance_agent/plugins/codedeploy/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def initialize(opts = {})
def install(deployment_group_id, application_specification)
cleanup_file = File.join(deployment_instructions_dir, "#{deployment_group_id}-cleanup")

if File.exists?(cleanup_file)
if File.exist?(cleanup_file)
commands = InstanceAgent::Plugins::CodeDeployPlugin::InstallInstruction.parse_remove_commands(File.read(cleanup_file))
commands.each do |cmd|
cmd.execute
Expand Down Expand Up @@ -116,7 +116,7 @@ def generate_directory_copy(i, absolute_source_path, destination, file_exists_be

private
def generate_normal_copy(i, absolute_source_path, destination, file_exists_behavior)
if File.exists?(destination)
if File.exist?(destination)
case file_exists_behavior
when "DISALLOW"
raise "The deployment failed because a specified file already exists at this location: #{destination}"
Expand All @@ -136,7 +136,7 @@ def generate_normal_copy(i, absolute_source_path, destination, file_exists_behav
def fill_in_missing_ancestors(i, destination)
missing_ancestors = []
parent_dir = File.dirname(destination)
while !File.exists?(parent_dir) &&
while !File.exist?(parent_dir) &&
parent_dir != "." && parent_dir != "/"
missing_ancestors.unshift(parent_dir)
parent_dir = File.dirname(parent_dir)
Expand Down
2 changes: 1 addition & 1 deletion lib/instance_agent/plugins/codedeploy/onpremise_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class OnPremisesConfig
def self.configure
file_path = InstanceAgent::Config.config[:on_premises_config_file]
file_config = nil
if File.exists?(file_path) && File.readable?(file_path)
if File.readable?(file_path)
begin
file_config = YAML.load(File.read(file_path)).symbolize_keys
rescue
Expand Down
Loading

0 comments on commit 3ba4279

Please sign in to comment.