changeset 42648:d80edcb0b30c stable

automation: make Windows base image name configurable Since automation broke in the middle of the 5.0 release cycle, there's a good chance it will break again in the future. While a robust solution might be to search for all available images and choose the newest one, it does seem useful to be able to explicitly choose the name of the image to find and use so users can opt in to using a different image. This commit implements that functionality. Differential Revision: https://phab.mercurial-scm.org/D6673
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 22 Jul 2019 19:06:20 -0700
parents 8804aa6c07a0
children 7fae3b0bd893
files contrib/automation/hgautomation/aws.py contrib/automation/hgautomation/cli.py
diffstat 2 files changed, 49 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/automation/hgautomation/aws.py	Mon Jul 22 18:55:52 2019 -0700
+++ b/contrib/automation/hgautomation/aws.py	Mon Jul 22 19:06:20 2019 -0700
@@ -1032,7 +1032,8 @@
                 instance.ssh_client.close()
 
 
-def ensure_windows_dev_ami(c: AWSConnection, prefix='hg-'):
+def ensure_windows_dev_ami(c: AWSConnection, prefix='hg-',
+                           base_image_name=WINDOWS_BASE_IMAGE_NAME):
     """Ensure Windows Development AMI is available and up-to-date.
 
     If necessary, a modern AMI will be built by starting a temporary EC2
@@ -1050,7 +1051,7 @@
 
     name = '%s%s' % (prefix, 'windows-dev')
 
-    image = find_image(ec2resource, AMAZON_ACCOUNT_ID, WINDOWS_BASE_IMAGE_NAME)
+    image = find_image(ec2resource, AMAZON_ACCOUNT_ID, base_image_name)
 
     config = {
         'BlockDeviceMappings': [
@@ -1103,6 +1104,7 @@
         'user_data': WINDOWS_USER_DATA,
         'initial_bootstrap': WINDOWS_BOOTSTRAP_POWERSHELL,
         'bootstrap_commands': commands,
+        'base_image_name': base_image_name,
     })
 
     existing_image = find_and_reconcile_image(ec2resource, name, fingerprint)
--- a/contrib/automation/hgautomation/cli.py	Mon Jul 22 18:55:52 2019 -0700
+++ b/contrib/automation/hgautomation/cli.py	Mon Jul 22 19:06:20 2019 -0700
@@ -52,15 +52,16 @@
             aws.ensure_linux_dev_ami(c, distro=distro)
 
 
-def bootstrap_windows_dev(hga: HGAutomation, aws_region):
+def bootstrap_windows_dev(hga: HGAutomation, aws_region, base_image_name):
     c = hga.aws_connection(aws_region)
-    image = aws.ensure_windows_dev_ami(c)
+    image = aws.ensure_windows_dev_ami(c, base_image_name=base_image_name)
     print('Windows development AMI available as %s' % image.id)
 
 
-def build_inno(hga: HGAutomation, aws_region, arch, revision, version):
+def build_inno(hga: HGAutomation, aws_region, arch, revision, version,
+               base_image_name):
     c = hga.aws_connection(aws_region)
-    image = aws.ensure_windows_dev_ami(c)
+    image = aws.ensure_windows_dev_ami(c, base_image_name=base_image_name)
     DIST_PATH.mkdir(exist_ok=True)
 
     with aws.temporary_windows_dev_instances(c, image, 't3.medium') as insts:
@@ -74,9 +75,10 @@
                                          version=version)
 
 
-def build_wix(hga: HGAutomation, aws_region, arch, revision, version):
+def build_wix(hga: HGAutomation, aws_region, arch, revision, version,
+              base_image_name):
     c = hga.aws_connection(aws_region)
-    image = aws.ensure_windows_dev_ami(c)
+    image = aws.ensure_windows_dev_ami(c, base_image_name=base_image_name)
     DIST_PATH.mkdir(exist_ok=True)
 
     with aws.temporary_windows_dev_instances(c, image, 't3.medium') as insts:
@@ -89,9 +91,10 @@
                                         DIST_PATH, version=version)
 
 
-def build_windows_wheel(hga: HGAutomation, aws_region, arch, revision):
+def build_windows_wheel(hga: HGAutomation, aws_region, arch, revision,
+                        base_image_name):
     c = hga.aws_connection(aws_region)
-    image = aws.ensure_windows_dev_ami(c)
+    image = aws.ensure_windows_dev_ami(c, base_image_name=base_image_name)
     DIST_PATH.mkdir(exist_ok=True)
 
     with aws.temporary_windows_dev_instances(c, image, 't3.medium') as insts:
@@ -104,9 +107,9 @@
 
 
 def build_all_windows_packages(hga: HGAutomation, aws_region, revision,
-                               version):
+                               version, base_image_name):
     c = hga.aws_connection(aws_region)
-    image = aws.ensure_windows_dev_ami(c)
+    image = aws.ensure_windows_dev_ami(c, base_image_name=base_image_name)
     DIST_PATH.mkdir(exist_ok=True)
 
     with aws.temporary_windows_dev_instances(c, image, 't3.medium') as insts:
@@ -169,9 +172,9 @@
 
 
 def run_tests_windows(hga: HGAutomation, aws_region, instance_type,
-                      python_version, arch, test_flags):
+                      python_version, arch, test_flags, base_image_name):
     c = hga.aws_connection(aws_region)
-    image = aws.ensure_windows_dev_ami(c)
+    image = aws.ensure_windows_dev_ami(c, base_image_name=base_image_name)
 
     with aws.temporary_windows_dev_instances(c, image, instance_type,
                                              disable_antivirus=True) as insts:
@@ -217,6 +220,11 @@
         'bootstrap-windows-dev',
         help='Bootstrap the Windows development environment',
     )
+    sp.add_argument(
+        '--base-image-name',
+        help='AMI name of base image',
+        default=aws.WINDOWS_BASE_IMAGE_NAME,
+    )
     sp.set_defaults(func=bootstrap_windows_dev)
 
     sp = subparsers.add_parser(
@@ -232,6 +240,11 @@
         '--version',
         help='Mercurial version string to use',
     )
+    sp.add_argument(
+        '--base-image-name',
+        help='AMI name of base image',
+        default=aws.WINDOWS_BASE_IMAGE_NAME,
+    )
     sp.set_defaults(func=build_all_windows_packages)
 
     sp = subparsers.add_parser(
@@ -254,6 +267,11 @@
         '--version',
         help='Mercurial version string to use in installer',
     )
+    sp.add_argument(
+        '--base-image-name',
+        help='AMI name of base image',
+        default=aws.WINDOWS_BASE_IMAGE_NAME,
+    )
     sp.set_defaults(func=build_inno)
 
     sp = subparsers.add_parser(
@@ -272,6 +290,11 @@
         help='Mercurial revision to build',
         default='.',
     )
+    sp.add_argument(
+        '--base-image-name',
+        help='AMI name of base image',
+        default=aws.WINDOWS_BASE_IMAGE_NAME,
+    )
     sp.set_defaults(func=build_windows_wheel)
 
     sp = subparsers.add_parser(
@@ -294,6 +317,11 @@
         '--version',
         help='Mercurial version string to use in installer',
     )
+    sp.add_argument(
+        '--base-image-name',
+        help='AMI name of base image',
+        default=aws.WINDOWS_BASE_IMAGE_NAME,
+    )
     sp.set_defaults(func=build_wix)
 
     sp = subparsers.add_parser(
@@ -368,6 +396,11 @@
         '--test-flags',
         help='Extra command line flags to pass to run-tests.py',
     )
+    sp.add_argument(
+        '--base-image-name',
+        help='AMI name of base image',
+        default=aws.WINDOWS_BASE_IMAGE_NAME,
+    )
     sp.set_defaults(func=run_tests_windows)
 
     return parser