From ef86bc08851a76728a859782d5206138ef14960d Mon Sep 17 00:00:00 2001 From: David Vogt Date: Fri, 21 Jun 2019 10:54:50 +0200 Subject: [PATCH] Experimental PyPy version of Caluma This uses a separate Dockerfile, so users will still have the choice Also we need to use a different psycopg2 implementation, as the cPython version doesn't work with pypy --- caluma/settings.py | 8 ++++++++ pypy/Dockerfile | 35 +++++++++++++++++++++++++++++++++++ pypy/requirements-pypy.txt | 2 ++ 3 files changed, 45 insertions(+) create mode 100644 pypy/Dockerfile create mode 100644 pypy/requirements-pypy.txt diff --git a/caluma/settings.py b/caluma/settings.py index 2b94a577d..51604cfa2 100644 --- a/caluma/settings.py +++ b/caluma/settings.py @@ -1,9 +1,17 @@ import os import re +import sys import environ from django.conf import global_settings +if hasattr(sys, "pypy_version_info"): # pragma: no cover + # in pypy, override psycopg2 with cffi version + from psycopg2cffi import compat + + compat.register() + + env = environ.Env() django_root = environ.Path(__file__) - 2 diff --git a/pypy/Dockerfile b/pypy/Dockerfile new file mode 100644 index 000000000..daafefbec --- /dev/null +++ b/pypy/Dockerfile @@ -0,0 +1,35 @@ +FROM pypy:3.6 + +# pypy image still has /usr/bin/python being cpython, we don't want that +RUN rm /usr/bin/python && cp /usr/local/bin/pypy3 /usr/local/bin/python + +WORKDIR /app + +RUN wget -q https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh -P /usr/local/bin \ +&& chmod +x /usr/local/bin/wait-for-it.sh \ +&& mkdir -p /app \ +&& useradd -u 901 -r caluma --create-home \ +# all project specific folders need to be accessible by newly created user but also for unknown users (when UID is set manually). Such users are in group root. +&& chown -R caluma:root /home/caluma \ +&& chmod -R 770 /home/caluma + +# needs to be set for users with manually set UID +ENV HOME=/home/caluma + +ENV PYTHONUNBUFFERED=1 +ENV APP_HOME=/app +ENV DJANGO_SETTINGS_MODULE caluma.settings +ENV UWSGI_INI /app/uwsgi.ini + +ARG REQUIREMENTS=requirements-pypy.txt +COPY requirements.txt requirements-dev.txt pypy/requirements-pypy.txt $APP_HOME/ +RUN pip install --no-cache-dir --upgrade -r $REQUIREMENTS --disable-pip-version-check + + +USER caluma + +COPY . $APP_HOME + +EXPOSE 8000 + +CMD /bin/sh -c "wait-for-it.sh $DATABASE_HOST:${DATABASE_PORT:-5432} -- ./manage.py migrate && uwsgi" diff --git a/pypy/requirements-pypy.txt b/pypy/requirements-pypy.txt new file mode 100644 index 000000000..abb1e938e --- /dev/null +++ b/pypy/requirements-pypy.txt @@ -0,0 +1,2 @@ +-f requirements.txt +psycopg2cffi==2.8.1