Commit 3c0785d60675c148b9332641f679b055d67fc882

Authored by hitier
1 parent 65f2cab9

Auto deploy to apache wsgi

INSTALL.md
... ... @@ -9,12 +9,43 @@ update your server installation
9 9 ress/flaskenv > .flaskenv
10 10 run tests
11 11 PYTHONPATH=. pytest --cov=app --cov-report=xml:"coverage.xml" --cov-report=term --junitxml "tests-report.xml"
12   -install apache
  12 +
  13 +install
  14 +-------
  15 +
  16 +make working dir:
  17 +
  18 + mkdir /path/to/working-directory
  19 + git --work-tree=/path/to/working-directory --git-dir=/path/to/the/repo.git checkout -f master
  20 +
  21 +set environment
  22 +
  23 + python3 -m venv venv
  24 + source venv/bin/activate
  25 + pip install -r requirements.txt
  26 + cp resources/pdc_config.py .
  27 + $(EDITOR) pdc_config.py
  28 +
  29 +git autodeploy
13 30 --------------
  31 +
  32 + # make bare repo
  33 + git clone --bare /path/to/the/repo.git
  34 + # put on hook
  35 + cp /path/to/working-directory/resources/post-receive.git-hook
  36 +
  37 +configure apache
  38 +----------------
  39 +
  40 + cp ./resources/apache2-virtual-host.conf /etc/apache2/sites-available/pdc-web.conf
  41 + $(EDITOR) /etc/apache2/sites-available/pdc-web.conf # set parameters
  42 + $(EDITOR) /etc/hosts # to add your hostname if local install
  43 + apachectl restart
  44 +
  45 +virtual-apage.conf
14 46 pdc_web.py
15 47 pdc_web.wsgi
16 48 .flaskenv
17 49 post-deploy.sh
18 50 git-hook
19   -virtual-apage.conf
20 51 git bare repo
... ...
resources/apache2-virtual-host.conf
... ... @@ -39,8 +39,8 @@ Define flaskapp_group apache
39 39 #
40 40 # Virtualhost log config doesnt show stdout/err see before
41 41 # ErrorLog ${flaskapp_path}/flaskapp-error.log
42   - # TransferLog ${flaskapp_path}/aroma-access.log
43   - # CustomLog ${flaskapp_path}/aroma-custom.log combined
  42 + # TransferLog ${flaskapp_path}/flaskapp-access.log
  43 + # CustomLog ${flaskapp_path}/flaskapp-custom.log combined
44 44  
45 45 # python-home is the virtual env path
46 46 # python-path sets the PYTHON_PATH for modules import
... ...
resources/post-receive.git-hook
... ... @@ -37,8 +37,9 @@
37 37 # $TARGET: is the working dir you want to update at last
38 38 # $BRANCH: is the branch you want to update from
39 39 #
40   -TARGET="/var/www/aroma-db"
  40 +TARGET="/var/www/pdc-web/"
41 41 BRANCH="DEV"
  42 +GIT_DIR="/path/to/pdc-web.git/"
42 43  
43 44 while read oldrev newrev ref
44 45 do
... ... @@ -46,24 +47,20 @@ do
46 47 if [ "$ref" = "refs/heads/$BRANCH" ];
47 48 then
48 49 echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
  50 + -d $TARGET || exit
  51 + git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f $BRANCH
49 52 cd $TARGET || exit
50   - unset GIT_DIR
51   - git stash # remove any modification, sorry guy.
52   - git checkout ${BRANCH} # set branch if not done yet, sorry guy
53   - git pull origin ${BRANCH} # get latest modifications, assumes remote origin previously set
54 53 touch *wsgi # now, trigger wsgidaemons restarting
55 54 /bin/sh scripts/post-deploy.sh
56   - exec git update-server-info
57 55 else
58 56 echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
59 57 fi
60 58 done
61 59  
62   -# Alternately, it is possible to just update a
63   -# working tree without any git meta data in it with the
64   -# following instruction:
65   -# $GIT_DIR: is the directory of current bare repo
66   -# GIT_DIR="/home/richard/aroma-db.git/"
67   -# git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f $BRANCH
  60 +# Alternately, it is possible to just update a git repo
  61 +# git stash # remove any modification, sorry guy.
  62 +# git checkout ${BRANCH} # set branch if not done yet, sorry guy
  63 +# git pull origin ${BRANCH} # get latest modifications, assumes remote origin previously set
  64 +# exec git update-server-info
68 65  
69 66 # vim: ft=sh
... ...