This commit is contained in:
2025-01-08 23:34:15 -05:00
parent 35877c2762
commit c46b465a19
5 changed files with 21 additions and 8 deletions

3
.gitignore vendored
View File

@@ -1,4 +1,5 @@
**/__pycache__/*
venv/*
production/*
test*
test*
logs/*

View File

@@ -1,6 +1,10 @@
build:
@:
if [ ! -d venv ]; then
python3 -m venv venv
fi
venv/bin/pip install requirements.txt
deploy:
venv/bin/waitress-serve --host 0.0.0.0 --port 5000 listen:app

View File

@@ -18,7 +18,10 @@ def handle_request(rq: DeployerRequest):
log_file = f"{log_folder}/{int(time())}.log"
subprocess.Popen(
f"sudo -E ./deploy.sh > {log_file} >2 {log_file}",
["./deploy.sh"],
user="root",
stdout=open(log_file, "w"),
stderr=open(log_file, "a"),
shell=True,
env=dict(
os.environ,

View File

@@ -1,16 +1,19 @@
#!/bin/bash
deploydir=$DEPLOYERDIR/$REPO/$BRANCH
mkdir -p $deploydir
mkdir -p $deploydir/src
cd $deploydir
git clone $CLONE_URL .
git clone $CLONE_URL ./src
cd src
git fetch origin $BRANCH
git reset --hard origin/$BRANCH
git checkout $COMMIT_HASH
make build
cd ..
echo "
[Unit]
Description=Deployment of $REPO/$BRANCH
@@ -20,7 +23,7 @@ After=network.target
Type=simple
ExecStart=make deploy
User=drm
WorkingDirectory=$deploydir
WorkingDirectory=$deploydir/src
Restart=on-failure
StandardOutput=file:$deploydir/server.log
StandardError=file:$deploydir/server.log
@@ -28,11 +31,11 @@ StandardError=file:$deploydir/server.log
[Install]
WantedBy=multi-user.target
" > deploy.service
systemctl daemon-reload
service="deployer-$REPO-$BRANCH.service"
echo /etc/systemd/system/$service
ln -s $deploydir/deploy.service /etc/systemd/system/$service
sudo systemctl daemon-reload
systemctl stop $service
systemctl start $service

2
requirements.txt Normal file
View File

@@ -0,0 +1,2 @@
flask
waitress