|
| 1 | +#! /usr/bin/env python3 |
| 2 | + |
| 3 | +import os |
| 4 | +import tempfile |
| 5 | +import subprocess |
| 6 | +from typing import Tuple |
| 7 | +from pathlib import Path |
| 8 | +import shlex |
| 9 | + |
| 10 | +KNOWN_HOSTS = ''' |
| 11 | +flexflow.ai ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAING3BmAIYc0G5hxIFPqQrgLjCt2t4vlRaLxds3QY6MaE |
| 12 | +''' |
| 13 | + |
| 14 | +def create_ssh_key_file(d: Path) -> Tuple[Path, Path]: |
| 15 | + d.chmod(0o700) |
| 16 | + |
| 17 | + ssh_private_key_path = d / 'id_ed25519' |
| 18 | + ssh_private_key_path.touch(mode=0o600, exist_ok=False) |
| 19 | + |
| 20 | + ssh_known_hosts_path = d / 'known_hosts' |
| 21 | + ssh_known_hosts_path.touch(mode=0o600, exist_ok=False) |
| 22 | + |
| 23 | + ssh_private_key_path.write_text(os.environ['SSH_PRIVATE_KEY'] + '\n') |
| 24 | + ssh_known_hosts_path.write_text(KNOWN_HOSTS) |
| 25 | + |
| 26 | + return ssh_private_key_path, ssh_known_hosts_path |
| 27 | + |
| 28 | +def deploy(ssh_private_key_path: Path, ssh_known_hosts_path: Path) -> None: |
| 29 | + assert ssh_private_key_path.is_file() |
| 30 | + assert ssh_known_hosts_path.is_file() |
| 31 | + |
| 32 | + docs_html_dir = Path('./build/doxygen/html/') |
| 33 | + assert docs_html_dir.is_dir() |
| 34 | + assert (docs_html_dir / 'index.html').is_file() |
| 35 | + |
| 36 | + ssh_command = shlex.join([ |
| 37 | + 'ssh', '-i', str(ssh_private_key_path), '-o', f'UserKnownHostsFile={ssh_known_hosts_path}', |
| 38 | + ]) |
| 39 | + print(ssh_command) |
| 40 | + subprocess.run( |
| 41 | + [ |
| 42 | + 'rsync', |
| 43 | + '--delete', |
| 44 | + '--recursive', |
| 45 | + '--verbose', |
| 46 | + '--human-readable', |
| 47 | + f'--rsh={ssh_command}', |
| 48 | + str(docs_html_dir) + '/', |
| 49 | + 'deploy-ff-train-docs@flexflow.ai:/opt/www/ff-train-docs/', |
| 50 | + ], |
| 51 | + check=True, |
| 52 | + ) |
| 53 | + |
| 54 | +if __name__ == '__main__': |
| 55 | + with tempfile.TemporaryDirectory() as _d: |
| 56 | + d = Path(_d) |
| 57 | + |
| 58 | + ssh_private_key_path, ssh_known_hosts_path = create_ssh_key_file(d) |
| 59 | + |
| 60 | + deploy( |
| 61 | + ssh_private_key_path=ssh_private_key_path, |
| 62 | + ssh_known_hosts_path=ssh_known_hosts_path, |
| 63 | + ) |
0 commit comments