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, ), )