Commit 74b778d4 authored by Romain Loth's avatar Romain Loth

update doc and run script

parent fa17b805
#! /bin/bash
usage() { echo -e "Usage: $0 [-d|-p]\n -d dev mode (app bind point is 0.0.0.0:9090)\n -p prod mode (app bind point is /tmp/comex.sock)" 1>&2; exit 1; }
unset COMEX_BIND_POINT
while getopts dph run_mode; do
case $run_mode in
d)
# debug mode: run on TCP socket 0.0.0.0:9090
export COMEX_BIND_POINT=0.0.0.0:9090
echo "binding gunicorn to tcp socket: $COMEX_BIND_POINT"
;;
p)
# production mode: run on fs socket
export COMEX_BIND_POINT='unix:/tmp/comex.sock'
echo "binding gunicorn to fs socket: $COMEX_BIND_POINT"
# POSS in-memory socket ?
# export COMEX_BIND_POINT='unix:/run/shm/comex.sock'
;;
*)
usage
esac
done
# production mode is the default
if [ -z "$COMEX_BIND_POINT" ]
then
echo "(no mode was specified: using production mode)"
export COMEX_BIND_POINT='unix:/tmp/comex.sock'
echo "binding gunicorn to fs socket: $COMEX_BIND_POINT"
fi
# if we're inside a docker (we're used as entrypoint)...
if grep --quiet docker /proc/1/cgroup
then
# ... then we're also in charge of the inner nginx
# (to package the php with the services below)
export REAL_DOCKER_HOST=$(hostname -i)
echo "starting nginx on $REAL_DOCKER_HOST"
export COMEX_DOCKER_HOST_IP=$(hostname -i)
echo "starting nginx on docker (available at http://$COMEX_DOCKER_HOST_IP)"
service nginx start
echo "starting php 7 with clear_env = no"
/etc/init.d/php7.0-fpm start
# NB if we started it with the "service" command
# all our env vars would be intercepted by it
# even though we set "clear_env=no" in www.conf
# NB if we started php-fpm with the "service" command
# then all our env vars would be intercepted by it
# even though we set "clear_env=no" in www.conf !
fi
# anyway we always need a simple web server to run the services
export COMEX_NWORKERS=$(grep -oP '(?<=COMEX_NWORKERS=).*' config/parametres_comex.ini)
echo "binding gunicorn to unix:/tmp/comex.sock"
gunicorn -b unix:/tmp/comex.sock services.main:app --workers $COMEX_NWORKERS --worker-class gevent
# export COMEX_HOST=$(grep -oP '(?<=COMEX_HOST=).*' config/parametres_comex.ini)
# export COMEX_PORT=$(grep -oP '(?<=COMEX_PORT=).*' config/parametres_comex.ini)
# echo "binding gunicorn to $COMEX_HOST:$COMEX_PORT"
# gunicorn -b $COMEX_HOST:$COMEX_PORT services.main:app --workers $COMEX_NWORKERS
gunicorn -b $COMEX_BIND_POINT services.main:app --workers $COMEX_NWORKERS --worker-class gevent
......@@ -8,7 +8,7 @@ comex app contains:
- the services views are in `services/main.py`
- the main templates are `base_layout.html` and `rootindex.html`
- main and `services/user.py` handle DB add/modify/remove scholars
- `services/db_to_tina_api` contains a custom python extraction function for tinawebJS
- `services/dbdatapi.py` contains a facet agregation API and custom python extraction function to create bipartite graphs for tinawebJS display
- a copy of tinawebJS in `static/tinawebJS` to explore the data in graph view
- the twjs is in a legacy version, downloadable [via this subtree](https://github.com/moma/tinawebJS/tree/comex_wip)
......@@ -19,9 +19,9 @@ comex app contains:
In development, it is more natural to run the app *without* the docker wrapper.
This way one can see the effects of changes without the bother of committing them, pulling them in the image and rebuilding the image.
Another difference is that without the docker wrapper, the app will be available on COMEX_HOST:9090 instead of 8080.
Another difference is that without the docker wrapper, the app will be available on 0.0.0.0:9090 instead of 8080.
#### Minimal config
#### Minimal run commands
```
# get the code
......@@ -33,24 +33,37 @@ cd $INSTALL_DIR
sudo pip3 install -r setup/requirements.txt
```
Then to run the comex2 server just do:
Then to run the comex2 server for development just do:
```
bash comex-run.sh
bash comex-run.sh -d
```
Check the parameters in `config/parametres_comex.ini`
Finally, simply configure the serving of your php|www documentroot in nginx (cf [detailed doc](https://github.com/moma/comex2/blob/master/doc/nginx_conf.md) for real-life conf).
At this point you're running a python gunicorn webserver pointing to the files in `/services`. You can connect to `0.0.0.0:9090` and checkout the app, but you won't have the php, DB access and authentication elements working yet.
-------
#### Full dev config
1. external mysql database
2. external doors (or simulated by docker)
3. gunicorn webserver (linked to 1 & 2 via `$SQL_HOST` and `$DOORS_HOST`)
1. php serving
2. mysql database
3. doors authentication server
4. gunicorn webserver (linked to 1 & 2 via `$SQL_HOST` and `$DOORS_HOST`)
##### 1) Set up your php
Configure the serving of our php documents in your nginx with something like this:
```
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
# here adapt documentroot to your real path to comex
fastcgi_param SCRIPT_FILENAME /home/romain/comex2$fastcgi_script_name;
# -------------------
# documentroot
}
```
##### 1) Set up your mysql database
##### 2) Set up your mysql database
###### If you have your own local mysql
```
......@@ -77,7 +90,7 @@ docker inspect comex_db | jq -r '.[0].NetworkSettings.IPAddress'
nano config/parametres_comex.ini
```
##### 2) Set up a doors connection
##### 3) Set up a doors connection
Again, the environment variable `DOORS_HOST` must simply be set to the doors server's hostname or IP, and `DOORS_PORT` to the doors server's exposed port.
###### If you have a doors server
......@@ -88,16 +101,19 @@ nano config/parametres_comex.ini
###### If you have no doors server
For tests you can use a self-deployed doors container, available on [this repository](https://github.com/ISCPIF/doors-docker)
For tests you can use a self-deployed doors container, available from ISCPIF on [this repository](https://github.com/ISCPIF/doors-docker)
##### 3) Run the regomex app with gunicorn
##### 4) Run the regomex app with gunicorn
```
bash comex-run.sh
bash comex-run.sh -d
```
The form server is then accessible locally on `0.0.0.0:9090/services/user/register`
The user DB service is then accessible locally on `0.0.0.0:9090/services/user`
The API server is then accessible locally on `0.0.0.0:9090/services/api`
(for instance `services/api/aggs?field=keywords&like=biol`)
**Remark:** the prefix `/services` and the user route `/user` can both be changed in the config file
**Remark:** the prefix `/services` and the routes `/user` and `/api` can both be changed in the config file
-------
......@@ -44,16 +44,12 @@ RUN git clone https://github.com/moma/comex2.git
# main CMD to start the app
WORKDIR /comex2
# flask dev server
# CMD python3 server_comex_registration.py
# start nginx inner wrapper and gunicorn production server
CMD bash comex-run.sh
CMD bash comex-run.sh -p
# ports -----------------------------------------------------------------------
# nginx server (redirecting to php AND services)
EXPOSE 80
# https test
EXPOSE 443
# https is actually handled outside by proxy layer
......@@ -11,8 +11,8 @@
- ../../data/shared_mysql_data:/var/lib/mysql
comex_test:
container_name: comex_test
image: comex2_services:testing
container_name: comex_services
image: comex2_services:latest
build: ./comex2_services
# logs will show all that's printed to STDOUT with tty:true
tty: true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment