Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion api/config/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion api/dockerfiles/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ ENV C_FORCE_ROOT true

LABEL maintainers="lesly Houndole <lesly.houndole@crem.ch>, Daniel Hunacek <daniel.hunacek@hevs.ch>"

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
Expand Down Expand Up @@ -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"]
CMD ["/usr/bin/supervisord"]
49 changes: 23 additions & 26 deletions api/producer_cm_alive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)


14 changes: 11 additions & 3 deletions api/supervisord.conf
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
31 changes: 25 additions & 6 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down