works
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
**/__pycache__/*
|
**/__pycache__/*
|
||||||
venv/*
|
venv/*
|
||||||
|
production/*
|
||||||
3
Makefile
3
Makefile
@@ -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:
|
|
||||||
@:
|
|
||||||
23
deploy.py
23
deploy.py
@@ -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,
|
||||||
REPO=rq.repo,
|
DEPLOYERDIR=DEPLOYERDIR,
|
||||||
BRANCH=rq.branch,
|
REPO=rq.repo,
|
||||||
COMMIT_HASH=rq.commit_hash,
|
BRANCH=rq.branch,
|
||||||
),
|
CLONE_URL=rq.clone_url,
|
||||||
)
|
COMMIT_HASH=rq.commit_hash,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|||||||
9
deploy.sh
Normal file → Executable file
9
deploy.sh
Normal file → Executable 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
|
||||||
|
|||||||
@@ -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"]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
Reference in New Issue
Block a user