mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-12-02 07:47:58 +00:00
Merge remote-tracking branch 'upstream/main' into feature/web-app-openpost
This commit is contained in:
118 files changed
+3635
-306
No files matched your search
@@ -1 +1,15 @@
|
||||
from utils.docker.image.discovery import ImageRef
|
||||
|
||||
NODE_DIGEST = "sha256:feb76650b7195319268c59cb2d419c732d6c499b13bf5296f16ab59eb1f0a4f3"
|
||||
NODE = ImageRef(
|
||||
role="web-app-example",
|
||||
service="node",
|
||||
name="node",
|
||||
version=NODE_DIGEST,
|
||||
source=f"docker.io/library/node@{NODE_DIGEST}",
|
||||
registry="docker.io",
|
||||
)
|
||||
NODE_MIRROR = f"ghcr.io/acme/myrepo/mirror/docker.io/node@{NODE_DIGEST}"
|
||||
DIGEST_REFERENCE = r"^[a-z0-9._/-]+@sha256:[0-9a-f]{64}$"
|
||||
|
||||
__all__ = ["DIGEST_REFERENCE", "NODE", "NODE_DIGEST", "NODE_MIRROR"]
|
||||
@@ -1,10 +1,15 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
from itertools import chain
|
||||
from unittest.mock import patch
|
||||
|
||||
from cli.contributing.mirror.providers import GHCRProvider
|
||||
from utils.docker.image.discovery import ImageRef
|
||||
from utils import PROJECT_ROOT
|
||||
from utils.docker.image.discovery import ImageRef, iter_role_images, iter_runner_images
|
||||
from utils.docker.image.pin import is_digest
|
||||
|
||||
from . import DIGEST_REFERENCE, NODE, NODE_MIRROR
|
||||
|
||||
|
||||
class TestGHCRProviderImageBase(unittest.TestCase):
|
||||
@@ -107,5 +112,44 @@ class TestGHCRProviderIsStale(unittest.TestCase):
|
||||
)
|
||||
|
||||
|
||||
class TestGHCRProviderImageRef(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.provider = GHCRProvider("acme", "myrepo")
|
||||
|
||||
def test_every_tag_pin_of_the_repository_keeps_its_mirror_reference(self) -> None:
|
||||
refs = [
|
||||
ref
|
||||
for ref in chain(
|
||||
iter_role_images(PROJECT_ROOT), iter_runner_images(PROJECT_ROOT)
|
||||
)
|
||||
if not is_digest(ref.version)
|
||||
]
|
||||
self.assertGreater(len(refs), 100)
|
||||
for ref in refs:
|
||||
with self.subTest(ref=ref.source):
|
||||
self.assertEqual(
|
||||
self.provider.image_ref(ref),
|
||||
f"{self.provider.image_base(ref)}:{ref.version}",
|
||||
)
|
||||
|
||||
def test_a_digest_pin_is_copied_to_its_digest_reference(self) -> None:
|
||||
with patch("cli.contributing.mirror.providers.subprocess.run") as run:
|
||||
self.provider.mirror(NODE)
|
||||
|
||||
source, dest = run.call_args.args[0][-2:]
|
||||
self.assertEqual(source, f"docker://{NODE.source}")
|
||||
self.assertEqual(dest, f"docker://{NODE_MIRROR}")
|
||||
self.assertRegex(dest.removeprefix("docker://"), DIGEST_REFERENCE)
|
||||
|
||||
def test_a_digest_pin_is_probed_at_its_digest_reference(self) -> None:
|
||||
with patch("cli.contributing.mirror.providers.subprocess.run") as run:
|
||||
run.return_value.returncode = 0
|
||||
self.assertTrue(self.provider.tag_exists(NODE))
|
||||
|
||||
self.assertEqual(
|
||||
run.call_args.args[0], ["skopeo", "inspect", f"docker://{NODE_MIRROR}"]
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__": # pragma: no cover
|
||||
unittest.main()
|
||||
@@ -7,6 +7,8 @@ from unittest.mock import patch
|
||||
import cli.contributing.mirror.sync.__main__ as sync_main
|
||||
from utils.docker.image.discovery import ImageRef
|
||||
|
||||
from . import DIGEST_REFERENCE, NODE, NODE_MIRROR
|
||||
|
||||
|
||||
class TestThrottle(unittest.TestCase):
|
||||
def test_only_docker_hub_copies_wait_for_the_throttle(self) -> None:
|
||||
@@ -167,6 +169,35 @@ class TestMirrorSync(unittest.TestCase):
|
||||
self.assertEqual(result, 0)
|
||||
mock_mirror.assert_called_once_with(image)
|
||||
|
||||
def test_a_digest_pin_reaches_skopeo_as_a_valid_reference(self) -> None:
|
||||
with (
|
||||
patch(
|
||||
"cli.contributing.mirror.sync.__main__.iter_role_images",
|
||||
return_value=[NODE],
|
||||
),
|
||||
patch(
|
||||
"cli.contributing.mirror.sync.__main__.iter_runner_images",
|
||||
return_value=[],
|
||||
),
|
||||
patch("cli.contributing.mirror.providers.subprocess.run") as run,
|
||||
patch(
|
||||
"sys.argv",
|
||||
[
|
||||
"mirror-sync",
|
||||
"--ghcr-namespace",
|
||||
"acme",
|
||||
"--ghcr-repository",
|
||||
"myrepo",
|
||||
],
|
||||
),
|
||||
):
|
||||
result = sync_main.main()
|
||||
|
||||
self.assertEqual(result, 0)
|
||||
dest = run.call_args.args[0][-1]
|
||||
self.assertEqual(dest, f"docker://{NODE_MIRROR}")
|
||||
self.assertRegex(dest.removeprefix("docker://"), DIGEST_REFERENCE)
|
||||
|
||||
|
||||
if __name__ == "__main__": # pragma: no cover
|
||||
unittest.main()
|
||||
@@ -1,24 +1,70 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import io
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
import cli.contributing.mirror.wait.__main__ as wait_main
|
||||
from utils.docker.image.discovery import ImageRef
|
||||
|
||||
from . import NODE, NODE_MIRROR
|
||||
|
||||
COREDNS = ImageRef(
|
||||
role="runner",
|
||||
service="coredns",
|
||||
name="coredns/coredns",
|
||||
version="1.14.4",
|
||||
source="docker.io/coredns/coredns:1.14.4",
|
||||
registry="docker.io",
|
||||
source_file="compose.yml",
|
||||
)
|
||||
|
||||
|
||||
class TestMirrorWait(unittest.TestCase):
|
||||
def test_a_missing_runner_mirror_keeps_the_wait_open(self) -> None:
|
||||
image = ImageRef(
|
||||
role="runner",
|
||||
service="coredns",
|
||||
name="coredns/coredns",
|
||||
version="1.14.4",
|
||||
source="docker.io/coredns/coredns:1.14.4",
|
||||
registry="docker.io",
|
||||
source_file="compose.yml",
|
||||
def test_missing_refs_name_the_tag_and_the_digest_reference(self) -> None:
|
||||
stderr = io.StringIO()
|
||||
with (
|
||||
patch(
|
||||
"cli.contributing.mirror.wait.__main__.iter_role_images",
|
||||
return_value=[NODE],
|
||||
),
|
||||
patch(
|
||||
"cli.contributing.mirror.wait.__main__.iter_runner_images",
|
||||
return_value=[COREDNS],
|
||||
),
|
||||
patch.object(wait_main.GHCRProvider, "tag_exists", return_value=False),
|
||||
patch(
|
||||
"sys.argv",
|
||||
[
|
||||
"mirror-wait",
|
||||
"--ghcr-namespace",
|
||||
"acme",
|
||||
"--ghcr-repository",
|
||||
"myrepo",
|
||||
"--attempts",
|
||||
"1",
|
||||
"--sleep-seconds",
|
||||
"1",
|
||||
],
|
||||
),
|
||||
contextlib.redirect_stdout(io.StringIO()),
|
||||
contextlib.redirect_stderr(stderr),
|
||||
):
|
||||
result = wait_main.main()
|
||||
|
||||
self.assertEqual(result, 1)
|
||||
self.assertEqual(
|
||||
[line for line in stderr.getvalue().splitlines() if line.startswith(" - ")],
|
||||
[
|
||||
f" - {NODE_MIRROR}",
|
||||
" - ghcr.io/acme/myrepo/mirror/docker.io/coredns/coredns:1.14.4",
|
||||
],
|
||||
)
|
||||
|
||||
def test_a_missing_runner_mirror_keeps_the_wait_open(self) -> None:
|
||||
image = COREDNS
|
||||
|
||||
with (
|
||||
patch(
|
||||
"cli.contributing.mirror.wait.__main__.iter_role_images",
|
||||
|
||||
@@ -137,6 +137,19 @@ class TestVerdict(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(result["pins"]["unreciprocated"], [])
|
||||
|
||||
def test_a_resolving_without_pin_passes(self) -> None:
|
||||
pin = {
|
||||
"carrier": "app#3",
|
||||
"partner": "pa",
|
||||
"target": "without-a",
|
||||
"key": "a",
|
||||
"reciprocal": 0,
|
||||
}
|
||||
result = compare.verdict(
|
||||
_before(), _after(pin=pin), old=["app#0"], split=["app#0", "app#3"]
|
||||
)
|
||||
self.assertEqual(result["pins"]["unreciprocated"], [])
|
||||
|
||||
def test_the_render_names_the_verdict(self) -> None:
|
||||
text = compare.render(
|
||||
compare.verdict(
|
||||
|
||||
@@ -76,6 +76,15 @@ class TestPins(unittest.TestCase):
|
||||
)
|
||||
self.assertTrue(str(finding["reciprocal"]).startswith("error:"))
|
||||
|
||||
def test_a_without_pin_names_the_variant_switching_the_key_off(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
[finding] = rounds.pin_findings(
|
||||
"web-app-a",
|
||||
roles_dir=_tree(tmp, "without-a", gate=False),
|
||||
variants_per_app=VARIANTS,
|
||||
)
|
||||
self.assertEqual((finding["target"], finding["reciprocal"]), ("without-a", 0))
|
||||
|
||||
|
||||
class TestToken(unittest.TestCase):
|
||||
def test_a_whole_role_row_is_variant_0(self) -> None:
|
||||
|
||||
Reference in new issue
Block a user