Skip to content

Commit

Permalink
Polishing deployment of Docker image
Browse files Browse the repository at this point in the history
* Ahead compilation of Cython modules (so that "pyximport" finds modules already compiled)
* Use of Named Lock to avoid database initialization problems with multiple gunicorn workers starting at the same
  • Loading branch information
rnebot committed Dec 9, 2020
1 parent 4784447 commit 4b1ee94
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ FROM python:3.7.3-slim-stretch
# docker build -t magicnexush2020/magic-nis-backend .
#
# 1.bis) REFRESH image into Docker Hub:
# ("docker login" first)
# docker push magicnexush2020/magic-nis-backend:<TAGNAME>
#
# Usage example:
Expand Down Expand Up @@ -113,4 +114,6 @@ CMD ["/usr/local/bin/gunicorn", "--workers=3", "--log-level=debug", "--timeout=2
#CMD ["supervisord", "-c", "/etc/supervisord.conf"]

COPY nexinfosys /app/nexinfosys
RUN cythonize -a -i /app/nexinfosys/restful_service/helper_accel.pyx && \
cythonize -a -i /app/nexinfosys/command_generators/parser_spreadsheet_utils_accel.pyx

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ The pip version is obviously for execution as package, and does not include the

`pip install nexinfosys`

* Use class class *NIS*, with methods similar to *NISClient* class in [nexinfosys-client](https://github.com/MAGIC-nexus/nis-python-client) package.
* Use class **NIS**, with methods similar to **NISClient** class in [nexinfosys-client](https://github.com/MAGIC-nexus/nis-python-client) package.

#### Docker image

Expand Down
9 changes: 8 additions & 1 deletion nexinfosys/restful_service/service_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# from flask import (jsonify, abort, redirect, url_for,
#
# )
from NamedAtomicLock import NamedAtomicLock
from flask import (Response, request, session as flask_session, send_from_directory, redirect
)
from flask.helpers import get_root_path
Expand Down Expand Up @@ -124,7 +125,13 @@ def construct_session_persistence_backend():
# >>>> THE INITIALIZATION CODE <<<<
#

initialize_databases()
lock = NamedAtomicLock("nis-backend-lock")
lock.acquire()
try:
initialize_databases()
finally:
lock.release()

nexinfosys.data_source_manager = register_external_datasources()

d = construct_session_persistence_backend()
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ jsonpickle==1.2
python_magic>=0.4.13 # To be removed, it is used only by the Magic Box file type detection
dotted>=0.1.8 # <- Dotted notation: !!Fantastic!!
sympy>=1.1.1
NamedAtomicLock==1.1.3
#sympy==1.3
#cachier==1.2.2
#tablib <- dictmapper (convert nested dict's to CSV)
Expand Down

0 comments on commit 4b1ee94

Please sign in to comment.