-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.py
More file actions
executable file
·90 lines (72 loc) · 2.11 KB
/
build.py
File metadata and controls
executable file
·90 lines (72 loc) · 2.11 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3
import shlex
import shutil
import subprocess
from pathlib import Path
from sys import argv
def main():
if len(argv) == 1:
build_js()
build_py()
return
if len(argv) == 2:
# I prefer explicitly listing all possible commands here,
# for both safety and readability.
commands = {
"js": build_js,
"py": build_py,
"deploy": deploy,
}
commands[argv[1]]()
def build_js():
run(
"esbuild",
"src/pytaku/js-src/main.js",
"--bundle",
"--sourcemap",
"--minify",
"--outfile=src/pytaku/static/js/main.min.js",
)
def build_py():
shutil.rmtree("dist")
Path("dist").mkdir()
run("uv", "build")
def deploy():
hostname = "pytaku"
# Ensure necessary dirs
run("ssh", hostname, "mkdir", "-p", "/opt/pytaku/workdir", "/opt/pytaku/venv")
# Upload and install latest source distribution
sdist = list(path for path in Path("dist").glob("*.tar.gz"))[0]
run("scp", str(sdist), f"{hostname}:/tmp/pytaku.tar.gz")
run(
"ssh",
hostname,
"/opt/pytaku/venv/bin/pip",
"install",
"--force-reinstall",
"/tmp/pytaku.tar.gz",
)
# # Optional: copy static files into a separate dir for nginx/caddy to serve.
# # Personally I don't use it for my demo instance.
# run("ssh", hostname, "rm", "-rf", "/opt/pytaku/workdir/static")
# run(
# "ssh",
# hostname,
# "/opt/pytaku/venv/bin/pytaku-collect-static",
# "/opt/pytaku/workdir",
# )
# Install & restart systemd services
services = ("pytaku", "pytaku-scheduler")
for service in services:
run(
"scp",
f"contrib/systemd/{service}.service",
f"{hostname}:/etc/systemd/system/",
)
run("ssh", hostname, "systemctl", "daemon-reload")
run("ssh", hostname, "systemctl", "restart", *services)
def run(*cmd):
print("RUN:", " ".join(shlex.quote(arg) for arg in cmd))
return subprocess.run(cmd, check=True)
if __name__ == "__main__":
main()