diff options
Diffstat (limited to 'tools/deploy.py')
-rwxr-xr-x | tools/deploy.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tools/deploy.py b/tools/deploy.py new file mode 100755 index 0000000..26048e8 --- /dev/null +++ b/tools/deploy.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 + + +import argparse +import subprocess +import pathlib + + +SCRIPT = pathlib.Path(__file__) +SOURCE_ROOT = SCRIPT.parent.parent.resolve() +ARTIFACTS_DEFAULT = SOURCE_ROOT / "build" / "artifacts" + + +def main() -> None: + parser = argparse.ArgumentParser( + description="Use OpenSSH and rsync to deploy artifacts", + ) + + parser.add_argument( + "-a", + "--artifacts", + default=ARTIFACTS_DEFAULT, + help="local path to artifacts folder", + ) + parser.add_argument( + "-H", "--host", default="cloud", help="target `Host` name from ~/.ssh/config" + ) + parser.add_argument( + "-p", + "--path", + default="/srv/http/deploy.xengineering.eu/public/git/iot-contact/main/", + help="remote path to destination folder on server", + ) + parser.add_argument( + "-d", + "--dry-run", + action="store_true", + help="do not execute command and instead print it", + ) + + args = parser.parse_args() + + command = [ + "rsync", + "-av", + "--delete", + f"{str(pathlib.Path(args.artifacts).resolve())}/", + f"{args.host}:{args.path}", + ] + + if args.dry_run: + print(command) + else: + subprocess.run(command, shell=False, check=True) + + +if __name__ == "__main__": + main() |