[Request] [+- ] D8465: automation: always use latest Windows AMI

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Wed Apr 22 02:39:28 UTC 2020


indygreg created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The old AMI isn't available any more.
  
  We seem to run into this problem every few months. Amazon (or
  Microsoft) appears to be removing the old AMIs when they are
  superseded or something. Let's give up on tracking known images
  and switch the image selection logic to use the latest published
  image.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

REVISION DETAIL
  https://phab.mercurial-scm.org/D8465

AFFECTED FILES
  contrib/automation/hgautomation/aws.py

CHANGE DETAILS

diff --git a/contrib/automation/hgautomation/aws.py b/contrib/automation/hgautomation/aws.py
--- a/contrib/automation/hgautomation/aws.py
+++ b/contrib/automation/hgautomation/aws.py
@@ -59,7 +59,7 @@
 UBUNTU_ACCOUNT_ID = '099720109477'
 
 
-WINDOWS_BASE_IMAGE_NAME = 'Windows_Server-2019-English-Full-Base-2019.11.13'
+WINDOWS_BASE_IMAGE_NAME = 'Windows_Server-2019-English-Full-Base-*'
 
 
 KEY_PAIRS = {
@@ -464,7 +464,7 @@
             profile.add_role(RoleName=role)
 
 
-def find_image(ec2resource, owner_id, name):
+def find_image(ec2resource, owner_id, name, reverse_sort_field=None):
     """Find an AMI by its owner ID and name."""
 
     images = ec2resource.images.filter(
@@ -476,6 +476,13 @@
         ]
     )
 
+    if reverse_sort_field:
+        images = sorted(
+            images,
+            key=lambda image: getattr(image, reverse_sort_field),
+            reverse=True,
+        )
+
     for image in images:
         return image
 
@@ -1059,7 +1066,7 @@
 
 
 def ensure_windows_dev_ami(
-    c: AWSConnection, prefix='hg-', base_image_name=WINDOWS_BASE_IMAGE_NAME
+    c: AWSConnection, prefix='hg-', base_image_name=WINDOWS_BASE_IMAGE_NAME,
 ):
     """Ensure Windows Development AMI is available and up-to-date.
 
@@ -1078,7 +1085,12 @@
 
     name = '%s%s' % (prefix, 'windows-dev')
 
-    image = find_image(ec2resource, AMAZON_ACCOUNT_ID, base_image_name)
+    image = find_image(
+        ec2resource,
+        AMAZON_ACCOUNT_ID,
+        base_image_name,
+        reverse_sort_field="name",
+    )
 
     config = {
         'BlockDeviceMappings': [



To: indygreg, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20200422/695de4c0/attachment-0001.html>


More information about the Mercurial-patches mailing list