works
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
**/__pycache__/*
|
||||
venv/*
|
||||
production/*
|
||||
3
Makefile
3
Makefile
@@ -4,6 +4,3 @@ build:
|
||||
|
||||
deploy:
|
||||
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:
|
||||
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,
|
||||
),
|
||||
)
|
||||
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,
|
||||
),
|
||||
)
|
||||
|
||||
9
deploy.sh
Normal file → Executable file
9
deploy.sh
Normal file → Executable file
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user