Skip to content

Commit 3af77fd

Browse files
Use system uWSGI packages instead of pip installation
Replace pip-installed uWSGI with OS-provided system packages to eliminate compilation during Docker builds. Changes: - Remove uWSGI from requirements.txt - Debian: Install uwsgi + uwsgi-plugin-python3 from apt - Alpine: Install uwsgi + uwsgi-python3 from apk - Remove build dependencies (gcc, build-essential, python3-dev, libffi-dev) - Remove CPUCOUNT=1 workaround (no longer needed) Benefits: - Eliminates uWSGI compilation (major build time improvement) - Removes need for build toolchain in Docker images - Smaller build stage (no gcc, build-essential, etc.) - Faster Docker image builds Version notes: - Debian Trixie: uwsgi 2.0.28 (vs pip 2.0.31) - Alpine 3.22: uwsgi 2.0.30 (vs pip 2.0.31) System packages are maintained by official distribution teams and receive security backports within their release cycle.
1 parent b8b6a29 commit 3af77fd

4 files changed

Lines changed: 12 additions & 21 deletions

File tree

Dockerfile.django-alpine

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,19 @@ WORKDIR /app
1111
RUN \
1212
apk update && \
1313
apk add --no-cache \
14-
gcc \
15-
build-base \
1614
bind-tools \
1715
postgresql16-client \
1816
xmlsec \
1917
git \
2018
util-linux \
2119
curl-dev \
2220
openssl \
23-
libffi-dev \
24-
python3-dev \
2521
&& \
2622
rm -rf /var/cache/apk/* && \
2723
true
2824
COPY requirements.txt ./
29-
# CPUCOUNT=1 is needed, otherwise the wheel for uwsgi won't always be build succesfully
30-
# https://github.com/unbit/uwsgi/issues/1318#issuecomment-542238096
3125
RUN export PYCURL_SSL_LIBRARY=openssl && \
32-
CPUCOUNT=1 pip3 wheel --wheel-dir=/tmp/wheels -r ./requirements.txt
26+
pip3 wheel --wheel-dir=/tmp/wheels -r ./requirements.txt
3327

3428
FROM base AS release
3529
WORKDIR /app
@@ -50,6 +44,9 @@ RUN \
5044
postgresql16-client \
5145
curl-dev \
5246
openssl \
47+
# uwsgi from system packages (avoids compilation)
48+
uwsgi \
49+
uwsgi-python3 \
5350
# needed for integration-tests
5451
bash \
5552
&& \

Dockerfile.django-debian

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ WORKDIR /app
1111
RUN \
1212
apt-get -y update && \
1313
apt-get -y install --no-install-recommends \
14-
gcc \
15-
build-essential \
1614
dnsutils \
1715
postgresql-client \
1816
xmlsec1 \
@@ -25,10 +23,8 @@ RUN \
2523
rm -rf /var/lib/apt/lists && \
2624
true
2725
COPY requirements.txt ./
28-
# CPUCOUNT=1 is needed, otherwise the wheel for uwsgi won't always be build succesfully
29-
# https://github.com/unbit/uwsgi/issues/1318#issuecomment-542238096
3026
RUN export PYCURL_SSL_LIBRARY=openssl && \
31-
CPUCOUNT=1 pip3 wheel --wheel-dir=/tmp/wheels -r ./requirements.txt
27+
pip3 wheel --wheel-dir=/tmp/wheels -r ./requirements.txt
3228

3329
FROM base AS release
3430
WORKDIR /app
@@ -53,6 +49,9 @@ RUN \
5349
postgresql-client \
5450
# libcurl4-openssl-dev is required for installing pycurl python package
5551
libcurl4-openssl-dev \
52+
# uwsgi from system packages (avoids compilation)
53+
uwsgi \
54+
uwsgi-plugin-python3 \
5655
&& \
5756
apt-get clean && \
5857
rm -rf /var/lib/apt/lists && \

Dockerfile.nginx-alpine

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,20 @@ WORKDIR /app
1111
RUN \
1212
apk update && \
1313
apk add --no-cache \
14-
gcc \
15-
build-base \
1614
bind-tools \
1715
postgresql16-client \
1816
xmlsec \
1917
git \
2018
util-linux \
2119
curl-dev \
2220
openssl \
23-
libffi-dev \
24-
python3-dev \
2521
&& \
2622
rm -rf /var/cache/apk/* && \
2723
true
2824
COPY requirements.txt requirements-dev.txt ./
29-
# CPUCOUNT=1 is needed, otherwise the wheel for uwsgi won't always be build succesfully
30-
# https://github.com/unbit/uwsgi/issues/1318#issuecomment-542238096
31-
RUN CPUCOUNT=1 pip3 wheel --wheel-dir=/tmp/wheels -r ./requirements.txt
25+
RUN pip3 wheel --wheel-dir=/tmp/wheels -r ./requirements.txt
3226
# needed for static files debug toolbar
33-
RUN CPUCOUNT=1 pip3 wheel --wheel-dir=/tmp/wheels -r ./requirements-dev.txt
27+
RUN pip3 wheel --wheel-dir=/tmp/wheels -r ./requirements-dev.txt
3428

3529

3630
FROM build AS collectstatic

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ redis==7.1.0
3636
requests==2.32.5
3737
sqlalchemy==2.0.45 # Required by Celery broker transport
3838
urllib3==2.6.2
39-
uWSGI==2.0.31
39+
# uWSGI is installed via system packages (uwsgi + uwsgi-plugin-python3 on Debian,
40+
# uwsgi + uwsgi-python3 on Alpine) to avoid compilation during Docker builds and to have official binaries
4041
vobject==0.9.9
4142
whitenoise==5.2.0
4243
titlecase==2.4.1

0 commit comments

Comments
 (0)