From 233c14ec2d9d72d8801a59231c7ca7f5ccb0f745 Mon Sep 17 00:00:00 2001 From: danijoo Date: Sun, 27 Nov 2022 10:59:54 +0100 Subject: [PATCH] run app with gunicorn --- Dockerfile | 14 ++++++++++---- gunicorn.conf.py | 8 ++++++++ requirements.txt | 3 ++- 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 gunicorn.conf.py diff --git a/Dockerfile b/Dockerfile index 8594b1c..e332aac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,17 @@ -# build pdfact +# STEP 1: build pdfact FROM ubuntu:20.04 + ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update -y && apt-get upgrade -y && apt-get install -y maven git WORKDIR / +# TODO freeze revision? RUN git clone https://github.com/ad-freiburg/pdfact.git WORKDIR pdfact RUN mvn install -DskipTests +# STEP 2: run service FROM alpine:latest WORKDIR / @@ -26,12 +29,15 @@ RUN apk add --no-cache python3 \ && python3 -m ensurepip \ && pip3 install --upgrade pip setuptools +# set environment variables +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 # install flask app WORKDIR /app COPY ./requirements.txt . RUN pip install -r requirements.txt -COPY app.py . -ENTRYPOINT ["python3"] -CMD ["app.py"] +COPY app.py gunicorn.conf.py ./ + +ENTRYPOINT ["gunicorn", "--conf", "gunicorn.conf.py", "--bind", "0.0.0.0:80", "app:app"] diff --git a/gunicorn.conf.py b/gunicorn.conf.py new file mode 100644 index 0000000..795268c --- /dev/null +++ b/gunicorn.conf.py @@ -0,0 +1,8 @@ +loglevel = "info" +errorlog = "-" # stderr +accesslog = "-" # stdout +worker_tmp_dir = "/dev/shm" +graceful_timeout = 120 +timeout = 120 +keepalive = 5 +threads = 4 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 3c78d8f..bd753fb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -Flask==2.2.2 \ No newline at end of file +Flask==2.2.2 +gunicorn==20.1.0 \ No newline at end of file