File
Blob: scripts/deploy_worker.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Deploy the Worker with only its four production secrets. Supports --dry-run.""" |
| 3 | import argparse |
| 4 | import json |
| 5 | import os |
| 6 | from pathlib import Path |
| 7 | import subprocess |
| 8 | import tempfile |
| 9 | from credentials import worker_secrets |
| 10 | from project import ROOT |
| 11 | |
| 12 | def 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 | |
| 33 | if __name__ == "__main__": |
| 34 | main() |