diff --git a/Dockerfile b/Dockerfile index fc59134..8c650b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,12 +7,20 @@ WORKDIR /code # Install LaTeX requirements RUN apt update && \ - apt install -y gettext texlive-latex-extra texlive-fonts-extra texlive-lang-french && \ + apt install -y gettext texlive-latex-extra texlive-fonts-extra texlive-lang-french nginx && \ rm -rf /var/lib/apt/lists/* COPY . /code/ +# Configure nginx +RUN ln -s nginx_tfjm.conf /etc/nginx/sites-available/tfjm.conf +RUN rm /var/log/nginx/*.log +RUN ln -s /dev/stdout /var/log/nginx/access.log +RUN ln -s /dev/stderr /var/log/nginx/error.log +RUN rm /etc/nginx/sites-enabled/default +RUN ln -sf /code/nginx_tfjm.conf /etc/nginx/sites-enabled/tfjm.conf + RUN pip install -r requirements.txt ENTRYPOINT ["/code/entrypoint.sh"] -EXPOSE 8000 +EXPOSE 80 diff --git a/entrypoint.sh b/entrypoint.sh index 8fef126..d8d491a 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -4,4 +4,10 @@ python manage.py compilemessages python manage.py makemigrations python manage.py migrate -python manage.py runserver 0.0.0.0:8000 --insecure +service nginx start + +if [ "$TFJM_STAGE" = "prod" ]; then + gunicorn -b 0.0.0.0:8000 --workers=2 --threads=4 --worker-class=gthread tfjm.wsgi --access-logfile '-'; +else + ./manage.py runserver 0.0.0.0:8000; +fi diff --git a/nginx_tfjm.conf b/nginx_tfjm.conf new file mode 100644 index 0000000..be143ce --- /dev/null +++ b/nginx_tfjm.conf @@ -0,0 +1,19 @@ +upstream tfjm { + server 127.0.0.1:8000; +} + +server { + listen 80; + server_name tfjm; + + location / { + proxy_pass http://tfjm; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_redirect off; + } + + location /static { + alias /code/static/; + } +} diff --git a/requirements.txt b/requirements.txt index 532ec72..0daf9ef 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,3 +9,4 @@ django-tables2 djangorestframework django-rest-polymorphic psycopg2-binary +gunicorn \ No newline at end of file