Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update presidio containers to use gunicorn #1497

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion presidio-analyzer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
omri374 marked this conversation as resolved.
Show resolved Hide resolved
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}
Expand All @@ -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:app
5 changes: 3 additions & 2 deletions presidio-analyzer/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ def supported_entities() -> Tuple[str, int]:
def http_exception(e):
return jsonify(error=e.description), e.code

server = Server()
omri374 marked this conversation as resolved.
Show resolved Hide resolved
app = server.app

if __name__ == "__main__":
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)
3 changes: 2 additions & 1 deletion presidio-analyzer/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the gunicorn license into the NOTICE file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the NOTICE file, thanks

transformers = [
"transformers",
"huggingface_hub",
Expand Down
6 changes: 5 additions & 1 deletion presidio-anonymizer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}/
Expand All @@ -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
CMD poetry run gunicorn -w $WORKERS -b 0.0.0.0:$PORT app:app
5 changes: 3 additions & 2 deletions presidio-anonymizer/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ def server_error(e):
self.logger.error(f"A fatal error occurred during execution: {e}")
return jsonify(error="Internal server error"), 500

server = Server()
app = server.app

if __name__ == "__main__":
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)
3 changes: 2 additions & 1 deletion presidio-anonymizer/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "*"
Expand Down
5 changes: 4 additions & 1 deletion presidio-image-redactor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
CMD poetry run gunicorn -w $WORKERS -b 0.0.0.0:$PORT app:app
5 changes: 3 additions & 2 deletions presidio-image-redactor/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ def server_error(e):
self.logger.error(f"A fatal error occurred during execution: {e}")
return jsonify(error="Internal server error"), 500

server = Server()
app = server.app

if __name__ == "__main__":
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)
3 changes: 2 additions & 1 deletion presidio-image-redactor/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "*"
Expand Down
Loading