From 14f9bb557da4b3f3ee4854d8fdb5dce89caaa737 Mon Sep 17 00:00:00 2001 From: Daniel McCrystal Date: Tue, 7 Jan 2025 22:20:02 -0500 Subject: [PATCH] works --- .gitignore | 3 ++- Makefile | 3 --- deploy.py | 23 +++++++++++++---------- deploy.sh | 9 +++++---- listen.py | 1 + 5 files changed, 21 insertions(+), 18 deletions(-) mode change 100644 => 100755 deploy.sh diff --git a/.gitignore b/.gitignore index 3a66904..f0edf14 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ **/__pycache__/* -venv/* \ No newline at end of file +venv/* +production/* \ No newline at end of file diff --git a/Makefile b/Makefile index 9fa9acf..705168c 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,3 @@ build: deploy: venv/bin/waitress-serve --host 0.0.0.0 --port 5000 listen:app - -stop: - @: \ No newline at end of file diff --git a/deploy.py b/deploy.py index a1a542a..82af8b7 100644 --- a/deploy.py +++ b/deploy.py @@ -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"], - env=dict( - os.environ, - REPO=rq.repo, - BRANCH=rq.branch, - COMMIT_HASH=rq.commit_hash, - ), - ) \ No newline at end of file + 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, + ), + ) diff --git a/deploy.sh b/deploy.sh old mode 100644 new mode 100755 index 9af8355..962c5df --- a/deploy.sh +++ b/deploy.sh @@ -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 diff --git a/listen.py b/listen.py index d0adedc..6436145 100644 --- a/listen.py +++ b/listen.py @@ -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"] ) ) \ No newline at end of file