diff --git a/.env.dev b/.env.dev new file mode 100644 index 00000000..76bb53e0 --- /dev/null +++ b/.env.dev @@ -0,0 +1,46 @@ +# This is an example of a .env file. +# This file contains all environment variables needed to run the service +# Duplicate this file, fill it with your configuration and rename it to '.env' + +# Set the environment of the service +ENVIRONMENT=development # development|production + +# Set the backend and frontend url + port +API_URL=https://localhost # host used to access the backend +API_PORT=5000 # port used to access the backend (ie. docker-compose external port) +CLIENT_URL=http://localhost:4200 # url used to access the frontend +GEOSERVER_URL=https://geo.wxyz # base url to access Geoserver (not REST) + + +# Flask configuration +FLASK_SECRET_KEY=MyFlaskSecretKey +FLASK_SALT=MyFlaskSalt +FLASK_SERVER_NAME=0.0.0.0:5556 + +# Celery configuration +CELERY_BROKER_URL=amqp://admin:mypass@rabbit:5672/ +CELERY_RESULT_BACKEND=redis://redis:6379 +# CELERYD_SOFT_TIME_LIMIT=10 # does not work +USER_UPLOAD_FOLDER=/var/hotmaps/users/ # directory where user uploads are stored on the 'api' container + # must match users path in docker-compose.yml volumes + +# Database configuration +DB_USER=root +DB_PASSWORD=password +DB_HOST=postgres +DB_PORT=5432 +DB_DATABASE=toolboxdb + +# Geoserver configuration +GEOSERVER_API_URL=https://geo.wxyz/geoserver/rest/ # full REST url to access geoserver (display layers on the map) +GEOSERVER_USER=admin +GEOSERVER_PASSWORD=password + +# SMTP Mail configuration (used to send emails to the users (register, recover, feedback...)) +MAIL_USERNAME=support@example.com +MAIL_PASSWORD=password +MAIL_SERVER=mail.server.com +MAIL_PORT=587 + +# Testing configuration +PYTEST_BASE_URL=http://127.0.0.1:5000/api # url used to run the tests diff --git a/api/config/production.py b/api/config/production.py index 7341e4d4..c59d2e5b 100644 --- a/api/config/production.py +++ b/api/config/production.py @@ -30,7 +30,8 @@ ) SQLALCHEMY_BINDS = { - 'cm_db': 'sqlite:///' + db_path + 'cm_db': os.environ.get('DATABASE_URL') or \ + 'sqlite:///' + db_path } SECRET_KEY = FLASK_SECRET_KEY diff --git a/api/dockerfiles/api/Dockerfile b/api/dockerfiles/api/Dockerfile index 0f7f2752..621464b2 100644 --- a/api/dockerfiles/api/Dockerfile +++ b/api/dockerfiles/api/Dockerfile @@ -6,6 +6,12 @@ ENV C_FORCE_ROOT true LABEL maintainers="lesly Houndole , Daniel Hunacek " +RUN apt-get clean && apt-get update && apt-get install -y locales +RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \ + locale-gen +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US:en +ENV LC_ALL en_US.UTF-8 # setup volume RUN mkdir -p /data @@ -33,4 +39,4 @@ RUN mkdir -p /var/log/supervisor COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf # Start processes -CMD ["/usr/bin/supervisord"] \ No newline at end of file +CMD ["/usr/bin/supervisord"] diff --git a/api/producer_cm_alive.py b/api/producer_cm_alive.py index ffaaeeec..dab54d03 100644 --- a/api/producer_cm_alive.py +++ b/api/producer_cm_alive.py @@ -13,7 +13,6 @@ '-35s %(lineno) -5d: %(message)s') LOGGER = logging.getLogger(__name__) - class HeartBeatCalculationModuleProducer(object): def __init__(self): parameters = pika.URLParameters(constants.CELERY_BROKER_URL) @@ -48,30 +47,28 @@ def call(self, queue_name): break return self.response - - - - - -while True : - listofCM = getCMList() - start = time.time() - if len(listofCM)>0: - for value in enumerate(listofCM): - time.sleep(constants.TIMEOUT_ALIVE_CM) - end = time. time() - print(end - start) - - - heart_cm = HeartBeatCalculationModuleProducer() - cm_id = value[1]['cm_id'] - print(" [HTAPI] Requesting cm_id = ",cm_id) - response = heart_cm.call(constants.RPC_CM_ALIVE + str(cm_id)) - if response is not None: - print("[HTAPI] is connected to the Calculation module with id: %s ", str(cm_id)) - LOGGER.info("[HTAPI] is connected to the Calculation module with id: %s ", str(cm_id)) - else: - LOGGER.info("[HTAPI] is going to delete: %s ",str(cm_id)) - delete_cm(str(cm_id)) +if __name__ == "__main__": + while True: + listofCM = getCMList() + start = time.time() + if listofCM: + for value in enumerate(listofCM): + time.sleep(constants.TIMEOUT_ALIVE_CM) + end = time. time() + print(end - start) + + + heart_cm = HeartBeatCalculationModuleProducer() + cm_id = value[1]['cm_id'] + print(" [HTAPI] Requesting cm_id = ", cm_id) + response = heart_cm.call(constants.RPC_CM_ALIVE + str(cm_id)) + if response is not None: + print("[HTAPI] is connected to the Calculation module with id: %s ", str(cm_id)) + LOGGER.info("[HTAPI] is connected to the Calculation module with id: %s ", str(cm_id)) + else: + LOGGER.info("[HTAPI] is going to delete: %s ",str(cm_id)) + delete_cm(str(cm_id)) + #sleep a bit between two alive checks + time.sleep(30) diff --git a/api/supervisord.conf b/api/supervisord.conf index 05cfb6b9..8572c272 100644 --- a/api/supervisord.conf +++ b/api/supervisord.conf @@ -1,17 +1,25 @@ [supervisord] nodaemon=true +#the three section below allow us to access supervisorctl +[unix_http_server] +file=/var/run/supervisord.sock +[rpcinterface:supervisor] +supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface + +[supervisorctl] +serverurl=unix:///var/run/supervisord.sock [program:mainwebservice] -command = gunicorn run:application --config gunicorn-config.py --timeout 9000 -directory = /api +command=gunicorn run:application --config gunicorn-config.py --timeout 9000 +directory=/api autostart=true autorestart=true startretries=30000 stderr_logfile=/var/log/mainwebservice.err.log stdout_logfile=/var/log/mainwebservice.out.log -user = root +user=root [program:producer_cm_alive] diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index 1a4ca4b8..71f76781 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -6,28 +6,47 @@ services: environment: - RABBITMQ_DEFAULT_USER=admin - RABBITMQ_DEFAULT_PASS=mypass - ports: - - "5672:5672" networks: - cm-net + healthcheck: + test: [ "CMD", "nc", "-z", "localhost", "5672" ] + interval: 10s + timeout: 10s + retries: 5 + db: + image: postgres + environment: + - POSTGRES_DB=toolboxdb + - POSTGRES_USER=root + - POSTGRES_PASSWORD=password + networks: + - cm-net + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 10s + timeout: 5s + retries: 5 api: build: context: ./api dockerfile: dockerfiles/api/Dockerfile restart: always ports: - - "5000:5000" + - "127.0.0.1:8080:80" links: - rabbit - redis depends_on: - redis + - db + - rabbit networks: - cm-net volumes: - - /var/tmp:/var/tmp - - /var/hotmaps/repositories:/var/hotmaps/repositories - + - /var/tmp:/var/tmp + - /var/hotmaps/repositories:/var/hotmaps/repositories + env_file: + - ./.env.dev redis: image: redis