Files
deployer/deploy.py
2025-01-08 22:59:47 -05:00

32 lines
753 B
Python

from dataclasses import dataclass
import subprocess
import os
from time import time
@dataclass
class DeployerRequest:
repo: str
branch: str
clone_url: str
commit_hash: str
DEPLOYERDIR = "/home/drm/live"
def handle_request(rq: DeployerRequest):
log_folder = f"./logs/{rq.repo}/{rq.branch}"
os.makedirs(log_folder, exist_ok=True)
log_file = f"{log_folder}/{int(time())}.log"
subprocess.Popen(
f"sudo -E ./deploy.sh > {log_file} >2 {log_file}",
shell=True,
env=dict(
os.environ,
DEPLOYERDIR=DEPLOYERDIR,
REPO=rq.repo,
BRANCH=rq.branch,
CLONE_URL=rq.clone_url,
COMMIT_HASH=rq.commit_hash,
),
)