diff --git a/NOTICE b/NOTICE index 56dc1d2c6..098e4819e 100644 --- a/NOTICE +++ b/NOTICE @@ -1552,3 +1552,30 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + +******* +gunicorn + +2009-2024 (c) BenoƮt Chesneau +2009-2015 (c) Paul J. Davis + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/presidio-analyzer/Dockerfile b/presidio-analyzer/Dockerfile index 6d2f59539..86ded5997 100644 --- a/presidio-analyzer/Dockerfile +++ b/presidio-analyzer/Dockerfile @@ -10,6 +10,9 @@ ENV ANALYZER_CONF_FILE=${ANALYZER_CONF_FILE} ENV RECOGNIZER_REGISTRY_CONF_FILE=${RECOGNIZER_REGISTRY_CONF_FILE} ENV NLP_CONF_FILE=${NLP_CONF_FILE} +ENV PORT=3000 +ENV WORKERS=1 + COPY ${ANALYZER_CONF_FILE} /usr/bin/${NAME}/${ANALYZER_CONF_FILE} COPY ${RECOGNIZER_REGISTRY_CONF_FILE} /usr/bin/${NAME}/${RECOGNIZER_REGISTRY_CONF_FILE} COPY ${NLP_CONF_FILE} /usr/bin/${NAME}/${NLP_CONF_FILE} @@ -31,4 +34,4 @@ RUN poetry run python install_nlp_models.py --conf_file ${NLP_CONF_FILE} COPY . /usr/bin/${NAME}/ EXPOSE ${PORT} -CMD poetry run python app.py --host 0.0.0.0 +CMD poetry run gunicorn -w $WORKERS -b 0.0.0.0:$PORT 'app:create_app()' diff --git a/presidio-analyzer/app.py b/presidio-analyzer/app.py index 900429eae..a85ce16de 100644 --- a/presidio-analyzer/app.py +++ b/presidio-analyzer/app.py @@ -135,8 +135,11 @@ def supported_entities() -> Tuple[str, int]: def http_exception(e): return jsonify(error=e.description), e.code +def create_app(): # noqa + server = Server() + return server.app if __name__ == "__main__": + app = create_app() port = int(os.environ.get("PORT", DEFAULT_PORT)) - server = Server() - server.app.run(host="0.0.0.0", port=port) + app.run(host="0.0.0.0", port=port) diff --git a/presidio-analyzer/pyproject.toml b/presidio-analyzer/pyproject.toml index f6e266ddb..fa477e9fa 100644 --- a/presidio-analyzer/pyproject.toml +++ b/presidio-analyzer/pyproject.toml @@ -36,9 +36,10 @@ azure-ai-textanalytics = { version = "*", optional = true } azure-core = { version = "*", optional = true } transformers = { version = "*", optional = true } huggingface_hub = { version = "*", optional = true } +gunicorn = {version = "*", optional = true} [tool.poetry.extras] -server = ["flask"] +server = ["flask", "gunicorn"] transformers = [ "transformers", "huggingface_hub", diff --git a/presidio-anonymizer/Dockerfile b/presidio-anonymizer/Dockerfile index ade207023..b7d1870ee 100644 --- a/presidio-anonymizer/Dockerfile +++ b/presidio-anonymizer/Dockerfile @@ -2,6 +2,10 @@ FROM python:3.9-slim ARG NAME ENV PIP_NO_CACHE_DIR=1 + +ENV PORT=3000 +ENV WORKERS=1 + WORKDIR /usr/bin/${NAME} COPY ./pyproject.toml /usr/bin/${NAME}/ @@ -11,4 +15,4 @@ RUN pip install poetry && poetry install --no-root --only=main -E server COPY . /usr/bin/${NAME}/ EXPOSE ${PORT} -CMD poetry run python app.py \ No newline at end of file +CMD poetry run gunicorn -w $WORKERS -b 0.0.0.0:$PORT 'app:create_app()' \ No newline at end of file diff --git a/presidio-anonymizer/app.py b/presidio-anonymizer/app.py index 12ce67c02..52f75f41a 100644 --- a/presidio-anonymizer/app.py +++ b/presidio-anonymizer/app.py @@ -112,8 +112,11 @@ def server_error(e): self.logger.error(f"A fatal error occurred during execution: {e}") return jsonify(error="Internal server error"), 500 +def create_app(): # noqa + server = Server() + return server.app if __name__ == "__main__": + app = create_app() port = int(os.environ.get("PORT", DEFAULT_PORT)) - server = Server() - server.app.run(host="0.0.0.0", port=port) + app.run(host="0.0.0.0", port=port) diff --git a/presidio-anonymizer/pyproject.toml b/presidio-anonymizer/pyproject.toml index e840ac7f5..b570a86fd 100644 --- a/presidio-anonymizer/pyproject.toml +++ b/presidio-anonymizer/pyproject.toml @@ -25,9 +25,10 @@ python = ">=3.9,<4.0" pycryptodome = ">=3.10.1" azure-core = { version = "*", optional = true } flask = { version = ">=1.1", optional = true } +gunicorn = {version = "*", optional = true} [tool.poetry.extras] -server = ["flask"] +server = ["flask", "gunicorn"] [tool.poetry.group.dev.dependencies] pip = "*" diff --git a/presidio-image-redactor/Dockerfile b/presidio-image-redactor/Dockerfile index 5c0244a11..0f11dc905 100644 --- a/presidio-image-redactor/Dockerfile +++ b/presidio-image-redactor/Dockerfile @@ -10,6 +10,9 @@ ENV ANALYZER_CONF_FILE=${ANALYZER_CONF_FILE} ENV RECOGNIZER_REGISTRY_CONF_FILE=${RECOGNIZER_REGISTRY_CONF_FILE} ENV NLP_CONF_FILE=${NLP_CONF_FILE} +ENV PORT=3000 +ENV WORKERS=1 + COPY ${ANALYZER_CONF_FILE} /usr/bin/${NAME}/${ANALYZER_CONF_FILE} COPY ${RECOGNIZER_REGISTRY_CONF_FILE} /usr/bin/${NAME}/${RECOGNIZER_REGISTRY_CONF_FILE} COPY ${NLP_CONF_FILE} /usr/bin/${NAME}/${NLP_CONF_FILE} @@ -35,4 +38,4 @@ RUN pip install poetry && poetry install --no-root --only=main -E server COPY . /usr/bin/${NAME}/ EXPOSE ${PORT} -CMD poetry run python app.py \ No newline at end of file +CMD poetry run gunicorn -w $WORKERS -b 0.0.0.0:$PORT 'app:create_app()' \ No newline at end of file diff --git a/presidio-image-redactor/app.py b/presidio-image-redactor/app.py index 780742eaf..fdcc31e95 100644 --- a/presidio-image-redactor/app.py +++ b/presidio-image-redactor/app.py @@ -80,8 +80,11 @@ def server_error(e): self.logger.error(f"A fatal error occurred during execution: {e}") return jsonify(error="Internal server error"), 500 +def create_app(): # noqa + server = Server() + return server.app if __name__ == "__main__": + app = create_app() port = int(os.environ.get("PORT", DEFAULT_PORT)) - server = Server() - server.app.run(host="0.0.0.0", port=port) + app.run(host="0.0.0.0", port=port) diff --git a/presidio-image-redactor/pyproject.toml b/presidio-image-redactor/pyproject.toml index ac39df6b6..f02f4b312 100644 --- a/presidio-image-redactor/pyproject.toml +++ b/presidio-image-redactor/pyproject.toml @@ -32,9 +32,10 @@ azure-ai-formrecognizer = ">=3.3.0,<4.0.0" opencv-python = ">=4.0.0,<5.0.0" python-gdcm = ">=3.0.24.1" flask = { version = ">=1.1", optional = true } +gunicorn = {version = "*", optional = true} [tool.poetry.extras] -server = ["flask"] +server = ["flask", "gunicorn"] [tool.poetry.group.dev.dependencies] pip = "*"