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__/* **/__pycache__/*
venv/* venv/*
production/*

View File

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

View File

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

9
deploy.sh Normal file → Executable file
View File

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

View File

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