-
Notifications
You must be signed in to change notification settings - Fork 3
/
fabfile.py
31 lines (25 loc) · 1.01 KB
/
fabfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import subprocess
import sys
from pathlib import Path
from typing import Optional
from fabric import Connection, task # type: ignore[import-untyped]
@task
def deploy(
c: object, package: Optional[str] = None, target_directory: Optional[str] = None
) -> None:
if not isinstance(c, Connection):
sys.exit("usage: fab -H user@host deploy [--package=FILE] [--target-directory=DIRECTORY]")
if package:
directory = str(Path(package).parent)
filename = Path(package).name
else:
version = subprocess.check_output(["uv", "run", "hatch", "version"]).decode("utf-8").strip()
directory = "dist"
filename = f"valens-{version}-py3-none-any.whl"
if not target_directory:
target_directory = "/srv/http/valens"
filepath = f"{target_directory}/{filename}"
c.put(f"{directory}/{filename}", filepath)
c.run(f"{target_directory}/venv/bin/pip install --force-reinstall {filepath}")
c.run(f"rm {filepath}")
c.run("systemctl restart uwsgi@valens", pty=True)