Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/scripts/mirror_base_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
are also named in containerd, whose images Docker reads only on the containerd image store. Switching dockerd to it
restarts dockerd, which stops the containers it runs, so this runs before any start.

``mirror_base_images.py PATH...`` does this for the Dockerfiles at or under each PATH.
``mirror_base_images.py PATH...`` does this for the Dockerfiles at or under each PATH, pulling their bases at once.
"""

from __future__ import annotations
Expand All @@ -19,6 +19,7 @@
import subprocess
import sys
import time
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path

ECR = "public.ecr.aws/docker/library/"
Expand All @@ -33,8 +34,8 @@ def main(argv: list[str]) -> int:
bases = _bases([Path(arg) for arg in argv])
if any("@" in base for base in bases):
_use_containerd_store()
for base in bases:
_pull(base)
with ThreadPoolExecutor(max_workers=max(len(bases), 1)) as pool:
list(pool.map(_pull, bases))
return 0


Expand Down
20 changes: 20 additions & 0 deletions tst/unit/test_mirror_base_images_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import json
import subprocess
import sys
import threading

import pytest

Expand Down Expand Up @@ -139,3 +140,22 @@ def test_a_pull_that_fails_once_is_tried_again(script, monkeypatch, tmp_path):

assert ran[-1] == ["docker", "tag", "mirror.gcr.io/library/postgres:16-alpine", _TAGGED]
assert ["sleep", 10] in ran and ["sleep", 20] not in ran


def test_the_bases_are_pulled_at_once(script, monkeypatch, tmp_path):
ran = _docker(monkeypatch, script)
fake = script.subprocess.run
both_pulling = threading.Barrier(2, timeout=10)

def run(argv, **kwargs):
if argv[:2] == ["docker", "pull"]:
both_pulling.wait()
return fake(argv, **kwargs)

monkeypatch.setattr(script.subprocess, "run", run)
dockerfile = tmp_path / "Dockerfile"
dockerfile.write_text(f"FROM {_TAGGED}\nFROM public.ecr.aws/docker/library/busybox:1.37\n")

assert script.main([str(dockerfile)]) == 0

assert sorted(argv[1] for argv in ran) == ["pull", "pull", "tag", "tag"]