fix(site-publish): retain immutable history across deploys
Authored-By: @architect <architect@fritzlab.net>
This commit is contained in:
+56
-12
@@ -273,16 +273,17 @@ class GenerationTests(unittest.TestCase):
|
||||
self.assertNotIn("passhostheader", files["manifests/ingress-portal.yaml"])
|
||||
self.assertIn("baseline-dist.web.sjc001.fritzlab.net", files["manifests/service-distributions.yaml"])
|
||||
|
||||
def test_yaml_ambiguous_artifact_name_stays_a_string_annotation(self):
|
||||
def test_history_keeps_yaml_ambiguous_artifact_names_as_strings(self):
|
||||
raw = fixture("split-site.yaml")
|
||||
raw["artifacts"][0]["name"] = "yes"
|
||||
raw["routes"][0]["artifact"] = "yes"
|
||||
tmp, _, files = self.render(raw)
|
||||
self.addCleanup(tmp.cleanup)
|
||||
ingress = yaml.safe_load(files["manifests/ingress-portal.yaml"])
|
||||
self.assertEqual(
|
||||
"yes", ingress["metadata"]["annotations"]["site-publish.fritzlab.net/artifact"],
|
||||
)
|
||||
cfg = normalize_site_config(raw, "baseline.fritzlab.net")
|
||||
contracts = deploy.next_route_contracts(cfg, {})
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
app_dir = Path(tmp)
|
||||
deploy.write_route_contracts(app_dir, contracts)
|
||||
restored = deploy.previous_route_contracts(app_dir)
|
||||
self.assertEqual("yes", restored["baseline-portal"]["artifact"])
|
||||
|
||||
def test_generation_is_deterministic_when_input_lists_are_reversed(self):
|
||||
raw = fixture("split-site.yaml")
|
||||
@@ -473,7 +474,7 @@ class PublishingTests(unittest.TestCase):
|
||||
):
|
||||
deploy.s3_sync(artifact, route, root, previous_contract={
|
||||
"path": "/foo", "access": "public", "artifact": "distributions",
|
||||
"immutable_paths": ["releases"],
|
||||
"immutable_prefixes": ["foo/releases"],
|
||||
})
|
||||
rendered = [" ".join(command) for command in commands]
|
||||
self.assertTrue(all("foo/releases/*" in command for command in rendered[:2]))
|
||||
@@ -484,7 +485,7 @@ class PublishingTests(unittest.TestCase):
|
||||
previous = {
|
||||
"baseline-dist": {
|
||||
"path": "/dist", "access": "protected", "artifact": "old-name",
|
||||
"immutable_paths": ["releases"],
|
||||
"immutable_prefixes": ["dist/releases"],
|
||||
}
|
||||
}
|
||||
with self.assertRaisesRegex(RuntimeError, "cannot become public while reusing protected"):
|
||||
@@ -504,7 +505,7 @@ class PublishingTests(unittest.TestCase):
|
||||
previous = {
|
||||
"baseline.fritzlab.net": {
|
||||
"path": "/portal", "access": "protected", "artifact": "portal",
|
||||
"immutable_paths": [],
|
||||
"immutable_prefixes": [],
|
||||
}
|
||||
}
|
||||
with self.assertRaisesRegex(RuntimeError, "cannot become public while reusing protected"):
|
||||
@@ -521,17 +522,60 @@ class PublishingTests(unittest.TestCase):
|
||||
html = Path(tmp)
|
||||
filters = deploy.retired_immutable_filters(artifact, route, html, {
|
||||
"path": "/dist", "access": "public", "artifact": "distributions",
|
||||
"immutable_paths": ["releases"],
|
||||
"immutable_prefixes": ["dist/releases"],
|
||||
})
|
||||
self.assertEqual(["--exclude", "releases/*"], filters)
|
||||
previous = {
|
||||
"baseline-dist": {
|
||||
"path": "/dist", "access": "public", "artifact": "distributions",
|
||||
"immutable_prefixes": ["dist/releases"],
|
||||
}
|
||||
}
|
||||
next_contracts = deploy.next_route_contracts(cfg, previous)
|
||||
self.assertEqual(
|
||||
["dist/releases"], next_contracts["baseline-dist"]["immutable_prefixes"],
|
||||
)
|
||||
self.assertEqual(
|
||||
["--exclude", "releases/*"],
|
||||
deploy.retired_immutable_filters(
|
||||
artifact, route, html, next_contracts["baseline-dist"],
|
||||
),
|
||||
)
|
||||
(html / "releases").mkdir()
|
||||
(html / "releases" / "replacement.js").write_text("mutable")
|
||||
with self.assertRaisesRegex(RuntimeError, "collides with retired immutable"):
|
||||
deploy.retired_immutable_filters(artifact, route, html, {
|
||||
"path": "/dist", "access": "public", "artifact": "distributions",
|
||||
"immutable_paths": ["releases"],
|
||||
"immutable_prefixes": ["dist/releases"],
|
||||
})
|
||||
|
||||
def test_removed_route_history_remains_append_only(self):
|
||||
cfg = normalize_site_config(fixture("split-site.yaml"), "baseline.fritzlab.net")
|
||||
previous = {
|
||||
"retired-bucket": {
|
||||
"path": "/retired", "access": "protected", "artifact": "retired",
|
||||
"immutable_prefixes": ["retired/releases"],
|
||||
}
|
||||
}
|
||||
contracts = deploy.next_route_contracts(cfg, previous)
|
||||
self.assertEqual(previous["retired-bucket"], contracts["retired-bucket"])
|
||||
|
||||
def test_decommission_preserves_history_for_an_unpurged_bucket(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
apps = Path(tmp)
|
||||
site = apps / "sjc001/websites/baseline"
|
||||
site.mkdir(parents=True)
|
||||
history = b'{"schemaVersion":1,"buckets":{}}\n'
|
||||
(site / deploy.HISTORY_FILE).write_bytes(history)
|
||||
(site / "app.yaml").write_text("live\n")
|
||||
with patch.object(deploy, "clone_apps", return_value=apps), patch.object(
|
||||
deploy, "commit_and_push"
|
||||
) as commit:
|
||||
deploy.decommission("baseline", "token", ["baseline-dist"])
|
||||
self.assertEqual(history, (site / deploy.HISTORY_FILE).read_bytes())
|
||||
self.assertFalse((site / "app.yaml").exists())
|
||||
commit.assert_called_once_with(apps, "Decommission baseline", "token")
|
||||
|
||||
def test_later_route_immutable_failure_stops_all_mutable_publication(self):
|
||||
cfg = normalize_site_config(fixture("split-site.yaml"), "baseline.fritzlab.net")
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
|
||||
Reference in New Issue
Block a user