This commit is contained in:
2025-01-07 22:20:02 -05:00
parent c3ef3f2dd5
commit 14f9bb557d
5 changed files with 21 additions and 18 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
**/__pycache__/*
venv/*
production/*

View File

@@ -4,6 +4,3 @@ build:
deploy:
venv/bin/waitress-serve --host 0.0.0.0 --port 5000 listen:app
stop:
@:

View File

@@ -6,17 +6,20 @@ import os
class DeployerRequest:
repo: str
branch: str
clone_url: str
commit_hash: str
DEPLOYERDIR = "/home/drm/deployer/production"
def handle_request(rq: DeployerRequest):
subprocess.run(
["./deploy.sh"],
subprocess.Popen(
["sudo", "-E", "./deploy.sh"],
env=dict(
os.environ,
DEPLOYERDIR=DEPLOYERDIR,
REPO=rq.repo,
BRANCH=rq.branch,
CLONE_URL=rq.clone_url,
COMMIT_HASH=rq.commit_hash,
),
)

9
deploy.sh Normal file → Executable file
View File

@@ -1,9 +1,9 @@
#!/bin/bash
$rootdir=$(pwd)
$deploydir=$rootdir/deployments/$REPO/$BRANCH
deploydir=$DEPLOYERDIR/$REPO/$BRANCH
mkdir -p $deploydir
cd $deploydir
git clone $CLONE_URL .
git fetch origin $BRANCH
@@ -28,9 +28,10 @@ StandardError=file:$deploydir/server.log
[Install]
WantedBy=multi-user.target
" > deploy.service
systemctl daemon reload
systemctl daemon-reload
$service="deployer-$repo-$branch.service"
service="deployer-$REPO-$BRANCH.service"
echo /etc/systemd/system/$service
ln -s $deploydir/deploy.service /etc/systemd/system/$service
systemctl stop $service
systemctl start $service

View File

@@ -13,6 +13,7 @@ def gitea():
DeployerRequest(
repo = data["repository"]["name"],
branch = data["ref"].strip("refs/heads/"),
clone_url = data["repository"]["clone_url"]
commit_hash = data["after"]
)
)