-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
30 lines (22 loc) · 896 Bytes
/
Copy pathmain.py
File metadata and controls
30 lines (22 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""Demo: a good release deploys; a bad one rolls back completely."""
from __future__ import annotations
import tempfile
from pathlib import Path
from patterns.modern.context_manager.examples.atomic_deploy.deploy import (
ReleaseError,
deploy,
require_nonempty,
)
def main() -> None:
with tempfile.TemporaryDirectory() as tmp:
target = Path(tmp)
deploy({"app.toml": "retries = 3\n", "logging.toml": "level = 'info'\n"}, target)
print(f"v1 deployed: {sorted(p.name for p in target.iterdir())}")
bad_release = {"app.toml": "retries = 5\n", "logging.toml": " "}
try:
deploy(bad_release, target, validate=require_nonempty)
except ReleaseError as exc:
print(f"v2 rejected ({exc})")
print(f"app.toml still reads: {(target / 'app.toml').read_text().strip()}")
if __name__ == "__main__":
main()