-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy_src.py
More file actions
77 lines (62 loc) · 3.04 KB
/
Copy pathdeploy_src.py
File metadata and controls
77 lines (62 loc) · 3.04 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
import subprocess
import datetime
import pathlib
import sys
# Read version from VERSION file
version_file = pathlib.Path(__file__).parent / "VERSION"
version = version_file.read_text().strip() if version_file.exists() else "dev"
# Build timestamp (ISO-8601 UTC)
build_time = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
print(f"[deploy_src] SAGA Engine v{version} — build time: {build_time}")
# ── 1. Create the archive ────────────────────────────────────────────────────
print("[deploy_src] Creating archive...")
subprocess.run([
"tar", "-czf", "deploy_src.tar.gz",
"frontend/src", "frontend/public", "frontend/index.html",
"frontend/package.json",
"backend/app/routers/admin.py",
"backend/app/runtime/core_engine.py",
"main.py",
"VERSION",
], check=True)
# ── 2. SCP to Raspberry Pi ───────────────────────────────────────────────────
print("[deploy_src] Uploading archive to Pi...")
subprocess.run([
"scp", "deploy_src.tar.gz",
"odegaard12@192.168.68.104:/home/odegaard12/saga_engine/"
], check=True)
# ── 3. Remote deploy commands ────────────────────────────────────────────────
print("[deploy_src] Running deploy on Pi...")
remote_cmd = f"""set -e
cd /home/odegaard12/saga_engine
echo "[pi] Extracting archive..."
tar -xzf deploy_src.tar.gz
echo "[pi] Building frontend (Node)..."
docker run --rm \\
-v /home/odegaard12/saga_engine/frontend:/app \\
-w /app node:20-alpine \\
sh -c "npm install && npm run build"
echo "[pi] Copying backend files into container..."
docker cp backend/app/routers/admin.py saga_engine_app:/app/backend/app/routers/admin.py
docker cp backend/app/runtime/core_engine.py saga_engine_app:/app/backend/app/runtime/core_engine.py
docker cp main.py saga_engine_app:/app/main.py
docker cp VERSION saga_engine_app:/app/VERSION
echo "[pi] Copying frontend build..."
docker cp frontend/dist saga_engine_app:/app/frontend/
docker cp frontend/public saga_engine_app:/app/frontend/
docker cp frontend/index.html saga_engine_app:/app/frontend/index.html
docker cp frontend/package.json saga_engine_app:/app/frontend/package.json
echo "[pi] Writing build-info env file inside container..."
docker exec saga_engine_app sh -c "echo 'SAGA_VERSION={version}' > /app/.saga_build_env && echo 'SAGA_BUILD_TIME={build_time}' >> /app/.saga_build_env"
echo "[pi] Restarting container..."
docker restart saga_engine_app
echo "[pi] Done — v{version} at {build_time}"
"""
result = subprocess.run(
["ssh", "odegaard12@192.168.68.104", remote_cmd],
capture_output=False
)
if result.returncode != 0:
print(f"[deploy_src] ERROR: remote deploy failed (exit code {result.returncode})", file=sys.stderr)
sys.exit(result.returncode)
print(f"[deploy_src] OK. v{version} deployed at {build_time}")