diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000000000000000000000000000000..b570aefca75ae14b8f10b2c47f072612c01950b4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.git +.venv +.envrc diff --git a/Dockerfile b/Dockerfile index 7d964303945e366ded0ae198a0833ed2936e59a6..3f80ae5d5e19ffe814862bf855627dd6bce786b5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,19 @@ -# Use an official Python runtime as a parent image -FROM python:3.7 -LABEL maintainer="hello@wagtail.io" +FROM python:3.8-slim -# Set environment varibles -ENV PYTHONUNBUFFERED 1 -ENV DJANGO_ENV dev +RUN mkdir /app +WORKDIR /app -COPY ./requirements.txt /code/requirements.txt -RUN pip install --upgrade pip -# Install any needed packages specified in requirements.txt -RUN pip install -r /code/requirements.txt -RUN pip install gunicorn +COPY requirements requirements/ +RUN pip install -r requirements/base.txt -r requirements/production.txt -# Copy the current directory contents into the container at /code/ -COPY . /code/ -# Set the working directory to /code/ -WORKDIR /code/ +COPY . . -RUN python manage.py migrate +RUN useradd app +RUN chown -R app /app +USER app -RUN useradd wagtail -RUN chown -R wagtail /code -USER wagtail +ENV DJANGO_SETTINGS_MODULE "majak.settings.production" EXPOSE 8000 -CMD exec gunicorn majak.wsgi:application --bind 0.0.0.0:8000 --workers 3 + +CMD ["bash", "run.sh"] diff --git a/README.md b/README.md index e5ea509c89d6d26f629be9be0b88a24e2251dab3..6e1547a70db23dacef06412599a7e00358abcbdf 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,9 @@ Maják je CMS pro PirátskĂ© weby. PostavenĂ˝ je na [Wagtail](https://wagtail.io ## VĂ˝voj -Pro vĂ˝voj je definován pomocnĂ˝ `Makefile` pro ÄŤastĂ© akce. +Pro vĂ˝voj je definován pomocnĂ˝ `Makefile` pro ÄŤastĂ© akce. Pro nápovÄ›du zavolej: + + $ make help ### LokálnĂ instalace a spuštÄ›nĂ @@ -69,11 +71,11 @@ PĹ™i zmÄ›nÄ› modelĹŻ vygeneruj migrace pomocĂ: #### SpuštÄ›nĂ development serveru -Django development server na portu `8003` se spustĂ pĹ™Ăkazem: +Django development server na portu `8006` se spustĂ pĹ™Ăkazem: $ make run -PotĂ© mĹŻĹľete otevĹ™Ăt web na adrese [http://localhost:8003](http://localhost:8003) +PotĂ© mĹŻĹľete otevĹ™Ăt web na adrese [http://localhost:8006](http://localhost:8006) #### Django shell @@ -114,5 +116,6 @@ K upgrade se pouĹľĂvajĂ [pip-tools](https://github.com/jazzband/pip-tools) (`p $ cd requirements/ $ pip-compile -U base.in + $ pip-compile -U production.in -TĂm se vygenerujĂ `base.txt`. +TĂm se vygenerujĂ `base.txt` a `production.txt`. diff --git a/gunicorn.conf.py b/gunicorn.conf.py new file mode 100644 index 0000000000000000000000000000000000000000..5fbe95a61da82df057158648c60feb1718b03a64 --- /dev/null +++ b/gunicorn.conf.py @@ -0,0 +1,5 @@ +bind = "0.0.0.0:8000" +accesslog = "-" +workers = 4 +max_requests = 1000 +max_requests_jitter = 10 diff --git a/majak/wsgi.py b/majak/wsgi.py index 08f897e37d33d9b3976d575b232899f209758f15..53341b6750cdd5eeca1e7ae0c5926d9855030c19 100644 --- a/majak/wsgi.py +++ b/majak/wsgi.py @@ -11,6 +11,6 @@ import os from django.core.wsgi import get_wsgi_application -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "majak.settings.dev") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "majak.settings.production") application = get_wsgi_application() diff --git a/requirements/production.in b/requirements/production.in new file mode 100644 index 0000000000000000000000000000000000000000..8f22dccf99affb5ab9b1c65023ec083269269bca --- /dev/null +++ b/requirements/production.in @@ -0,0 +1 @@ +gunicorn diff --git a/requirements/production.txt b/requirements/production.txt new file mode 100644 index 0000000000000000000000000000000000000000..dc632d0b8a65dded86d873d7fd1ffb78248af5c6 --- /dev/null +++ b/requirements/production.txt @@ -0,0 +1,10 @@ +# +# This file is autogenerated by pip-compile +# To update, run: +# +# pip-compile production.in +# +gunicorn==20.0.4 # via -r production.in + +# The following packages are considered to be unsafe in a requirements file: +# setuptools diff --git a/run.sh b/run.sh new file mode 100644 index 0000000000000000000000000000000000000000..b37b5eaf3e9b9f58b27a591263daa17177bc8c85 --- /dev/null +++ b/run.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# exit on error +set -e + +# migrate database +python manage.py migrate + +# start webserver +exec gunicorn -c gunicorn.conf.py majak.wsgi