Skip to content

Commit

Permalink
test/generate-ostree-build-config: download oci archive from s3
Browse files Browse the repository at this point in the history
Download the container archive from the s3 bucket instead of pulling it
from the gitlab registry.  After this, we will phase out use of the
gitlab registry and start removing all the containers we have there.

Each archive is downloaded to a temporary directory and run directly
with `podman run oci-archive:<path`, which also performs a `podman
pull`, then the temporary directory (along with the downloaded archive)
is discarded.
  • Loading branch information
achilleas-k committed Jun 5, 2024
1 parent 9479e22 commit 0758616
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions test/scripts/generate-ostree-build-config
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,12 @@ def default_ref(distro, arch):
else:
raise ValueError(f"unknown distro name {name}")

return f"{name}/{version}/{arch}/{product}" #pylint: disable=possibly-used-before-assignment
return f"{name}/{version}/{arch}/{product}" # pylint: disable=possibly-used-before-assignment


@contextmanager
def setup_dependencies(manifests, config_map, distro, arch):
# pylint: disable=too-many-statements
"""
For each config in the config map, list all image configurations (distro, arch, image type) that it applies to and
use the manifests to find the corresponding manifest IDs. Pull and run the corresponding dependency container from
Expand Down Expand Up @@ -221,15 +222,16 @@ def setup_dependencies(manifests, config_map, distro, arch):
ic_image_type = image_config["image-type"]
dep_build_name = testlib.gen_build_name(ic_distro, ic_arch, dep_image_type, dep_config_name)
manifest_id = manifests[dep_build_name + ".json"]["id"]
container = f"{testlib.REGISTRY}/{dep_build_name}:build-{manifest_id}"
container_s3_prefix = testlib.gen_build_info_s3(distro, arch, manifest_id)
container_s3_path = f"{container_s3_prefix}/container/container.tar"

# start each container once on an incremental port
port = container_ports.get(container)
port = container_ports.get(container_s3_path)
if not port:
# Pulling and launching the container will fail if the specific container config was never built. This
# can happen if a dependency is specified that does not exist in the config-map.
port = 42000 + len(container_ports)
container_ports[container] = port
container_ports[container_s3_path] = port

# modify image config with container address and ref
config_name = config_data["name"]
Expand All @@ -249,7 +251,7 @@ def setup_dependencies(manifests, config_map, distro, arch):
new_configs[config_name] = new_config

container_configs[config_name] = {
"name": container,
"name": container_s3_path,
"port": port,
}

Expand All @@ -261,10 +263,15 @@ def setup_dependencies(manifests, config_map, distro, arch):
new_config_map[config_fname] = new_filters

try:
for container, port in container_ports.items():
print(f"📦 Starting container {container} {port}")
cont_id, _ = testlib.runcmd(["podman", "run", "-d", "--rm", f"-p{port}:8080", container])
container_ids.append(cont_id.strip().decode())
for container_s3_path, port in container_ports.items():
with TemporaryDirectory() as container_dir:
print(f"⬇️ Downloading container archive from {container_s3_path}")
container_archive = os.path.join(container_dir, "container.tar")
testlib.runcmd_nc(["aws", "s3", "cp", "--no-progress", container_s3_path, container_archive])
print(f"📦 Starting container oci-archive:{container_archive} {port}")
cont_id, _ = testlib.runcmd(["podman", "run", "-d", "--rm", f"-p{port}:8080",
f"oci-archive:{container_archive}"])
container_ids.append(cont_id.strip().decode())

yield new_config_map, new_configs, container_configs
finally:
Expand Down

0 comments on commit 0758616

Please sign in to comment.