1+ # #########
2+ # PYTHON #
3+ # #########
4+ FROM python:3.12-alpine AS python
5+
6+
17# ##########
28# BUILDER #
39# ##########
4- FROM python:3.12-alpine AS builder
10+ FROM python AS builder
511
612# set work directory
713WORKDIR /usr/src/app
@@ -20,22 +26,10 @@ COPY backend/requirements.txt .
2026RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/python/wheels -r requirements.txt
2127
2228
23- # ################
24- # PYPY BUILDER #
25- # ################
26- FROM builder AS pypy-builder
27-
28- RUN echo "@testing https://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && \
29- apk --update add pypy3@testing
30-
31- RUN pypy3 -m ensurepip && pypy3 -m pip install --upgrade pip
32-
33- RUN pypy3 -m pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/pypy/wheels $(grep -ivE "#|cryptography|cffi" requirements.txt)
34-
3529# ########
3630# BASE #
3731# ########
38- FROM python:3.12-alpine AS base
32+ FROM python AS base
3933
4034# create the app user
4135RUN addgroup -S app && adduser -S app -G app
@@ -74,32 +68,37 @@ ENTRYPOINT ["/bin/sh", "entrypoint.prod.sh"]
7468RUN echo -e 'gunicorn backend.wsgi:application --bind 0.0.0.0:8000\n ' > entrypoint.prod.sh
7569
7670
77- # ########
78- # PYPY #
79- # ########
80- FROM base AS pypy
71+ # #########
72+ # CYTHON #
73+ # #########
74+ FROM builder AS cython
8175
82- # Switch to user root in order to install pypy
83- USER root
76+ RUN pip install --upgrade cython setuptools
8477
85- # install dependencies
86- RUN echo "@testing https://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && \
87- apk --update add pypy3@testing && \
88- ln -s $(which pypy3) $(dirname $(which pypy3))/pypy && \
89- pypy -m ensurepip && pypy -m pip install --no-cache-dir --upgrade pip
9078
91- COPY --from=pypy-builder /usr/src/app/pypy/wheels /pypy/wheels
79+ # #################
80+ # CYTHON-BUILDER #
81+ # #################
9282
93- RUN pypy -m pip install --no-cache-dir /pypy/wheels/* --no-deps
94- RUN pypy -m pip install --no-cache-dir psycopg
83+ FROM cython AS cython-builder
84+
85+ COPY backend/ common/ /usr/src/app/
86+ WORKDIR /usr/src/app/
87+ RUN cythonize -i 'spellbook/variants/*.py'
88+
89+
90+ # ##############
91+ # BASE-CYTHON #
92+ # ##############
93+ FROM base AS base-cython
94+
95+ COPY --from=cython-builder --parents /usr/src/app/./**/*.so $APP_HOME
9596
96- # Switch back to the app user
97- USER app
9897
9998# ########
10099# DEMO #
101100# ########
102- FROM pypy AS demo
101+ FROM base-cython AS demo
103102
104103RUN echo -e 'set -e\n \
105104python manage.py collectstatic --no-input --clear\n \
@@ -113,7 +112,7 @@ gunicorn backend.wsgi:application --bind 0.0.0.0:8000\n' > entrypoint.prod.sh
113112# #############
114113# PRODUCTION #
115114# #############
116- FROM pypy AS production
115+ FROM base-cython AS production
117116
118117ADD backend/nginx/production.conf /etc/nginx/nginx.conf
119118
0 commit comments