Files
deployer/deploy.py
2025-01-08 23:54:57 -05:00

35 lines
795 B
Python

from dataclasses import dataclass
import subprocess
import os
from time import time
@dataclass
class DeployerRequest:
user: str
repo: str
branch: 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(
["./deploy.sh"],
user="root",
stdout=open(log_file, "w"),
stderr=open(log_file, "a"),
shell=True,
env=dict(
os.environ,
DEPLOYERDIR=DEPLOYERDIR,
USER=rq.user,
REPO=rq.repo,
BRANCH=rq.branch
COMMIT_HASH=rq.commit_hash,
),
)