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

View File

@@ -1,6 +1,10 @@
build: build:
@: if [ ! -d venv ]; then
python3 -m venv venv
fi
venv/bin/pip install requirements.txt
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

View File

@@ -18,7 +18,10 @@ def handle_request(rq: DeployerRequest):
log_file = f"{log_folder}/{int(time())}.log" log_file = f"{log_folder}/{int(time())}.log"
subprocess.Popen( 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, shell=True,
env=dict( env=dict(
os.environ, os.environ,

View File

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

2
requirements.txt Normal file
View File

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