test: change image-prepare --container approach

Let's simplify our container installation script (which is now used
exclusively for the /ws-container scenarios) to only work if the
container version exactly matches the builder version.  We use the new
mapping introduced in https://github.com/cockpit-project/bots/pull/8755
to know what this should be (which is also used by the bots to ensure
proper gating).

This avoids copying the container image over from the builder machine
which was the cause of the gating failure in the first place.  After
this lands we should actually be able to remove the container images
there.
This commit is contained in:
Allison Karlitskaya 2026-03-03 09:07:16 +01:00 committed by Allison Karlitskaya
parent 799fae5f73
commit 7659f27bb3
2 changed files with 33 additions and 41 deletions

View file

@ -178,42 +178,31 @@ def build_install_bootc(dist_tars: list[str], image: str, *, verbose: bool, quic
return args
def build_install_container(dist_tars: list[str], *, verbose: bool, quick: bool) -> list[str]:
def build_install_container(dist_tars: list[str], image: str, *, verbose: bool, quick: bool) -> list[str]:
"""Build VM with cockpit/ws container
This can test an image with beibooting from a cockpit/ws container, without
any installed cockpit packages.
"""
# this needs to be the image that corresponds to the actual cockpit/ws container
with open(os.path.join(BASE_DIR, "containers/ws/Containerfile")) as f:
for line in f:
if line.startswith("FROM"):
fedora_version = line.split('fedora:')[1].split()[0]
break
else:
raise ValueError("failed to parse Fedora version from ws container")
builder = testmap.get_build_image_for_ws_container_inside_of(image)
if builder is None:
raise ValueError(f"Don't know how to build a container for {image}")
with create_machine(f"fedora-{fedora_version}") as m:
build_rpms(dist_tars, m, verbose=verbose, quick=quick)
# copy the rpms and playground where ws-container.install expects them
m.execute(r"find /var/tmp/build -name '*.rpm' -not -name '*.src.rpm' -exec mv {} /var/tmp/ \;")
m.execute("mkdir -p /var/tmp/install/usr/share/cockpit/")
m.upload([os.path.join(BASE_DIR, "dist/playground")], "/var/tmp/install/usr/share/cockpit/")
# create container
m.upload([os.path.join(BASE_DIR, "containers")], "/var/tmp/")
with open(os.path.join(TEST_DIR, "ws-container.install")) as f:
m.execute(f.read())
# download container
m.execute("podman save cockpit/ws -o /var/tmp/ws.tar")
m.download("/var/tmp/ws.tar", os.path.abspath("tmp/"))
return [
# install container
"--upload", os.path.abspath("tmp/ws.tar") + ":/var/tmp/",
"--run-command", "podman load -i /var/tmp/ws.tar; rm /var/tmp/ws.tar",
with create_machine(builder) as machine:
rpms = build_rpms(dist_tars, machine, verbose=verbose, quick=quick)
args: list[str] = []
for rpm in rpms:
args += ["--upload", f"{rpm}:/var/tmp/"]
args += [
# copy the playground where ws-container.install expects it
"--run-command", "mkdir -p /var/tmp/install/usr/share/cockpit/",
"--upload", os.path.join(BASE_DIR, "dist/playground") + ":/var/tmp/install/usr/share/cockpit/",
# remove preinstalled rpms
"--run-command", "dnf -C remove -y cockpit-bridge cockpit-ws",
"--upload", os.path.join(BASE_DIR, "containers") + ":/var/tmp/",
"--script", os.path.join(TEST_DIR, "ws-container.install"),
]
return args
def validate_packages() -> list[str]:
@ -272,7 +261,7 @@ def main() -> int:
elif args.image.endswith("-bootc"):
customize += build_install_bootc(dist_tars, args.image, verbose=args.verbose, quick=args.quick)
elif args.container:
customize += build_install_container(dist_tars, verbose=args.verbose, quick=args.quick)
customize += build_install_container(dist_tars, args.image, verbose=args.verbose, quick=args.quick)
else:
customize += build_install_package(dist_tars, args.image, quick=args.quick)

View file

@ -1,6 +1,7 @@
#!/bin/sh
#!/bin/bash
# update cockpit packages and install scripts in the container
set -eu
shopt -s failglob
# keep in sync with containers/ws/install.sh
PACKAGES="
@ -13,22 +14,24 @@ storaged
system
"
for rpm in ws bridge $PACKAGES; do
rpm2cpio /var/tmp/cockpit-$rpm-*.rpm | cpio -i --make-directories --directory=/var/tmp/install
# Mount the container image so we can check some things
ws_mount=$(podman image mount quay.io/cockpit/ws)
# Verify that we only install rpms from the correct dist
ws_dist=".fc$(. "${ws_mount}/etc/os-release" && echo "${VERSION_ID}")"
for pkg in ws bridge $PACKAGES; do
rpm2cpio /var/tmp/cockpit-${pkg}-*${ws_dist}.*.rpm | cpio -i --make-directories --directory=/var/tmp/install
done
# Sometimes the actual quay.io/cockpit/ws Fedora version lags behind containers/ws/Containerfile, i.e. in between
# moving the latter to a new Fedora version, and releasing Cockpit and landing it in Fedora. Then the Python version
# in the rpms does not match the actual Python version in the container. So remove any traces of the old Python
# deployment first, unpack the new rpms, and move our Python module into place.
ws_pyver=$(podman run --rm --entrypoint /usr/bin/python3 quay.io/cockpit/ws -c \
'import sys; print("%d.%d" % sys.version_info[:2])')
ws_sitelib="/var/tmp/install/usr/lib/python${ws_pyver}"
if ! [ -d "$ws_sitelib" ]; then
echo "Adjusting Python module location to $ws_sitelib" >&2
mv --verbose /var/tmp/install/usr/lib/python3.* "$ws_sitelib" >&2
# Verify Python version matches
# basename with a suffix argument fails if the glob expands to more than one match
ws_pylib="$(basename "${ws_mount}"/usr/lib/python3.* '')"
if ! [ -d "/var/tmp/install/usr/lib/${ws_pylib}" ]; then
echo "ERROR: RPMs have different Python version than container (expected ${ws_pylib})" >&2
exit 1
fi
# Copy those files into the container (we don't have RPM inside)
podman run --name build-cockpit -i \
-v /var/tmp/:/run/build:Z \
quay.io/cockpit/ws sh -exc '