Skip to content
File

Blob: scripts/deploy_worker.py

python35 lines
1#!/usr/bin/env python3
2"""Deploy the Worker with only its four production secrets. Supports --dry-run."""
3import argparse
4import json
5import os
6from pathlib import Path
7import subprocess
8import tempfile
9from credentials import worker_secrets
10from project import ROOT
11 
12def main(argv=None):
13 parser = argparse.ArgumentParser(description=__doc__)
14 parser.add_argument("--dry-run", action="store_true")
15 args = parser.parse_args(argv)
16 application = ROOT / "worker"
17 config = application / "dist/esp32_radio/wrangler.json"
18 if not config.exists():
19 raise SystemExit("Run make build-web before deploying the Vite application")
20 values = worker_secrets(ROOT)
21 os.umask(0o077)
22 with tempfile.TemporaryDirectory(prefix="pocket-radio-deploy-") as directory:
23 secret_file = Path(directory) / "secrets.json"
24 secret_file.write_text(json.dumps(values))
25 secret_file.chmod(0o600)
26 command = [str(application / "node_modules/.bin/wrangler"), "deploy", "--no-autoconfig", "--config", str(config),
27 "--secrets-file", str(secret_file)]
28 if args.dry_run: command.append("--dry-run")
29 result = subprocess.run(command, cwd=application)
30 raise SystemExit(result.returncode)
31 
32 
33if __name__ == "__main__":
34 main()