forked from mtusi2026/mtusi2026lab3
41 lines
1.7 KiB
Python
41 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Build committed sources with fresh secrets/volumes on a separate local test port."""
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
CLONE = ROOT / 'output' / 'clean-check'
|
|
ENV = dict(os.environ, PYTHONUTF8='1', PYTHONIOENCODING='utf-8', APP_PORT='8081', API_REPLICAS='2')
|
|
|
|
|
|
def run(args, cwd=CLONE):
|
|
result = subprocess.run(args, cwd=cwd, env=ENV, text=True, encoding='utf-8', errors='replace',
|
|
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
print(result.stdout, end='', flush=True)
|
|
if result.returncode:
|
|
raise RuntimeError('Clean checkout check failed; see command output')
|
|
|
|
|
|
def main():
|
|
if CLONE.exists():
|
|
raise SystemExit('output/clean-check already exists; preserve it or move it before a fresh run')
|
|
CLONE.parent.mkdir(exist_ok=True)
|
|
run(['git', 'clone', '--no-hardlinks', str(ROOT), str(CLONE)], cwd=ROOT)
|
|
assert not (CLONE / '.env').exists() and not (CLONE / 'secrets').exists()
|
|
run([sys.executable, '-X', 'utf8', 'scripts/bootstrap.py'])
|
|
dc = ['docker', 'compose', '-p', 'mtusi-lab3-osokin-clean', '--env-file', '.env']
|
|
try:
|
|
run([*dc, 'up', '-d', '--build', '--wait'])
|
|
run([sys.executable, '-X', 'utf8', 'tests/smoke.py', '--base-url', 'http://127.0.0.1:8081'])
|
|
run([*dc, 'exec', '-T', 'api', 'python', 'student-tests/test_idempotency.py'])
|
|
run([*dc, 'ps', '--all'])
|
|
print('PASS: committed clean clone, new secrets, fresh project volumes, smoke and concurrent replay.')
|
|
finally:
|
|
run([*dc, 'down']) # Keep even the disposable test data; never down --volumes here.
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|