From 3c0785d60675c148b9332641f679b055d67fc882 Mon Sep 17 00:00:00 2001 From: Richard Hitier Date: Sat, 13 Feb 2021 15:07:29 +0100 Subject: [PATCH] Auto deploy to apache wsgi --- INSTALL.md | 35 +++++++++++++++++++++++++++++++++-- resources/apache2-virtual-host.conf | 4 ++-- resources/post-receive.git-hook | 21 +++++++++------------ 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 4027cf2..ffb5520 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -9,12 +9,43 @@ update your server installation ress/flaskenv > .flaskenv run tests PYTHONPATH=. pytest --cov=app --cov-report=xml:"coverage.xml" --cov-report=term --junitxml "tests-report.xml" -install apache + +install +------- + +make working dir: + + mkdir /path/to/working-directory + git --work-tree=/path/to/working-directory --git-dir=/path/to/the/repo.git checkout -f master + +set environment + + python3 -m venv venv + source venv/bin/activate + pip install -r requirements.txt + cp resources/pdc_config.py . + $(EDITOR) pdc_config.py + +git autodeploy -------------- + + # make bare repo + git clone --bare /path/to/the/repo.git + # put on hook + cp /path/to/working-directory/resources/post-receive.git-hook + +configure apache +---------------- + + cp ./resources/apache2-virtual-host.conf /etc/apache2/sites-available/pdc-web.conf + $(EDITOR) /etc/apache2/sites-available/pdc-web.conf # set parameters + $(EDITOR) /etc/hosts # to add your hostname if local install + apachectl restart + +virtual-apage.conf pdc_web.py pdc_web.wsgi .flaskenv post-deploy.sh git-hook -virtual-apage.conf git bare repo diff --git a/resources/apache2-virtual-host.conf b/resources/apache2-virtual-host.conf index 6857bd1..476bc04 100644 --- a/resources/apache2-virtual-host.conf +++ b/resources/apache2-virtual-host.conf @@ -39,8 +39,8 @@ Define flaskapp_group apache # # Virtualhost log config doesnt show stdout/err see before # ErrorLog ${flaskapp_path}/flaskapp-error.log - # TransferLog ${flaskapp_path}/aroma-access.log - # CustomLog ${flaskapp_path}/aroma-custom.log combined + # TransferLog ${flaskapp_path}/flaskapp-access.log + # CustomLog ${flaskapp_path}/flaskapp-custom.log combined # python-home is the virtual env path # python-path sets the PYTHON_PATH for modules import diff --git a/resources/post-receive.git-hook b/resources/post-receive.git-hook index 126b543..6cef232 100644 --- a/resources/post-receive.git-hook +++ b/resources/post-receive.git-hook @@ -37,8 +37,9 @@ # $TARGET: is the working dir you want to update at last # $BRANCH: is the branch you want to update from # -TARGET="/var/www/aroma-db" +TARGET="/var/www/pdc-web/" BRANCH="DEV" +GIT_DIR="/path/to/pdc-web.git/" while read oldrev newrev ref do @@ -46,24 +47,20 @@ do if [ "$ref" = "refs/heads/$BRANCH" ]; then echo "Ref $ref received. Deploying ${BRANCH} branch to production..." + -d $TARGET || exit + git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f $BRANCH cd $TARGET || exit - unset GIT_DIR - git stash # remove any modification, sorry guy. - git checkout ${BRANCH} # set branch if not done yet, sorry guy - git pull origin ${BRANCH} # get latest modifications, assumes remote origin previously set touch *wsgi # now, trigger wsgidaemons restarting /bin/sh scripts/post-deploy.sh - exec git update-server-info else echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server." fi done -# Alternately, it is possible to just update a -# working tree without any git meta data in it with the -# following instruction: -# $GIT_DIR: is the directory of current bare repo -# GIT_DIR="/home/richard/aroma-db.git/" -# git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f $BRANCH +# Alternately, it is possible to just update a git repo +# git stash # remove any modification, sorry guy. +# git checkout ${BRANCH} # set branch if not done yet, sorry guy +# git pull origin ${BRANCH} # get latest modifications, assumes remote origin previously set +# exec git update-server-info # vim: ft=sh -- libgit2 0.21.2