mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-16 07:28:41 +00:00
fix(ci): share the vulnerability databases with act runs and local deploys
Under act the deploy job pinned an engine but skipped the cache restores, so every local swarm-* run stopped on a missing Grype database. The swarm matrix also ran inside the act job container, where the shared host directory did not exist, and the workspace job would have kept a copy of about 5 GB in every worktree. - scripts/tests/deploy/act/workflow.sh requires INFINITO_VULNERABILITY_DB_HOST_PATH, creates it on the host and binds it into the job container at the same path, because that container drives the host daemon, which resolves every stack and swarm node bind on the host. - call-test-deploy.yml pins engine and database path in one step that runs only outside act; under act the deploy draws an engine and refreshes the shared directory. call-test-workspace.yml takes the shared path under act. - The refresh lock moves into the shared directory, so host deploys and act runs serialize on one file, and a root refresh hands its files to the directory owner. hand_over skips paths a mocked download never created, which failed four TestRefresh cases when the gate ran as root. - A missing INFINITO_VULNERABILITY_DB_HOST_PATH stops compose up with a "run 'make dotenv'" hint instead of a KeyError. - Rationale paragraphs in the database and compose docstrings are dropped. Part of #1324 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c0b857598b
commit
ca6faac318
12 files changed
+359
-41
No files matched your search
@@ -96,29 +96,79 @@ class TestStale(_Root):
|
||||
|
||||
|
||||
class TestRefresh(_Root):
|
||||
def _refresh(self, engines, fetched=()):
|
||||
with mock.patch.object(
|
||||
database, "fetch_databases", return_value=list(fetched)
|
||||
) as fetch:
|
||||
errors = database.refresh(
|
||||
self.root, engines, lambda argv: None, lambda u, d: None
|
||||
)
|
||||
return errors, fetch
|
||||
|
||||
def test_only_stale_engines_are_downloaded(self):
|
||||
_touch(self.root / "grype" / "6" / "vulnerability.db", 60)
|
||||
with (
|
||||
mock.patch.object(database, "LOCK_FILE", self.root / "lock"),
|
||||
mock.patch.object(database, "fetch_databases", return_value=[]) as fetch,
|
||||
):
|
||||
database.refresh(
|
||||
self.root, ["trivy", "grype"], lambda argv: None, lambda u, d: None
|
||||
)
|
||||
_errors, fetch = self._refresh(["trivy", "grype"])
|
||||
self.assertEqual(fetch.call_args.args[2], ["trivy"])
|
||||
|
||||
def test_fresh_databases_download_nothing(self):
|
||||
_touch(self.root / "grype" / "6" / "vulnerability.db", 60)
|
||||
with (
|
||||
mock.patch.object(database, "LOCK_FILE", self.root / "lock"),
|
||||
mock.patch.object(database, "fetch_databases") as fetch,
|
||||
):
|
||||
errors = database.refresh(
|
||||
self.root, ["grype"], lambda argv: None, lambda u, d: None
|
||||
)
|
||||
errors, fetch = self._refresh(["grype"])
|
||||
self.assertEqual(errors, [])
|
||||
fetch.assert_not_called()
|
||||
|
||||
def test_the_lock_lives_in_the_shared_directory(self):
|
||||
self._refresh(["grype"])
|
||||
self.assertTrue((self.root / database.LOCK_NAME).is_file())
|
||||
|
||||
def test_a_missing_shared_directory_is_created(self):
|
||||
self.root = self.root / "vulnerability-db"
|
||||
self._refresh(["grype"])
|
||||
self.assertTrue(self.root.is_dir())
|
||||
|
||||
def test_a_failed_download_is_returned(self):
|
||||
errors, _fetch = self._refresh(["grype"], ["grype database: exited 1"])
|
||||
self.assertEqual(errors, ["grype database: exited 1"])
|
||||
|
||||
|
||||
class TestHandOver(_Root):
|
||||
def _hand_over(self, euid):
|
||||
_touch(self.root / "osv" / "osv-scalibr" / "Ubuntu" / "all.zip", 60)
|
||||
owner = self.root.stat()
|
||||
with (
|
||||
mock.patch.object(database.os, "geteuid", return_value=euid),
|
||||
mock.patch.object(database.os, "chown") as chown,
|
||||
):
|
||||
database.hand_over(self.root, [self.root / "osv"])
|
||||
return chown, (owner.st_uid, owner.st_gid)
|
||||
|
||||
def test_a_root_refresh_gives_every_file_to_the_directory_owner(self):
|
||||
chown, owner = self._hand_over(0)
|
||||
self.assertEqual(
|
||||
{(Path(call.args[0]), call.args[1:]) for call in chown.call_args_list},
|
||||
{
|
||||
(self.root / "osv", owner),
|
||||
(self.root / "osv" / "osv-scalibr", owner),
|
||||
(self.root / "osv" / "osv-scalibr" / "Ubuntu", owner),
|
||||
(self.root / "osv" / "osv-scalibr" / "Ubuntu" / "all.zip", owner),
|
||||
},
|
||||
)
|
||||
|
||||
def test_an_unprivileged_refresh_changes_no_owner(self):
|
||||
chown, _owner = self._hand_over(1000)
|
||||
chown.assert_not_called()
|
||||
|
||||
def test_a_root_refresh_that_wrote_no_database_hands_over_the_lock(self):
|
||||
with (
|
||||
mock.patch.object(database.os, "geteuid", return_value=0),
|
||||
mock.patch.object(database.os, "chown") as chown,
|
||||
mock.patch.object(database, "fetch_databases", return_value=[]),
|
||||
):
|
||||
database.refresh(self.root, ["grype"], lambda argv: None, lambda u, d: None)
|
||||
self.assertEqual(
|
||||
[Path(call.args[0]) for call in chown.call_args_list],
|
||||
[self.root / database.LOCK_NAME],
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user