ci: key the ECR Public prefetch on the classes that start each image (#4600)

* ci: key the ECR Public prefetch on the classes that start each image

prefetch-images.sh keyed the four Lambda runtimes on any /lambda/ path in
shard.txt, and partition.sh spreads the Lambda tests over every shard, so
each of the four shards pulled all four runtimes (674 MiB) plus the Firelens
router (105 MiB) from ECR Public anonymously before its tests started. ECR
Public counts that transfer per runner IP, and once the quota is spent every
later anonymous pull fails with "toomanyrequests: Data limit exceeded",
which is how a 2 MiB busybox pull took a shard down on main twice on
2026-09-27.

Measured from a full four-shard run by pairing each ImageCacheService
"Pulling image" / "Image already present locally" line with the class that
logged it: nodejs:20 is reached from every shard, python:3.14 and
python:3.12 each have one Docker-backed class, nodejs:18 was pulled by every
shard and started by none, and the Firelens router has one class. Each entry
now keys on those classes, which cuts a shard's ECR Public prefetch from
about 800 MiB to between 120 and 330 MiB. A class the list misses pulls
inline, as before.

The tests also used three busybox tags (latest, 1.36, stable) for the same
2 MiB image. They now share one pin, TestImages.BUSYBOX (busybox:stable,
the tag application.yml and the compatibility suites already use), and the
prefetch script reads that pin from the class the way it reads the sidecar
pins from application.yml, so one prefetch serves every test and the two
cannot drift apart. The one test that pulls the other architecture keeps a
tag of its own: a foreign-platform pull replaces what the local tag points
at on a daemon without the containerd image store, and the docker build in
the VolumesFrom test resolves its base from that local tag.

Each key that names a class is checked against src/test/java, and a stale
name is written to the log, so a rename cannot silently turn a prefetch off.

The prefetch also set off ECR Public's per-second limit on its own: every
pull started in the background at once, so the shard's ECR Public pulls
landed in the same second. They are now queued and pulled one after another,
a second apart, small images first because core/common/docker sorts near
the top of every shard, while the Docker Hub pulls stay parallel. And each pull now
writes one result line to prefetch-images.log, printed by a step after the
tests, so a failed or still-running prefetch can be told apart from a test
pulling the image itself.

* ci: pull the Docker library test images from Docker Hub

The first run of the prefetch results log showed where the quota actually
runs out. On the two shards that failed, the very first pull of the job,
docker/library/busybox or docker/library/python from the ECR Public mirror,
came back with "toomanyrequests: Data limit exceeded" before the job had
transferred anything, so the shard's own volume was not what spent it. The
same runner then pulled busybox from Docker Hub seven seconds later and a
116 MiB lambda/ image from ECR Public half a minute after that, both fine.
The mirror at public.ecr.aws/docker/library has an anonymous quota of its
own, shared by runner IP and often already spent when a job starts, while
GitHub-hosted runners pull Docker Hub without a limit: the fourteen Docker
Hub images each shard prefetches have never failed.

TestImages now names busybox and python-alpine the Docker Hub way, with the
reason in its Javadoc, and the prefetch pulls them with the other Docker Hub
images instead of queuing them behind the ECR Public runtimes. The three
python-alpine literals share one pin. The pin is read with a regex that
tolerates spacing, and a pin the script cannot read writes a "prefetch
skipped" line instead of silently pulling nothing. An image two entries
name is pulled once. The results step also lists any docker pull still
running, so an early exit does not make an unfinished pull look like one
that never ran.

* test(compat): pull the SageMaker and CodeBuild images from Docker Hub

The SageMaker compatibility tests (Java and Python) and the CodeBuild one
named busybox through the public.ecr.aws/docker/library mirror, the same
namespace whose anonymous quota fails the Build and Test shards, and the
native Python jobs of another PR failed on it the same way. They now name
the image the Docker Hub way. The CodeBuild digest is the same on both
registries, so that reference only changes its host.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-09-28 21:17:51 -04:00
1 parent 5ae46c2bd3
commit 903efdf58e
18 files changed
+155 -35

No files matched your search

+77 -10
View File
@@ -2,25 +2,95 @@
# Best-effort background prefetch of the Docker images this shard's tests use.
# Never fails the build; a pull that loses the race just means the test pulls
# it itself, exactly as before. Pulls only images implied by shard.txt so four
# shards do not each pull all images (Docker Hub rate-limit exposure).
# shards do not each pull all images (registry rate-limit exposure).
# ECR Public counts anonymous transfer per runner IP, so an image is keyed on the classes that
# start it whenever its package is spread over every shard (Lambda, ECS), and a key that names a
# class is checked against src/test/java so a rename cannot silently turn the prefetch off. The
# Docker library images the tests start come from Docker Hub, which GitHub-hosted runners pull
# without a limit; TestImages says why they are not taken through the ECR Public mirror.
# Each pull writes one line to $PREFETCH_LOG (prefetch-images.log next to shard.txt by default):
# "prefetched <image>" or "prefetch failed <image>: <last line of docker's output>", timestamped,
# so a test that pulled the image itself can be told apart from a prefetch that failed or was
# still downloading. The lines go to a file because the pulls outlive the workflow step that
# started them and the step's stdout is closed by then.
# Usage: prefetch-images.sh <shard.txt>
set -u
SHARD_FILE="${1:-}"
PREFETCH_LOG="${PREFETCH_LOG:-$(dirname "${SHARD_FILE:-.}")/prefetch-images.log}"
command -v docker >/dev/null 2>&1 || exit 0
[ -r "$SHARD_FILE" ] || { echo "prefetch-images: ${SHARD_FILE:-<none>} not readable, nothing prefetched" >&2; exit 0; }
: > "$PREFETCH_LOG"
pull() { docker pull -q "$1" >/dev/null 2>&1 & }
pull_and_log() {
if output="$(docker pull -q "$1" 2>&1)"; then
echo "$(date -u +%H:%M:%S) prefetched $1" >> "$PREFETCH_LOG"
else
echo "$(date -u +%H:%M:%S) prefetch failed $1: $(printf '%s\n' "$output" | tail -n 1)" >> "$PREFETCH_LOG"
fi
}
# Docker Hub and other registries: each pull in its own background job, as before. An image two
# entries name (busybox:stable is both the EFS init image and the tests' shell) is pulled once.
REQUESTED=""
pull() {
case " $REQUESTED " in *" $1 "*) return 0;; esac
REQUESTED="$REQUESTED $1"
pull_and_log "$1" &
}
# ECR Public counts unauthenticated pulls per second as well as bytes, so its images are queued
# and pulled one after another, a second apart, in a single background job instead of all at once.
ECR_PUBLIC_IMAGES=""
ecr() { ECR_PUBLIC_IMAGES="$ECR_PUBLIC_IMAGES $1"; }
# True when the shard runs any of the named classes. A name with no source file is a stale key,
# recorded in the log so the next reader can see why an image stopped being prefetched.
starts() {
for class in "$@"; do
[ -n "$(find src/test/java -name "$class.java" -print -quit)" ] \
|| echo "$(date -u +%H:%M:%S) stale prefetch key: no test class named $class" >> "$PREFETCH_LOG"
done
grep -qE "$(IFS='|'; echo "$*")" "$SHARD_FILE"
}
# The image a test constant pins, or empty (and a log line) when the constant cannot be read.
test_image() {
image="$(grep -oE "$1 *= *\"[^\"]+\"" src/test/java/io/github/hectorvent/floci/testing/TestImages.java | grep -oE '"[^"]+"' | tr -d '"')"
[ -n "$image" ] || echo "$(date -u +%H:%M:%S) prefetch skipped: TestImages.$1 not readable" >> "$PREFETCH_LOG"
echo "$image"
}
# Every Docker-backed test that needs a shell uses the one busybox TestImages pins, so one pull
# serves all of them. It is also the base of the image
# EcsContainerManagerVolumesFromDockerIntegrationTest builds, and a build resolves its base against
# the registry rather than through ImageCacheService, so it is prefetched for the cache hit rather
# than for the second it saves. ContainerPlatformDockerIntegrationTest is not listed: it pulls the
# other architecture, which a prefetch of the host image cannot serve.
BUSYBOX_IMAGE="$(test_image BUSYBOX)"
starts ContainerHostNetworkDockerIntegrationTest EcsServiceDiscoveryDockerIntegrationTest \
EcsContainerManagerEfsIsolationDockerIntegrationTest EcsContainerManagerFirelensDockerIntegrationTest \
EcsContainerManagerStatsDockerIntegrationTest EcsContainerManagerVolumesFromDockerIntegrationTest \
EcsExecChannelDockerIntegrationTest BatchDockerRunnerDockerIntegrationTest SageMakerDockerIntegrationTest \
&& [ -n "$BUSYBOX_IMAGE" ] && pull "$BUSYBOX_IMAGE"
PYTHON_ALPINE_IMAGE="$(test_image PYTHON_ALPINE)"
starts ContainerCaBundleDockerIntegrationTest EcsCredentialsProxyDockerIntegrationTest SageMakerDockerIntegrationTest \
&& [ -n "$PYTHON_ALPINE_IMAGE" ] && pull "$PYTHON_ALPINE_IMAGE"
# ECR Public images, in queue order: the Lambda runtimes by size, then the Firelens router.
# Lambda runtimes, measured from a full four-shard run by pairing each ImageCacheService
# "Pulling image" / "Image already present locally" line with the class that logged it.
# nodejs:20 is the runtime the API Gateway, ELBv2 and Lambda integration tests resolve and every
# shard reaches it; the two Python runtimes each have one Docker-backed class; nodejs:18 was
# pulled by every shard and started by none. A class missed here pulls inline, as before.
grep -qE '/apigateway/|/apigatewayv2/|/lambda/' "$SHARD_FILE" && ecr public.ecr.aws/lambda/nodejs:20
starts SwfLambdaIntegrationTest && ecr public.ecr.aws/lambda/python:3.12
starts ElbV2LambdaTargetDataPlaneIntegrationTest && ecr public.ecr.aws/lambda/python:3.14
# The Firelens test names the log router image itself rather than taking it from config.
starts EcsContainerManagerFirelensDockerIntegrationTest && ecr public.ecr.aws/aws-observability/aws-for-fluent-bit:3
# package token in shard.txt -> images its tests are known to launch
# (measured inline pulls; update alongside image-catalog changes)
grep -q '/lambda/' "$SHARD_FILE" && { pull public.ecr.aws/lambda/python:3.14; pull public.ecr.aws/lambda/nodejs:18; pull public.ecr.aws/lambda/nodejs:20; pull public.ecr.aws/lambda/python:3.12; }
grep -q '/docdb/' "$SHARD_FILE" && pull mongo:7.0
grep -q '/neptune/' "$SHARD_FILE" && { pull neo4j:5-community; pull tinkerpop/gremlin-server:3.7.3; }
grep -q '/elasticache/' "$SHARD_FILE" && { pull valkey/valkey:8; pull memcached:1.6; }
grep -q '/memorydb/' "$SHARD_FILE" && pull valkey/valkey:8
grep -q '/ecr/' "$SHARD_FILE" && pull registry:2
grep -q '/ec2/' "$SHARD_FILE" && { pull busybox:stable; pull alpine:latest; }
grep -q '/common/docker/' "$SHARD_FILE" && pull public.ecr.aws/docker/library/python:3.12-alpine
# The Cedar sidecar pin lives in application.yml; read it rather than duplicate it.
CEDAR_IMAGE="$(grep -oE 'cedar-image: *"[^"]+"' src/main/resources/application.yml | grep -oE '"[^"]+"' | tr -d '"')"
grep -q '/verifiedpermissions/' "$SHARD_FILE" && [ -n "$CEDAR_IMAGE" ] && pull "$CEDAR_IMAGE"
@@ -48,10 +118,7 @@ INFLUX_IMAGE="$(grep -oE 'default-image: *"influxdb:[^"]+"' src/main/resources/a
grep -q '/timestreaminfluxdb/' "$SHARD_FILE" && [ -n "$INFLUX_IMAGE" ] && pull "$INFLUX_IMAGE"
K3S_IMAGE="$(grep -oE 'default-image: *"rancher/k3s:[^"]+"' src/main/resources/application.yml | grep -oE '"[^"]+"' | tr -d '"')"
grep -q '/eks/' "$SHARD_FILE" && [ -n "$K3S_IMAGE" ] && pull "$K3S_IMAGE"
# The Firelens test names the log router image itself rather than taking it from config.
# busybox is the base of the image EcsContainerManagerVolumesFromDockerIntegrationTest builds, and
# a build resolves its base against the registry rather than through ImageCacheService. That pull
# has hit "toomanyrequests: Rate exceeded" and failed the shard three times (PRs 4075, 4142, 4164),
# so it is prefetched for the cache hit rather than for the second it saves.
grep -q '/ecs/container/' "$SHARD_FILE" && { pull public.ecr.aws/aws-observability/aws-for-fluent-bit:3; pull public.ecr.aws/docker/library/busybox:latest; }
if [ -n "$ECR_PUBLIC_IMAGES" ]; then
{ for image in $ECR_PUBLIC_IMAGES; do pull_and_log "$image"; sleep 1; done; } &
fi
exit 0
+10
View File
@@ -118,6 +118,15 @@ jobs:
-Dsurefire.includesFile="$GITHUB_WORKSPACE/shard.txt"
-Dsurefire.failIfNoTests=true
# The prefetch runs in the background past its own step, so its per-image
# results are only complete once the tests are done. A pull still running
# here (after an early exit) has no result line yet, so list it.
- name: Image prefetch results
if: always()
run: |
cat prefetch-images.log 2>/dev/null || echo "no prefetch log"
pgrep -af 'docker pull' | sed 's/^/still running: /' || true
# Save from main only, and from shard 1 only. Actions caches are ref-scoped:
# a pull_request run's write lands in refs/pull/N/merge where no other PR can
# read it, so every open PR was storing a ~201 MB byte-identical duplicate of
@@ -144,6 +153,7 @@ jobs:
path: |
shard.txt
all-classes.txt
prefetch-images.log
target/surefire-reports/
if-no-files-found: error