From 557ae9540603280c4b6534cb40a236242571a3dd Mon Sep 17 00:00:00 2001 From: Armin Friedl Date: Mon, 9 Nov 2020 05:37:17 +0100 Subject: [PATCH] Use https as default scheme, run behind gunicorn in container --- .snipenv.local | 1 + Dockerfile | 3 ++- snip/__init__.py | 1 + snip/config.py | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.snipenv.local b/.snipenv.local index a414b9e..3cc240e 100644 --- a/.snipenv.local +++ b/.snipenv.local @@ -7,3 +7,4 @@ SNIP_DATABASE_TRACK_MODIFICATIONS=False SNIP_FLASK_SECRET=secret SNIP_FLASK_ENVIRONMENT=development SNIP_FLASK_DEBUG=True +SNIP_FLASK_PREFERRED_URL_SCHEME=http diff --git a/Dockerfile b/Dockerfile index a395853..72d6733 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,10 +9,11 @@ COPY . /app WORKDIR /app RUN pipenv install +RUN pipenv install gunicorn ENV SNIP_DATABASE="sqlite" ENV SNIP_DATABASE_URI="sqlite:////data/snip.db" ENV SNIP_FLASK_HOST="0.0.0.0" EXPOSE 5000 -CMD ["pipenv", "run", "python", "-m", "snip"] +CMD ["pipenv", "run", "gunicorn", "-b0.0.0.0:5000", "snip:app"] diff --git a/snip/__init__.py b/snip/__init__.py index b681f5c..f56088c 100644 --- a/snip/__init__.py +++ b/snip/__init__.py @@ -24,6 +24,7 @@ app = Flask(__name__) app.config.update( SECRET_KEY = snip_config.SNIP_FLASK_SECRET.get_secret_value(), + PREFERRED_URL_SCHEME = snip_config.SNIP_FLASK_PREFERRED_URL_SCHEME, SQLALCHEMY_DATABASE_URI = snip_config.SNIP_DATABASE_URI, SQLALCHEMY_TRACK_MODIFICATIONS = snip_config.SNIP_DATABASE_TRACK_MODIFICATION) diff --git a/snip/config.py b/snip/config.py index 12d9324..ca87915 100644 --- a/snip/config.py +++ b/snip/config.py @@ -43,6 +43,7 @@ class SnipConfig(BaseModel): SNIP_FLASK_ENVIRONMENT: Literal['development', 'production'] = 'production' SNIP_FLASK_DEBUG: bool = False SNIP_FLASK_SKIP_DOTENV: int = 1 + SNIP_FLASK_PREFERRED_URL_SCHEME: Literal['http', 'https'] = 'https' # Non-standard flask settings SNIP_FLASK_HOST: str = "localhost" SNIP_FLASK_PORT: int = 5000