From 5c5712009727274abe155cad1b020baa44d2ac28 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 30 Aug 2022 16:10:02 -0400 Subject: [PATCH] change Dockerfile to use gunicorn, requiring some changes to the app. --- Dockerfile | 15 +++++++++------ pastey/common.py | 7 +++++-- pastey/functions.py | 5 ++++- pastey/routes.py | 5 ++++- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 62ff7d9..12bc827 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,11 @@ FROM tensorflow/tensorflow:2.5.0 -WORKDIR /app -COPY requirements.txt /app -RUN mkdir -p /app/data && pip install -r /app/requirements.txt +ENV PASTEY_WORKERS=2 +ENV PASTEY_THREADS=4 +ENV PASTEY_LISTEN_PORT=5000 +RUN pip install gunicorn +COPY requirements.txt /app/ +RUN pip install -r /app/requirements.txt COPY . /app/ -EXPOSE 5000 -ENV PASTEY_DATA_DIRECTORY=/app/data -ENTRYPOINT ["python3", "app.py"] +WORKDIR /app +ENTRYPOINT ["sh", "-c", "gunicorn -w $PASTEY_WORKERS -t $PASTEY_THREADS -b :$PASTEY_LISTEN_PORT app:app"] +EXPOSE $PASTEY_LISTEN_PORT diff --git a/pastey/common.py b/pastey/common.py index f0abe5f..ea295ce 100644 --- a/pastey/common.py +++ b/pastey/common.py @@ -1,5 +1,8 @@ from . import config -from __main__ import guess +if __name__ == '__main__': + from __main__ import guess +else: + from app import guess import ipaddress from os import path from pathlib import Path @@ -104,4 +107,4 @@ def build_url(request, path="/"): else: protocol = request.url.split('//')[0] if not config.force_https_links else "https:" - return protocol + "//" + domain + path \ No newline at end of file + return protocol + "//" + domain + path diff --git a/pastey/functions.py b/pastey/functions.py index 0564494..3a0742f 100644 --- a/pastey/functions.py +++ b/pastey/functions.py @@ -1,4 +1,7 @@ -from __main__ import guess, app +if __name__ == '__main__': + from __main__ import guess, app +else: + from app import guess, app from . import config, common from os import path, remove diff --git a/pastey/routes.py b/pastey/routes.py index 84a4c28..30ef84f 100644 --- a/pastey/routes.py +++ b/pastey/routes.py @@ -1,4 +1,7 @@ -from __main__ import app, limiter, loaded_config +if __name__ == '__main__': + from __main__ import app, limiter, loaded_config +else: + from app import app, limiter, loaded_config from . import config, common, functions from flask import Flask, render_template, request, redirect, abort, make_response