test(migrations): build each migration test image once per file

Every test in the migration 54, 55, 57, 58, 59 and 61 bats files called
prep(), and prep() ran `docker build -t` for one fixed tag. Tests in a
file run concurrently under bats -j, so on a cold cache several builds
of that tag ran at once. With the containerd image store a retag to a
different image deletes the old one before creating the new one, and a
sibling's `docker run` that resolved the tag in between found nothing
locally and fell back to a pull of an image that does not exist.

Build the image in setup_file, before any test of the file starts.
prep() keeps a fallback build for a run without setup_file, taken only
when the tag is missing.

Closes: #5299
Assisted-by: LLM
Signed-off-by: Adham Kiwan <adhamkiwan@outlook.com>
This commit is contained in:
Adham Kiwan authored and Aleksei Sviridkin committed 2026-11-19 15:16:30 +02:00
1 parent 382169be52
commit 589c895d59
6 files changed
+132 -28

No files matched your search

+22 -6
View File
@@ -106,6 +106,25 @@ run_migration() {
return "$_run_migration_rc"
}
# build_test_image bakes the test's packages onto the pinned base. Its status
# is docker build's, so a failed build fails whoever called it.
build_test_image() {
docker build -q -t "$TESTIMG" - >/dev/null <<DOCKERFILE
FROM $ALPINE
RUN apk add --no-cache jq
DOCKERFILE
}
# Build the image once per file, before any test runs. Tests in a file run in
# parallel under `bats -j`, and concurrent uncached builds of one tag replace
# each other's image, so a sibling's `docker run` could find the tag missing
# and fall back to a pull. Without docker, prep() reports why.
setup_file() {
docker info >/dev/null 2>&1 || return 0
build_test_image
return 0
}
# prep resets env to a clean scenario. Tests set FAKE_* afterwards.
prep() {
# Fail here rather than at the first docker run, so the reason is legible.
@@ -115,12 +134,9 @@ prep() {
echo "busybox ash — the interpreter run-migrations.sh actually gives it." >&2
return 1
}
# Bake jq onto the pinned base. Cached after the first run, so this is a no-op
# on every subsequent test; only the first build touches the network.
docker build -q -t "$TESTIMG" - >/dev/null <<DOCKERFILE
FROM $ALPINE
RUN apk add --no-cache jq
DOCKERFILE
# setup_file built it already; this only builds when the file runs without
# bats' setup_file, one test at a time.
docker image inspect "$TESTIMG" >/dev/null 2>&1 || build_test_image
chmod +x "$FAKEBIN/kubectl"
WORK=$(mktemp -d)
export FAKE_CMDLOG="$WORK/cmdlog"
+22 -6
View File
@@ -103,6 +103,25 @@ run_migration() {
return "$_run_migration_rc"
}
# build_test_image bakes the test's packages onto the pinned base. Its status
# is docker build's, so a failed build fails whoever called it.
build_test_image() {
docker build -q -t "$TESTIMG" - >/dev/null <<DOCKERFILE
FROM $ALPINE
RUN apk add --no-cache jq
DOCKERFILE
}
# Build the image once per file, before any test runs. Tests in a file run in
# parallel under `bats -j`, and concurrent uncached builds of one tag replace
# each other's image, so a sibling's `docker run` could find the tag missing
# and fall back to a pull. Without docker, prep() reports why.
setup_file() {
docker info >/dev/null 2>&1 || return 0
build_test_image
return 0
}
# prep resets env to a clean scenario. Tests set FAKE_* afterwards.
prep() {
# Fail here rather than at the first docker run, so the reason is legible.
@@ -112,12 +131,9 @@ prep() {
echo "busybox ash — the interpreter run-migrations.sh actually gives it." >&2
return 1
}
# Bake jq onto the pinned base. Cached after the first run, so this is a no-op
# on every subsequent test; only the first build touches the network.
docker build -q -t "$TESTIMG" - >/dev/null <<DOCKERFILE
FROM $ALPINE
RUN apk add --no-cache jq
DOCKERFILE
# setup_file built it already; this only builds when the file runs without
# bats' setup_file, one test at a time.
docker image inspect "$TESTIMG" >/dev/null 2>&1 || build_test_image
chmod +x "$FAKEBIN/kubectl"
WORK=$(mktemp -d)
export FAKE_CMDLOG="$WORK/cmdlog"
+22 -4
View File
@@ -106,16 +106,34 @@ runbook_step() {
return $?
}
# build_test_image bakes the test's packages onto the pinned base. Its status
# is docker build's, so a failed build fails whoever called it.
build_test_image() {
docker build -q -t "$TESTIMG" - >/dev/null <<DOCKERFILE
FROM $ALPINE
RUN apk add --no-cache jq
DOCKERFILE
}
# Build the image once per file, before any test runs. Tests in a file run in
# parallel under `bats -j`, and concurrent uncached builds of one tag replace
# each other's image, so a sibling's `docker run` could find the tag missing
# and fall back to a pull. Without docker, prep() reports why.
setup_file() {
docker info >/dev/null 2>&1 || return 0
build_test_image
return 0
}
prep() {
docker info >/dev/null 2>&1 || {
echo "docker is required: these tests run migration 57 inside a jq-enabled" >&2
echo "build of $ALPINE, the migrations image's base." >&2
return 1
}
docker build -q -t "$TESTIMG" - >/dev/null <<DOCKERFILE
FROM $ALPINE
RUN apk add --no-cache jq
DOCKERFILE
# setup_file built it already; this only builds when the file runs without
# bats' setup_file, one test at a time.
docker image inspect "$TESTIMG" >/dev/null 2>&1 || build_test_image
chmod +x "$FAKEBIN/kubectl"
WORK=$(mktemp -d)
export FAKE_CMDLOG="$WORK/cmdlog"
+22 -4
View File
@@ -58,16 +58,34 @@ run_migration() {
return "$_run_migration_rc"
}
# build_test_image bakes the test's packages onto the pinned base. Its status
# is docker build's, so a failed build fails whoever called it.
build_test_image() {
docker build -q -t "$TESTIMG" - >/dev/null <<DOCKERFILE
FROM $ALPINE
RUN apk add --no-cache jq
DOCKERFILE
}
# Build the image once per file, before any test runs. Tests in a file run in
# parallel under `bats -j`, and concurrent uncached builds of one tag replace
# each other's image, so a sibling's `docker run` could find the tag missing
# and fall back to a pull. Without docker, prep() reports why.
setup_file() {
docker info >/dev/null 2>&1 || return 0
build_test_image
return 0
}
prep() {
docker info >/dev/null 2>&1 || {
echo "docker is required: these tests run migration 58 inside a jq-enabled" >&2
echo "build of $ALPINE, the migrations image's base." >&2
return 1
}
docker build -q -t "$TESTIMG" - >/dev/null <<DOCKERFILE
FROM $ALPINE
RUN apk add --no-cache jq
DOCKERFILE
# setup_file built it already; this only builds when the file runs without
# bats' setup_file, one test at a time.
docker image inspect "$TESTIMG" >/dev/null 2>&1 || build_test_image
chmod +x "$FAKEBIN/kubectl"
mkdir -p "$WORKROOT"
WORK=$(mktemp -d "$WORKROOT/XXXXXX")
+22 -4
View File
@@ -48,16 +48,34 @@ run_migration() {
return "$_run_migration_rc"
}
# build_test_image bakes the test's packages onto the pinned base. Its status
# is docker build's, so a failed build fails whoever called it.
build_test_image() {
docker build -q -t "$TESTIMG" - >/dev/null <<DOCKERFILE
FROM $ALPINE
RUN apk add --no-cache jq
DOCKERFILE
}
# Build the image once per file, before any test runs. Tests in a file run in
# parallel under `bats -j`, and concurrent uncached builds of one tag replace
# each other's image, so a sibling's `docker run` could find the tag missing
# and fall back to a pull. Without docker, prep() reports why.
setup_file() {
docker info >/dev/null 2>&1 || return 0
build_test_image
return 0
}
prep() {
docker info >/dev/null 2>&1 || {
echo "docker is required: these tests run migration 59 inside a jq-enabled" >&2
echo "build of $ALPINE, the migrations image's base." >&2
return 1
}
docker build -q -t "$TESTIMG" - >/dev/null <<DOCKERFILE
FROM $ALPINE
RUN apk add --no-cache jq
DOCKERFILE
# setup_file built it already; this only builds when the file runs without
# bats' setup_file, one test at a time.
docker image inspect "$TESTIMG" >/dev/null 2>&1 || build_test_image
chmod +x "$FIXTURES/kubectl"
mkdir -p "$WORKROOT"
WORK=$(mktemp -d "$WORKROOT/XXXXXX")
+22 -4
View File
@@ -78,16 +78,34 @@ run_migration() {
return "$_run_migration_rc"
}
# build_test_image bakes the test's packages onto the pinned base. Its status
# is docker build's, so a failed build fails whoever called it.
build_test_image() {
docker build -q -t "$TESTIMG" - >/dev/null <<DOCKERFILE
FROM $ALPINE
RUN apk add --no-cache jq bash
DOCKERFILE
}
# Build the image once per file, before any test runs. Tests in a file run in
# parallel under `bats -j`, and concurrent uncached builds of one tag replace
# each other's image, so a sibling's `docker run` could find the tag missing
# and fall back to a pull. Without docker, prep() reports why.
setup_file() {
docker info >/dev/null 2>&1 || return 0
build_test_image
return 0
}
prep() {
docker info >/dev/null 2>&1 || {
echo "docker is required: these tests run migration 61 inside a jq-enabled" >&2
echo "build of $ALPINE, the migrations image's base." >&2
return 1
}
docker build -q -t "$TESTIMG" - >/dev/null <<DOCKERFILE
FROM $ALPINE
RUN apk add --no-cache jq bash
DOCKERFILE
# setup_file built it already; this only builds when the file runs without
# bats' setup_file, one test at a time.
docker image inspect "$TESTIMG" >/dev/null 2>&1 || build_test_image
chmod +x "$FIXTURES/kubectl"
mkdir -p "$WORKROOT"
WORK=$(mktemp -d "$WORKROOT/XXXXXX")