Patchwork D8465: automation: always use latest Windows AMI

login
register
mail settings
Submitter phabricator
Date April 22, 2020, 2:39 a.m.
Message ID <differential-rev-PHID-DREV-moo34j5yhmkiyvdevygb-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46195/
State Superseded
Headers show

Comments

phabricator - April 22, 2020, 2:39 a.m.
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




To: indygreg, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

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': [