Skip to content

Commit 8fe48b2

Browse files
aj-awsMichael Choi
authored andcommitted
Update Agent Install Script to support Ruby 3.1 and 3.2
1 parent 67a2faf commit 8fe48b2

File tree

2 files changed

+40
-32
lines changed

2 files changed

+40
-32
lines changed

bin/codedeploy-agent

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
ruby_versions = ["3.0", "2.7", "2.6", "2.5", "2.4", "2.3", "2.2", "2.1", "2.0"]
5+
ruby_versions = ["3.2", "3.1", "3.0", "2.7", "2.6", "2.5", "2.4", "2.3", "2.2", "2.1", "2.0"]
66
actual_ruby_version = RUBY_VERSION.split('.').map{|s|s.to_i}
77
left_bound = '2.0.0'.split('.').map{|s|s.to_i}
88
ruby_bin = nil

bin/install

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,39 @@
55
# than 2.0. Testing on multiple Ruby versions is required for
66
# changes to this part of the code.
77
##################################################################
8-
class Proxy
9-
instance_methods.each do |m|
10-
undef_method m unless m =~ /(^__|^send$|^object_id$)/
8+
9+
class LoggerWrapper
10+
def initialize(loggers)
11+
@loggers = loggers
1112
end
1213

13-
def initialize(*targets)
14-
@targets = targets
14+
def debug(message)
15+
@loggers.each do |logger|
16+
logger.debug(message)
17+
end
1518
end
1619

17-
def path
18-
@targets.map do |target|
19-
if target.respond_to?(:path)
20-
target.__send__(:path)
21-
else
22-
# default to to_s since it's just used as a label for log statements.
23-
target.__send__(:to_s)
24-
end
20+
def error(message)
21+
@loggers.each do |logger|
22+
logger.error(message)
2523
end
2624
end
2725

28-
protected
26+
def info(message)
27+
@loggers.each do |logger|
28+
logger.info(message)
29+
end
30+
end
2931

30-
def method_missing(name, *args, &block)
31-
@targets.map do |target|
32-
target.__send__(name, *args, &block)
32+
def level(message)
33+
@loggers.each do |logger|
34+
logger.level = message
35+
end
36+
end
37+
38+
def warn(message)
39+
@loggers.each do |logger|
40+
logger.warn(message)
3341
end
3442
end
3543
end
@@ -40,17 +48,17 @@ require 'logger'
4048

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

52-
@log.level = Logger::INFO
53-
5462
require 'net/http'
5563

5664
# This class is copied (almost directly) from lib/instance_metadata.rb
@@ -128,7 +136,7 @@ class IMDS
128136
Net::HTTP.start(IP_ADDRESS, 80, :read_timeout => 10, :open_timeout => 10) do |http|
129137
response = http.request(request)
130138
if block_given?
131-
yield(response)
139+
yield(response)
132140
elsif response.kind_of? Net::HTTPSuccess
133141
response.body
134142
else
@@ -153,7 +161,7 @@ class IMDS
153161
end
154162

155163
class S3Bucket
156-
# Split out as older versions of ruby dont like multi entry attr
164+
# Split out as older versions of ruby dont like multi entry attr
157165
attr :domain
158166
attr :region
159167
attr :bucket
@@ -203,8 +211,8 @@ to check for a running agent.
203211
To use a HTTP proxy, specify --proxy followed by the proxy server
204212
defined by http://hostname:port
205213
206-
This install script needs Ruby version 2.x installed as a prerequisite.
207-
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.
214+
This install script needs Ruby versions 2.x or 3.x installed as a prerequisite.
215+
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
208216
If multiple Ruby versions are installed, the default ruby version will be used.
209217
If the default ruby version does not satisfy requirement, the newest version will be used.
210218
If you do not have a supported Ruby version installed, please install one of them first.
@@ -213,7 +221,7 @@ EOF
213221
end
214222

215223
def supported_ruby_versions
216-
['3.0', '2.7', '2.6', '2.5', '2.4', '2.3', '2.2', '2.1', '2.0']
224+
['3.2','3.1','3.0', '2.7', '2.6', '2.5', '2.4', '2.3', '2.2', '2.1', '2.0']
217225
end
218226

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

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

411419
def get_version_file_from_s3(s3_bucket, key)
412420
@log.info("Downloading version file from bucket #{s3_bucket.bucket} and key #{key}...")

0 commit comments

Comments
 (0)