Skip to content

Commit c81af86

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 37b3e8e commit c81af86

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,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
libpq-dev \
2622
&& \
2723
rm -rf /var/cache/apk/* && \
2824
true
2925
COPY requirements.txt ./
30-
# CPUCOUNT=1 is needed, otherwise the wheel for uwsgi won't always be build succesfully
31-
# https://github.com/unbit/uwsgi/issues/1318#issuecomment-542238096
3226
RUN export PYCURL_SSL_LIBRARY=openssl && \
33-
CPUCOUNT=1 pip3 wheel --wheel-dir=/tmp/wheels -r ./requirements.txt
27+
pip3 wheel --wheel-dir=/tmp/wheels -r ./requirements.txt
3428

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

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
libpq-dev \
1816
postgresql-client \
@@ -26,10 +24,8 @@ RUN \
2624
rm -rf /var/lib/apt/lists && \
2725
true
2826
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
3127
RUN export PYCURL_SSL_LIBRARY=openssl && \
32-
CPUCOUNT=1 pip3 wheel --wheel-dir=/tmp/wheels -r ./requirements.txt
28+
pip3 wheel --wheel-dir=/tmp/wheels -r ./requirements.txt
3329

3430
FROM base AS release
3531
WORKDIR /app
@@ -55,6 +51,9 @@ RUN \
5551
postgresql-client \
5652
# libcurl4-openssl-dev is required for installing pycurl python package
5753
libcurl4-openssl-dev \
54+
# uwsgi from system packages (avoids compilation)
55+
uwsgi \
56+
uwsgi-plugin-python3 \
5857
&& \
5958
apt-get clean && \
6059
rm -rf /var/lib/apt/lists && \

Dockerfile.nginx-alpine

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,21 @@ 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
libpq-dev \
2622
&& \
2723
rm -rf /var/cache/apk/* && \
2824
true
2925
COPY requirements.txt requirements-dev.txt ./
30-
# CPUCOUNT=1 is needed, otherwise the wheel for uwsgi won't always be build succesfully
31-
# https://github.com/unbit/uwsgi/issues/1318#issuecomment-542238096
32-
RUN CPUCOUNT=1 pip3 wheel --wheel-dir=/tmp/wheels -r ./requirements.txt
26+
RUN pip3 wheel --wheel-dir=/tmp/wheels -r ./requirements.txt
3327
# needed for static files debug toolbar
34-
RUN CPUCOUNT=1 pip3 wheel --wheel-dir=/tmp/wheels -r ./requirements-dev.txt
28+
RUN pip3 wheel --wheel-dir=/tmp/wheels -r ./requirements-dev.txt
3529

3630

3731
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)