Commit a686fe4b authored by Romain Loth's avatar Romain Loth

troubleshooting config via docker-compose volume (new logic for debug...

troubleshooting config via docker-compose volume (new logic for debug messages, run.sh reads ini file, but shell env vars get priority over config vars)
parent 6f4898ab
...@@ -2,18 +2,8 @@ ...@@ -2,18 +2,8 @@
# #
# simple web server running services/comex_main_backend:app # simple web server running services/comex_main_backend:app
if [ -z "$HOST" ] export COMEX_HOST=$(grep COMEX_HOST config/parametres_comex.ini | perl -pe 's/^[^=]+=\s*//')
then export HOST="0.0.0.0"
fi
echo "using \$COMEX_HOST $COMEX_HOST"
if [ "$DEBUG_FLAG" != true ] gunicorn -b $COMEX_HOST:9090 services.comex_main_backend:app
then
gunicorn -b $HOST:9090 services.comex_main_backend:app
else
gunicorn -b $HOST:9090 \
--log-level debug \
services.comex_main_backend:app
# --access-logfile test_gu_access.log
# --error-logfile test_gu_error.log
fi
...@@ -31,6 +31,9 @@ from os import path ...@@ -31,6 +31,9 @@ from os import path
from traceback import format_tb from traceback import format_tb
from json import dumps from json import dumps
print("HELLO starting comex_main_backend.py====================")
if __package__ == 'services': if __package__ == 'services':
# when we're run via import # when we're run via import
from services.user import comex_user from services.user import comex_user
...@@ -48,6 +51,10 @@ else: ...@@ -48,6 +51,10 @@ else:
config = read_config() config = read_config()
# DEBUG
print("config is=====>", config)
# ============= verbose msg ============= # ============= verbose msg =============
if config['DEBUG_FLAG']: if config['DEBUG_FLAG']:
print("DEBUG: conf\n "+"\n ".join(["%s=%s"%(k,v) for k,v in config.items()])) print("DEBUG: conf\n "+"\n ".join(["%s=%s"%(k,v) for k,v in config.items()]))
...@@ -550,4 +557,4 @@ def read_record(incoming_data): ...@@ -550,4 +557,4 @@ def read_record(incoming_data):
########### MAIN ########### ########### MAIN ###########
if __name__ == "__main__": if __name__ == "__main__":
# our app should be bound to an ip (cf stackoverflow.com/a/30329547/2489184) # our app should be bound to an ip (cf stackoverflow.com/a/30329547/2489184)
app.run(host=config['COMEX_HOST'], port=config['COMEX_PORT']) app.run(host=config['COMEX_HOST'], port=int(config['COMEX_PORT']))
...@@ -32,8 +32,8 @@ def home_path(): ...@@ -32,8 +32,8 @@ def home_path():
def read_config(): def read_config():
""" """
reads all global config vars trying in order: reads all global config vars trying in order:
1) the config file $HOME/parametres_comex.ini 1) env variables of the same name
2) env variables of the same name 2) the config file $HOME/parametres_comex.ini
3) hard-coded default values 3) hard-coded default values
output is a simple dict output is a simple dict
...@@ -56,18 +56,28 @@ def read_config(): ...@@ -56,18 +56,28 @@ def read_config():
default = citem['def'] default = citem['def']
is_bool = (type(default) == bool) is_bool = (type(default) == bool)
if section in ini and varname in ini[section]: print("DEBUG: config for '%s'"%varname)
if is_bool:
out_dict[varname] = ini.getboolean(section, varname) if varname in environ:
else:
out_dict[varname] = ini.get(section, varname)
elif varname in environ:
if is_bool: if is_bool:
out_dict[varname] = (environ[varname] == 'true') out_dict[varname] = (environ[varname] == 'true')
else: else:
out_dict[varname] = environ[varname] out_dict[varname] = environ[varname]
print("DEBUG: ok from env for '%s'"%varname)
elif section in ini and varname in ini[section]:
if is_bool:
out_dict[varname] = ini.getboolean(section, varname)
else:
out_dict[varname] = ini.get(section, varname)
print("DEBUG: ok from file for '%s'"%varname)
else: else:
out_dict[varname] = default out_dict[varname] = default
print("DEBUG: ok from default for '%s'"%varname)
# DEBUG FORCED
out_dict['DEBUG_FLAG'] = True
# also add our project home since we have it and we'll need it # also add our project home since we have it and we'll need it
out_dict['HOME'] = our_home out_dict['HOME'] = our_home
......
...@@ -9,34 +9,33 @@ ...@@ -9,34 +9,33 @@
- ../../data/shared_mysql_data:/var/lib/mysql - ../../data/shared_mysql_data:/var/lib/mysql
# in the future: external service (=> just remove doors_test & change DOORS_HOST and DOORS_PORT) # in the future: external service (=> just remove doors_test & change DOORS_HOST and DOORS_PORT)
doors_test: # doors_test:
build: ./minidoors # build: ./minidoors
image: minidoors:latest # image: minidoors:latest
ports: # ports:
- "32789:8989" # - "32789:8989"
volumes: # volumes:
- ../../../shared_minidoors_data:/root/.doors # - ../../../shared_minidoors_data:/root/.doors
comex_test: comex_test:
ports: ports:
- "32790:9090" - "32790:9090"
build: ./comex2_services build: ./comex2_services
image: comex2_services:latest image: comex2_services:testing
depends_on: depends_on:
- comex_db_test - comex_db_test
- doors_test # - doors_test
links: links:
- comex_db_test:comex_db_backend - comex_db_test:comex_db_backend
- doors_test:doors_backend # - doors_test:doors_backend
# links the outside config parametres_comex.ini to the inside # links the outside config parametres_comex.ini to the inside
# /!\ this erases the contained config with the outside one /!\ # /!\ this erases the contained config with the outside one /!\
volumes: volumes:
- ../../config/:/comex2/config - ../../config:/comex2/config
# moved from env vars to new config vars via volume config
# # moved from env vars to new config vars via volume config
# environment: # 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 # - DEBUG_FLAG=true
# - SQL_HOST=comex_db_backend # script will read/write sql to this host # - SQL_HOST=comex_db_backend # script will read/write sql to this host
# - DOORS_HOST=134.158.75.71 # - DOORS_HOST=134.158.75.71
# - DOORS_PORT=80 # forwarded port we're accessing via ajax in tests # - DOORS_PORT=80 # forwarded port we're accessing via ajax in tests
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