Skip to content

Commit 17786db

Browse files
author
Alena Kastsiukavets
committed
#Add -v option to install\update agent command
# Why is this change needed? Customers should be able to install custom version of the agent if they need to # How does it address the issue? Add '-v', '--version' option to install\update command: 1. Windows: ``` powershell.exe -Command Read-S3Object -BucketName aws-codedeploy-us-east-1 -Key releases/codedeploy-agent-1.0.1.1095.msi -File c:\temp\codedeploy-agent.msi ``` test: `sc qdescription codedeployagent` output: CodeDeploy Host Agent Service v1.0.1.1095 2. Linux: ``` sudo ./install auto -v releases/codedeploy-agent-1.0-1.1095.noarch.rpm ``` test `sudo yum info codedeploy-agent` output: *Release : 1.1095* ``` sudo ./update auto --version releases/codedeploy-agent-1.0-1.1352.noarch.rpm ``` test `sudo yum info codedeploy-agent` output: *Release : 1.1352* 3. Ubuntu: ``` sudo ./install auto -v releases/codedeploy-agent_1.0-1.1095_all.deb ``` test `sudo dpkg -s codedeploy-agent` output: *Version: 1.0-1.1095* ``` sudo ./update auto --version releases/codedeploy-agent_1.0-1.1352_all.deb ``` test `sudo dpkg -s codedeploy-agent` output: *Version: 1.0-1.1352* # How was this tested ? * On instances with the commands above * Linux: ``` sudo ./update auto ``` test: `sudo yum info codedeploy-agent` output: *Release : 1.1597* ``` sudo ./install auto ``` test `sudo yum info codedeploy-agent` output: *Release : 1.1597* * Ubuntu: ``` sudo ./update auto ``` test: `sudo dpkg -s codedeploy-agent` output: *Version: 1.0-1.1597* ``` sudo ./install auto ``` test `sudo dpkg -s codedeploy-agent` output: *Version: 1.0-1.1597* cr https://code.amazon.com/reviews/CR-20081000
1 parent e99aa6f commit 17786db

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

bin/install

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,16 @@ EOF
135135
@sanity_check = false
136136
@reexeced = false
137137
@http_proxy = nil
138+
@target_version_arg = nil
138139

139140
@args = Array.new(ARGV)
140-
opts = GetoptLong.new(['--sanity-check', GetoptLong::NO_ARGUMENT], ['--help', GetoptLong::NO_ARGUMENT], ['--re-execed', GetoptLong::NO_ARGUMENT], ['--proxy', GetoptLong::OPTIONAL_ARGUMENT])
141+
opts = GetoptLong.new(
142+
['--sanity-check', GetoptLong::NO_ARGUMENT],
143+
['--help', GetoptLong::NO_ARGUMENT],
144+
['--re-execed', GetoptLong::NO_ARGUMENT],
145+
['--proxy', GetoptLong::OPTIONAL_ARGUMENT],
146+
['-v', '--version', GetoptLong::OPTIONAL_ARGUMENT]
147+
)
141148
opts.each do |opt, args|
142149
case opt
143150
when '--sanity-check'
@@ -150,6 +157,8 @@ EOF
150157
if (args != '')
151158
@http_proxy = args
152159
end
160+
when '-v' || '--version'
161+
@target_version_arg = args
153162
end
154163
end
155164
if (ARGV.length < 1)
@@ -273,10 +282,7 @@ end
273282
end
274283
end
275284

276-
def install_from_s3(region, bucket, version_file_key, type, install_cmd)
277-
version_data = get_version_file_from_s3(region, bucket, version_file_key)
278-
279-
package_key = version_data[type]
285+
def install_from_s3(region, bucket, package_key, install_cmd)
280286
package_base_name = File.basename(package_key)
281287
package_extension = File.extname(package_base_name)
282288
package_name = File.basename(package_base_name, package_extension)
@@ -309,6 +315,20 @@ end
309315
end
310316
end
311317

318+
def get_target_version(target_version, type, region, bucket)
319+
if target_version.nil?
320+
version_file_key = 'latest/VERSION'
321+
version_data = get_version_file_from_s3(region, bucket, version_file_key)
322+
if version_data.include? type
323+
return version_data[type]
324+
else
325+
@log.error("Unsupported package type '#{type}'")
326+
exit(1)
327+
end
328+
end
329+
return target_version
330+
end
331+
312332
@log.info("Starting update check.")
313333

314334
if (@type == 'auto')
@@ -347,21 +367,21 @@ end
347367

348368
region = get_region
349369
bucket = "aws-codedeploy-#{region}"
350-
version_file_key = 'latest/VERSION'
370+
371+
target_version = get_target_version(@target_version_arg, @type, region, bucket)
351372

352373
case @type
353374
when 'help'
354375
usage
355376
when 'rpm'
356377
running_version = `rpm -q codedeploy-agent`
357378
running_version.strip!
358-
target_version = get_version_file_from_s3(region, bucket, version_file_key)['rpm']
359379
if target_version.include? running_version
360380
@log.info('Running version matches target version, skipping install')
361381
else
362382
#use -y to answer yes to confirmation prompts
363383
install_cmd = ['/usr/bin/yum', '-y', 'localinstall']
364-
install_from_s3(region, bucket, version_file_key, @type, install_cmd)
384+
install_from_s3(region, bucket, target_version, install_cmd)
365385
do_sanity_check('/sbin/service')
366386
end
367387
when 'deb'
@@ -374,20 +394,19 @@ end
374394
running_version = "No running version"
375395
end
376396
@log.info("Running version " + running_version)
377-
target_version = get_version_file_from_s3(region, bucket, version_file_key)['deb']
378397
if target_version.include? running_version
379398
@log.info('Running version matches target version, skipping install')
380399
else
381400
#use -n for non-interactive mode
382401
#use -o to not overwrite config files unless they have not been changed
383402
install_cmd = ['/usr/bin/gdebi', '-n', '-o', 'Dpkg::Options::=--force-confdef', '-o', 'Dkpg::Options::=--force-confold']
384-
install_from_s3(region, bucket, version_file_key, @type, install_cmd)
403+
install_from_s3(region, bucket, target_version, install_cmd)
385404
do_sanity_check('/usr/sbin/service')
386405
end
387406
when 'zypper'
388407
#use -n for non-interactive mode
389408
install_cmd = ['/usr/bin/zypper', 'install', '-n']
390-
install_from_s3(region, bucket, version_file_key, 'rpm', install_cmd)
409+
install_from_s3(region, bucket, target_version, install_cmd)
391410
else
392411
@log.error("Unsupported package type '#{@type}'")
393412
exit(1)

bin/update

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,13 @@ EOF
148148
@http_proxy = nil
149149
@downgrade = false
150150
@upgrade = false
151+
@target_version_arg = nil
151152

152153
@args = Array.new(ARGV)
153154
opts = GetoptLong.new(['--sanity-check', GetoptLong::NO_ARGUMENT], ['--help', GetoptLong::NO_ARGUMENT],
154155
['--re-execed', GetoptLong::NO_ARGUMENT], ['--proxy', GetoptLong::OPTIONAL_ARGUMENT],
155-
['--downgrade', GetoptLong::NO_ARGUMENT], ['--upgrade', GetoptLong::NO_ARGUMENT])
156+
['--downgrade', GetoptLong::NO_ARGUMENT], ['--upgrade', GetoptLong::NO_ARGUMENT],
157+
['-v', '--version', GetoptLong::OPTIONAL_ARGUMENT])
156158
opts.each do |opt, args|
157159
case opt
158160
when '--sanity-check'
@@ -169,6 +171,8 @@ EOF
169171
if (args != '')
170172
@http_proxy = args
171173
end
174+
when '-v' || '--version'
175+
@target_version_arg = args
172176
end
173177
end
174178

@@ -550,7 +554,10 @@ EOF
550554
end
551555

552556
running_version = running_version(@type)
553-
target_version = target_version(@type)
557+
target_version = @target_version_arg
558+
if target_version.nil?
559+
target_version = target_version(@type)
560+
end
554561
if target_version.include? running_version
555562
@log.info("Running version, #{running_version}, matches target version, #{target_version}, skipping install")
556563
else

0 commit comments

Comments
 (0)