Skip to content

Commit

Permalink
Update presidio containers to use gunicorn (#1497)
Browse files Browse the repository at this point in the history
  • Loading branch information
RKapadia01 authored Dec 14, 2024
1 parent ebf0ca5 commit a081c22
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 12 deletions.
27 changes: 27 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
2009-2015 (c) Paul J. Davis <[email protected]>

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.
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
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:create_app()'
7 changes: 5 additions & 2 deletions presidio-analyzer/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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"]
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:create_app()'
7 changes: 5 additions & 2 deletions presidio-anonymizer/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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:create_app()'
7 changes: 5 additions & 2 deletions presidio-image-redactor/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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

0 comments on commit a081c22

Please sign in to comment.