more updates

This commit is contained in:
2025-07-30 21:57:31 -04:00
parent 93954f3190
commit 5d71c964b7
4 changed files with 46 additions and 14 deletions

View File

@@ -8,4 +8,4 @@ build:
start: start:
sudo venv/bin/waitress-serve --host 0.0.0.0 --port 5000 listen:app sudo venv/bin/waitress-serve --host 0.0.0.0 --port $(PORT) listen:app

View File

@@ -16,7 +16,10 @@ class DeployerRequest:
DEPLOYERDIR = "/home/drm/live" DEPLOYERDIR = "/home/drm/live"
BASE_PORT = 3001 BASE_PORT = 3001
config = {"games": {"user": "drm", "repo": "games", "branch": "prod"}} config = {
"deployer": ("drm", "deployer", "main"),
"games": ("drm", "games", "prod"),
}
by_branch = { by_branch = {
(user, repo, branch): {"domain": domain, "port": BASE_PORT + i} (user, repo, branch): {"domain": domain, "port": BASE_PORT + i}
for i, (domain, (user, repo, branch)) in enumerate(config.items()) for i, (domain, (user, repo, branch)) in enumerate(config.items())
@@ -25,18 +28,22 @@ by_branch = {
def handle_request(rq: DeployerRequest): def handle_request(rq: DeployerRequest):
if (rq.user, rq.repo, rq.branch) not in by_branch: if (rq.user, rq.repo, rq.branch) not in by_branch:
print(
f"{rq.user}/{rq.repo}/{rq.branch} is not registered in the deployer config"
)
print(by_branch)
return return
domain, port = itemgetter("domain", "port")( domain, port = itemgetter("domain", "port")(
by_branch[(rq.user, rq.repo, rq.branch)] by_branch[(rq.user, rq.repo, rq.branch)]
) )
deployment_id = int(time()) deployment_id = str(int(time()))
domain_dir = f"{DEPLOYERDIR}/{domain}" domain_dir = f"{DEPLOYERDIR}/{domain}"
deployment_dir = f"{domain_dir}/{deployment_id}" logs_dir = f"{domain_dir}/{deployment_id}"
os.makedirs(deployment_dir, exist_ok=True) os.makedirs(logs_dir, exist_ok=True)
build_log = f"{deployment_dir}/build.log" build_log = f"{logs_dir}/build.log"
subprocess.Popen( subprocess.Popen(
["./deploy.sh"], ["./deploy.sh"],
@@ -47,11 +54,12 @@ def handle_request(rq: DeployerRequest):
env=dict( env=dict(
os.environ, os.environ,
DOMAIN=domain, DOMAIN=domain,
DEPLOYMENT_DIR=deployment_dir, DOMAIN_DIR=domain_dir,
LOGS_DIR=logs_dir,
USER=rq.user, USER=rq.user,
REPO=rq.repo, REPO=rq.repo,
BRANCH=rq.branch, BRANCH=rq.branch,
COMMIT_HASH=rq.commit_hash, COMMIT_HASH=rq.commit_hash,
PORT=port, PORT=str(port),
), ),
) )

View File

@@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
cd $DEPLOYMENT_DIR cd $DOMAIN_DIR
# Create our service configuration # Create our service configuration
service_file=$DOMAIN.service service_file=$DOMAIN.service
@@ -10,17 +10,31 @@ After=network.target
[Service] [Service]
Type=simple Type=simple
ExecStart=make start ExecStart='PORT=$PORT make start'
User=drm User=drm
WorkingDirectory=$DEPLOYMENT_DIR/src WorkingDirectory=$DOMAIN_DIR/src
Restart=on-failure Restart=on-failure
StandardOutput=file:$DEPLOYMENT_DIR/start.log StandardOutput=file:$LOGS_DIR/start.log
StandardError=file:$DEPLOYMENT_DIR/start.log StandardError=file:$LOGS_DIR/start.log
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
" > $service_file " > $service_file
echo "
SHELL := /bin/bash
status:
systemctl status deployer-$DOMAIN
logs:
journalctl -u deployer-$DOMAIN
stop
systemctl stop deployer-$DOMAIN
" > Makefile
# create a folder to put the source code # create a folder to put the source code
mkdir -p src mkdir -p src
@@ -41,7 +55,7 @@ make build
cd .. cd ..
service="deployer-$DOMAIN.service" service="deployer-$DOMAIN.service"
ln -sf $DEPLOYMENT_DIR/$service_file /etc/systemd/system/$service ln -sf $DOMAIN_DIR/$service_file /etc/systemd/system/$service
systemctl daemon-reload systemctl daemon-reload
systemctl restart $service systemctl restart $service

10
deploy_self.py Normal file
View File

@@ -0,0 +1,10 @@
from deploy import DeployerRequest, handle_request
handle_request(
DeployerRequest(
user="drm",
repo="deployer",
branch="main",
commit_hash="93954f3190f7bbcbf29df2f68ebc400acb47cda9",
)
)