Commit d2a42c8f authored by Romain Loth's avatar Romain Loth

better config for minidoors

parent 2205e6c0
......@@ -41,7 +41,7 @@ Minimal config:
```
sudo apt install python3
sudo pip3 install -r setup/requirements.txt
source setup/regcomex.ini
source setup/regcomex_config.ini
```
Then to run the regcomex app in the simplest way just do:
......@@ -52,13 +52,19 @@ The form server is then accessible locally on `127.0.0.1:5000/regcomex`
-------
Or, to run the app with a real webserver (gunicorn) and a new mysql database:
Or, to run the app with a real-world config:
- gunicorn webserver
- external mysql database
- external doors (simulated by docker)
```
# install more prerequisites
sudo apt install docker jq
cd $INSTALL_DIR
source setup/regcomex_config.ini
# external mysql setup
mkdir ../shared_mysql_data
# run the database docker
......@@ -69,6 +75,8 @@ docker run --detach --name comex_db \
# get its IP into the env
export SQL_HOST=$(docker inspect comex_db | jq -r '.[0].NetworkSettings.IPAddress')
# here also set up the doors connection
# run the app
gunicorn -b 127.0.0.1:9090 server_comex_registration:app
```
......@@ -99,9 +107,22 @@ server {
```
-------
### Setting up the doors connection
### Setting up a doors connection
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.
For tests you can use a `minidoors` container
```
# build the docker image (once)
cd setup/dockers
docker build -t minidoors:latest minidoors/
# run the container (each time)
docker run -it -p 32789:8989 --name doors_test minidoors
The environment variable `DOORS_HOST` must simply be set to the doors server's hostname or IP.
# pass the info to the env before running regcomex
export DOORS_HOST=localhost
export DOORS_PORT=8989
```
-------
......
......@@ -29,6 +29,12 @@ MY_HOST = environ.get('HOST', '0.0.0.0')
MY_DEBUG_FLAG = environ.get('DEBUG_FLAG') == 'true'
MY_SQL_HOST = environ.get('SQL_HOST', '172.17.0.2')
MY_DOORS_HOST = environ.get('DOORS_HOST', '0.0.0.0')
MY_DOORS_PORT = environ.get('DOORS_PORT', '8989')
if MY_DEBUG_FLAG:
print("DEBUG: DOORS environ.get... =>", environ.get('DOORS_HOST'), environ.get('DOORS_PORT'))
print("DEBUG: DOORS final connect params =>", MY_DOORS_HOST+':'+MY_DOORS_PORT)
print("DEBUG: MYSQL final connect params =>", MY_SQL_HOST +':3306')
# TODO add doors port if != 8989
# ============= app creation =============
......@@ -36,7 +42,6 @@ app = Flask(__name__)
app.config['DEBUG'] = MY_DEBUG_FLAG
########### PARAMS ###########
# all columns as they are declared in form & DB as tuple:
......@@ -69,11 +74,19 @@ COLS = [ ("doors_uid", True, 36),
# prefix must match what nginx conf expects
ROUTE_PREFIX = "/regcomex"
# ROUTE_PREFIX = "/"
#
# @app.route("/regcomex", methods=['GET','POST'])
# def one_big_form2():
# one_big_form()
@app.route(ROUTE_PREFIX+"", methods=['GET','POST'])
@app.route("/regcomex/", methods=['GET','POST'])
def one_big_form():
if request.method == 'GET':
return render_template("base_form.html", doors_host=MY_DOORS_HOST)
return render_template(
"base_form.html",
doors_connect=MY_DOORS_HOST+':'+MY_DOORS_PORT
)
elif request.method == 'POST':
# ex: request.form = ImmutableMultiDict([('initials', 'R.L.'), ('email', 'romain.loth@iscpif.fr'), ('last_name', 'Loth'), ('country', 'France'), ('first_name', 'Romain'), ('my-captchaHash', '-773776109'), ('my-captcha', 'TSZVIN')])
# print("GOT ANSWERS <<========<<", request.form)
......
......@@ -14,13 +14,11 @@
doors_test:
image: minidoors
ports:
- "8989:32789"
- "32789:8989"
# POSSIBLE volume for h2 DB itself
flask_ispcif_regcomex:
image: flask_iscpif_regcomex
ports:
- "9090:32790"
depends_on:
- mysql_regcomex
- doors_test
......@@ -28,9 +26,12 @@
- mysql_regcomex:comex_db_backend
- doors_test:doors_backend
environment:
- HOST=0.0.0.0 # script will bind server to this address
- HOST=0.0.0.0 # script will bind server to this address
- DEBUG_FLAG=false
- SQL_HOST=comex_db_backend # script will read/write sql to this host
- DOORS_HOST=doors_backend # script will log/register users to this host
- SQL_HOST=comex_db_backend # script will read/write sql to this host
#- DOORS_HOST=doors_backend # script will log/register users to this host
#- DOORS_PORT=8989 # original port on doors_backend
- DOORS_HOST=localhost
- DOORS_PORT=32789 # forwarded port we're accessing in tests
#TODO add php legacy communityexplorer site
......@@ -5,6 +5,7 @@
# Pull base image
FROM java:8
# cf. doors/application/build.sbt for correct version
ENV SCALA_VERSION 2.11.8
ENV SBT_VERSION 0.13.12
ENV DOORS_COMMIT ef7c5e0
......@@ -32,7 +33,11 @@ RUN git clone https://github.com/ISCPIF/doors.git
WORKDIR /root/doors
RUN git checkout $DOORS_COMMIT
WORKDIR /root/doors/application
RUN sbt "project lab"
# build and compile it once so it downloads dependencies
RUN sbt "project lab" compile test package
# sset docker run command to run doors servers
CMD sbt "project lab" run
# ports
......
# REGCOMEX INI MINIMAL CONFIG
# ===========================
HOST=localhost
SQL_HOST=localhost
DOORS_HOST=hello_todo
DEBUG_FLAG=false
# REGCOMEX SH MINIMAL CONFIG
# ==========================
export HOST=localhost
export SQL_HOST=localhost
export DOORS_HOST=localhost
export DOORS_PORT=32789
export DEBUG_FLAG=false
......@@ -47,7 +47,8 @@ var regTimestamp = document.getElementById('last_modified_date')
var uidInput = document.getElementById('doors_uid')
var email = document.getElementById('email')
var doorsHost = document.getElementById('doors_host').value
// str of the form: doors_hostname:doors_port
var doorsConnectParam = document.getElementById('doors_connect').value
// captchaHash should be appended by itself if normal submit,
// but we may need to do it ourselves (TODO test)
......@@ -213,7 +214,7 @@ function callDoors(data, callback, apiAction) {
$.ajax({
contentType: "application/json",
dataType: 'json',
url: "http://"+doorsHost+":8989/api/" + apiAction,
url: "http://"+doorsConnectParam+"/api/" + apiAction,
data: JSON.stringify({
"login": mailStr,
"password": passStr,
......
......@@ -350,8 +350,9 @@
</ul>
</nav>
<!-- hidden input for doors hostname -->
<input id="doors_host" name="doors_host" type="text" hidden>{{doors_host|safe}}</input>
<!-- hidden input for doors "hostname:port" -->
<input id="doors_connect" name="doors_connect" type="text" hidden value="{{doors_connect|safe}}">
</input>
<!-- hidden input for modification date -->
<input id="last_modified_date" name="last_modified_date" type="text" hidden>
......
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