35 lines
813 B
Python
35 lines
813 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"/home/drm/deployer-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,
|
|
),
|
|
)
|