Skip to content

An open-source, faster Devin alternative

TypeScript

microvm images: the drift check could never pass, for three separate reasons — it read the stamp from get-microvm-image, which returns no description field at all, so every image reported as unstamped however many times it had been published; the guest hash was computed once per step and go list -deps answers differently as the module cache warms, so the check wanted 733b02f8629c93d4 while the stamp it had just caused said d8348d77e993a933, three seconds apart on one machine at one commit; and items[0] of a version list is not the newest version, because that list sorts as strings and 9.0 outranks 20.0, so egress preservation and the memory guard were both reading an eleven-version-old build. Now: the stamp is read off the version the image serves, one hash is resolved per run and passed to every step, and current means latestActiveImageVersion (#753)

Brian Reardond43824e8dac9
diff --git a/.github/workflows/publish-microvm-images.yml b/.github/workflows/publish-microvm-images.yml
index 3877b8c8..79c78bc7 100644
--- a/.github/workflows/publish-microvm-images.yml
+++ b/.github/workflows/publish-microvm-images.yml
@@ -59,7 +59,19 @@ jobs:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: us-east-1
+ # One hash for the whole run. It is derived from `go list -deps`, whose
+ # answer moves with the state of the module cache, so computing it in
+ # each step gave the drift check and the stamp different values on one
+ # machine at one commit — and the check then failed against the stamp it
+ # had itself caused to be written. Warm the cache, resolve it once, and
+ # hand the same value to every step.
+ - run: go mod download
+ - id: guest
+ run: echo "hash=$(./deploy/microvm/manifest.py guest-hash dev)" >> "$GITHUB_OUTPUT"
+
- id: dev_drift
+ env:
+ MICROVM_GUEST_HASH: ${{ steps.guest.outputs.hash }}
run: |
if ./deploy/microvm/manifest.py check-drift dev; then
echo "stale=false" >> "$GITHUB_OUTPUT"
@@ -72,8 +84,11 @@ jobs:
run: ./deploy/microvm/release.sh dev
env:
MICROVM_ALLOW_RESIZE: ${{ github.event.inputs.allow_resize && '1' || '0' }}
+ MICROVM_GUEST_HASH: ${{ steps.guest.outputs.hash }}
- id: prod_drift
+ env:
+ MICROVM_GUEST_HASH: ${{ steps.guest.outputs.hash }}
run: |
if ./deploy/microvm/manifest.py check-drift prod; then
echo "stale=false" >> "$GITHUB_OUTPUT"
@@ -87,8 +102,11 @@ jobs:
run: ./deploy/microvm/release.sh prod
env:
MICROVM_ALLOW_RESIZE: ${{ github.event.inputs.allow_resize && '1' || '0' }}
+ MICROVM_GUEST_HASH: ${{ steps.guest.outputs.hash }}
- name: Confirm nothing is behind
+ env:
+ MICROVM_GUEST_HASH: ${{ steps.guest.outputs.hash }}
run: |
./deploy/microvm/manifest.py check-drift dev
./deploy/microvm/manifest.py check-drift prod
diff --git a/deploy/microvm/manifest.py b/deploy/microvm/manifest.py
index 1cfd8ef3..6111d582 100755
--- a/deploy/microvm/manifest.py
+++ b/deploy/microvm/manifest.py
@@ -53,6 +53,13 @@ def load(env):
def guest_hash():
"""A hash of everything that ends up in the guest image.
+ MICROVM_GUEST_HASH overrides it. The closure below comes from
+ `go list -deps`, which answers differently depending on the state of the
+ module cache, so a run that computes this more than once can get more than
+ one answer — which is how CI's drift check came to fail against a stamp it
+ had just caused to be written. A caller that needs the check and the stamp
+ to agree resolves it once and passes it down.
+
Not a hash of the artifact zip: zip stores mtimes, so two builds of
identical code differ. Not a path filter either — that was the first
attempt, and it was already wrong: the guest binaries import ten packages
@@ -67,6 +74,9 @@ def guest_hash():
"""
import hashlib
import os
+ override = os.environ.get("MICROVM_GUEST_HASH")
+ if override:
+ return override
root = os.path.abspath(f"{HERE}/../..")
mod = subprocess.run(["go", "list", "-m"], cwd=root, capture_output=True,
text=True, check=True).stdout.strip()
@@ -91,16 +101,42 @@ def guest_hash():
return h.hexdigest()[:16]
-def published_hash(region, acct, name):
- """The guest hash stamped on an image, or None. The image API has no tags,
- so the stamp rides in --description."""
+def latest_version(region, image_arn):
+ """The version an image currently serves, as its own record reports it.
+
+ Not the first entry of the version list: that list is ordered as STRINGS,
+ so "9.0" sorts above "20.0" and the head of it is whichever version has the
+ highest leading digit. Anything that treats it as "current" is reading an
+ arbitrary old build.
+ """
out = subprocess.run(
["aws", "lambda-microvms", "get-microvm-image",
- "--image-identifier", arn(region, acct, name), "--region", region,
- "--query", "description", "--output", "text"],
+ "--image-identifier", image_arn, "--region", region,
+ "--query", "latestActiveImageVersion", "--output", "text"],
+ capture_output=True, text=True)
+ version = out.stdout.strip()
+ return version if version and version != "None" else None
+
+
+def published_hash(region, acct, name):
+ """The guest hash stamped on the version an image is serving, or None.
+
+ The stamp rides in the description because the image API has no tags worth
+ using, and the description belongs to a VERSION — `get-microvm-image` does
+ not return one at all, so reading it there reports every image as unstamped
+ however many times it has been published.
+ """
+ image_arn = arn(region, acct, name)
+ version = latest_version(region, image_arn)
+ if not version:
+ return None
+ out = subprocess.run(
+ ["aws", "lambda-microvms", "list-microvm-image-versions",
+ "--image-identifier", image_arn, "--region", region,
+ "--query", f"items[?imageVersion=='{version}'].description",
+ "--output", "text"],
capture_output=True, text=True)
- desc = out.stdout.strip()
- m = re.search(r"guest=([0-9a-f]{16})", desc or "")
+ m = re.search(r"guest=([0-9a-f]{16})", out.stdout.strip() or "")
return m.group(1) if m else None
@@ -149,11 +185,17 @@ def main():
allow_resize = os.environ.get("MICROVM_ALLOW_RESIZE") == "1"
acct, bad = account(), []
for i in e["images"]:
+ image_arn = arn(region, acct, i["name"])
+ serving = latest_version(region, image_arn)
+ # By version, not by list position: that list sorts as strings, so
+ # "9.0" outranks "20.0" and items[0] is an arbitrary old build.
+ query = (f"items[?imageVersion=='{serving}'].resources[0].minimumMemoryInMiB | [0]"
+ if serving else "items[0].resources[0].minimumMemoryInMiB")
out = subprocess.run(
["aws", "lambda-microvms", "list-microvm-image-versions",
- "--image-identifier", arn(region, acct, i["name"]),
+ "--image-identifier", image_arn,
"--region", region,
- "--query", "items[0].resources[0].minimumMemoryInMiB",
+ "--query", query,
"--output", "text"], capture_output=True, text=True)
live = out.stdout.strip()
if live in ("", "None", "null"):
diff --git a/deploy/microvm/publish.sh b/deploy/microvm/publish.sh
index d6e39f18..df3c403f 100755
--- a/deploy/microvm/publish.sh
+++ b/deploy/microvm/publish.sh
@@ -100,9 +100,24 @@ LOGGING="{\"cloudWatch\":{\"logGroup\":\"/aws/lambda/microvms/${NAME}\"}}"
# new sandbox would have booted with no route off the box, which looks like the
# customer's code hanging rather than like a deploy. Read what the image already
# has and pass it back; fall back to AWS's internet connector for a new image.
-EXISTING_EGRESS="$(aws lambda-microvms list-microvm-image-versions \
+#
+# Read it off the version the image is actually serving. items[0] is not that
+# version: the list is ordered as STRINGS, so "9.0" sorts above "20.0" and the
+# head of it is whichever version happens to lead with the highest digit. Today
+# every version carries the same connector, so items[0] has been returning the
+# right answer by luck — the first image whose egress ever changes would have
+# been silently reverted to an eleven-version-old value by a routine rebuild.
+SERVING_VERSION="$(aws lambda-microvms get-microvm-image \
--image-identifier "$IMAGE_ARN" --region "$REGION" \
- --query 'items[0].egressNetworkConnectors' --output json 2>/dev/null || echo 'null')"
+ --query 'latestActiveImageVersion' --output text 2>/dev/null || echo '')"
+if [[ -n "$SERVING_VERSION" && "$SERVING_VERSION" != "None" ]]; then
+ EXISTING_EGRESS="$(aws lambda-microvms list-microvm-image-versions \
+ --image-identifier "$IMAGE_ARN" --region "$REGION" \
+ --query "items[?imageVersion=='${SERVING_VERSION}'].egressNetworkConnectors | [0]" \
+ --output json 2>/dev/null || echo 'null')"
+else
+ EXISTING_EGRESS='null'
+fi
if [[ -z "$EXISTING_EGRESS" || "$EXISTING_EGRESS" == "null" || "$EXISTING_EGRESS" == "[]" ]]; then
EGRESS="${MICROVM_EGRESS_CONNECTORS:-arn:aws:lambda:${REGION}:aws:network-connector:aws-network-connector:INTERNET_EGRESS}"
else
diff --git a/deploy/microvm/release.sh b/deploy/microvm/release.sh
index cda259fb..fc2d553d 100755
--- a/deploy/microvm/release.sh
+++ b/deploy/microvm/release.sh
@@ -39,7 +39,15 @@ echo "=== memory tiers (publishing may change code, never size) ==="
"$MANIFEST" check-memory "$ENVIRONMENT"
# Stamped onto every image so drift is an exact comparison later, not a guess.
-GUEST_HASH="$("$MANIFEST" guest-hash "$ENVIRONMENT")"
+#
+# Taken from the environment when the caller already computed it. The hash is
+# derived from `go list -deps`, whose answer depends on the state of the module
+# cache, so computing it twice in one run does not reliably give the same value
+# twice: CI's drift check saw 733b02f8629c93d4 and this stamp said
+# d8348d77e993a933, three seconds apart on one machine at one commit. The check
+# then failed against the stamp it had just caused to be written, every run,
+# forever. One value per run, computed once, passed down.
+GUEST_HASH="${MICROVM_GUEST_HASH:-$("$MANIFEST" guest-hash "$ENVIRONMENT")}"
GIT_SHA="$(git -C "$HERE/../.." rev-parse --short HEAD 2>/dev/null || echo unknown)"
export MICROVM_IMAGE_DESCRIPTION="guest=${GUEST_HASH} git=${GIT_SHA}"
echo "stamp : $MICROVM_IMAGE_DESCRIPTION"