feat: setup dataset enrichment app codebase and scripts
This commit is contained in:
1 parent
b5c28cc98a
commit
d07578462e
72 files changed
+11370
No files matched your search
Executable
+46
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Auto-pull service: monitors origin/main and pulls new commits automatically."""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
INTERVAL_SECONDS = int(os.environ.get("AUTO_PULL_INTERVAL", 30))
|
||||
REPO_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
def run_git(args):
|
||||
res = subprocess.run(["git"] + args, cwd=REPO_DIR, capture_output=True, text=True)
|
||||
return res.returncode == 0, res.stdout.strip(), res.stderr.strip()
|
||||
|
||||
def check_and_pull():
|
||||
# Fetch latest remote changes quietly
|
||||
ok, _, err = run_git(["fetch", "origin", "main"])
|
||||
if not ok:
|
||||
print(f"[Auto-Pull] Git fetch error: {err}")
|
||||
return
|
||||
|
||||
_, incoming_commits, _ = run_git(["log", "HEAD..origin/main", "--oneline"])
|
||||
|
||||
if incoming_commits:
|
||||
print(f"[Auto-Pull] Incoming commits detected:\n{incoming_commits}")
|
||||
ok, out, err = run_git(["pull", "origin", "main"])
|
||||
if ok:
|
||||
print(f"[Auto-Pull] Successfully pulled:\n{out}")
|
||||
print("[Auto-Pull] Restarting app services...")
|
||||
restart_script = os.path.join(REPO_DIR, "scripts", "restart_app.sh")
|
||||
subprocess.run(["bash", restart_script], cwd=REPO_DIR)
|
||||
else:
|
||||
print(f"[Auto-Pull] Pull failed:\n{err}")
|
||||
|
||||
def main():
|
||||
print(f"🔄 Auto-pull background poller started (Interval: {INTERVAL_SECONDS}s)")
|
||||
while True:
|
||||
try:
|
||||
check_and_pull()
|
||||
except Exception as exc:
|
||||
print(f"[Auto-Pull] Error: {exc}")
|
||||
time.sleep(INTERVAL_SECONDS)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
cd "$REPO_DIR"
|
||||
|
||||
echo "🔄 Restarting app services..."
|
||||
|
||||
# Kill running uvicorn and vite processes
|
||||
pkill -f "uvicorn backend.main:app" || true
|
||||
pkill -f "vite" || true
|
||||
sleep 1
|
||||
|
||||
export PATH="$HOME/.local/bin:$PATH"
|
||||
|
||||
# Run backend
|
||||
nohup uv run uvicorn backend.main:app --host 0.0.0.0 --port 8000 > "$REPO_DIR/data/backend.log" 2>&1 &
|
||||
|
||||
# Run frontend
|
||||
cd "$REPO_DIR/frontend"
|
||||
nohup npm run dev > "$REPO_DIR/data/frontend.log" 2>&1 &
|
||||
|
||||
echo "✅ Services restarted."
|
||||
Executable
+67
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env python3
|
||||
"""GitHub Webhook Listener for Auto-Pull on Push."""
|
||||
|
||||
import hmac
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
|
||||
PORT = int(os.environ.get("WEBHOOK_PORT", 9000))
|
||||
SECRET = os.environ.get("WEBHOOK_SECRET", "").encode("utf-8")
|
||||
REPO_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
class WebhookHandler(BaseHTTPRequestHandler):
|
||||
def do_POST(self):
|
||||
if self.path != "/webhook":
|
||||
self.send_response(404)
|
||||
self.end_headers()
|
||||
return
|
||||
|
||||
content_length = int(self.headers.get("Content-Length", 0))
|
||||
body = self.rfile.read(content_length)
|
||||
|
||||
if SECRET:
|
||||
signature = self.headers.get("X-Hub-Signature-256", "")
|
||||
expected = "sha256=" + hmac.new(SECRET, body, hashlib.sha256).hexdigest()
|
||||
if not hmac.compare_digest(signature, expected):
|
||||
self.send_response(403)
|
||||
self.end_headers()
|
||||
self.wfile.write(b"Invalid signature\n")
|
||||
return
|
||||
|
||||
event = self.headers.get("X-GitHub-Event", "push")
|
||||
if event == "push":
|
||||
print("[Webhook] Received push event. Pulling latest code...")
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["git", "pull", "origin", "main"],
|
||||
cwd=REPO_DIR,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
)
|
||||
output = result.stdout
|
||||
print(f"[Webhook] Git pull success:\n{output}")
|
||||
self.send_response(200)
|
||||
self.end_headers()
|
||||
self.wfile.write(f"Updated successfully:\n{output}".encode("utf-8"))
|
||||
except subprocess.CalledProcessError as err:
|
||||
error_msg = f"Git pull failed:\n{err.stderr}"
|
||||
print(f"[Webhook] {error_msg}")
|
||||
self.send_response(500)
|
||||
self.end_headers()
|
||||
self.wfile.write(error_msg.encode("utf-8"))
|
||||
else:
|
||||
self.send_response(200)
|
||||
self.end_headers()
|
||||
self.wfile.write(f"Ignored event: {event}\n".encode("utf-8"))
|
||||
|
||||
def main():
|
||||
server = HTTPServer(("0.0.0.0", PORT), WebhookHandler)
|
||||
print(f"🚀 GitHub Webhook listener running on http://0.0.0.0:{PORT}/webhook")
|
||||
server.serve_forever()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user