Skip to content

Use system uWSGI packages instead of pip installation#13999

Closed
valentijnscholten wants to merge 8 commits intoDefectDojo:devfrom
valentijnscholten:uwsgi-system-packages
Closed

Use system uWSGI packages instead of pip installation#13999
valentijnscholten wants to merge 8 commits intoDefectDojo:devfrom
valentijnscholten:uwsgi-system-packages

Conversation

@valentijnscholten
Copy link
Copy Markdown
Member

@valentijnscholten valentijnscholten commented Dec 29, 2025

Builds on #13993 and #13993 so merge those first.

Description

Replace pip-installed uWSGI with OS-provided system packages to eliminate compilation during Docker builds. This removes the need for build toolchains (gcc, build-essential, python3-dev) in Docker images.

Why Use System Packages?

1. Eliminates Compilation

uWSGI requires compilation from source when installed via pip, which:

  • Requires build toolchain (gcc, build-essential, python3-dev, libffi-dev)
  • Takes significant time during Docker builds
  • Increases image size with build dependencies

2. System Packages Are Well-Maintained

Platform Package Version Maintainer
Debian Trixie uwsgi + uwsgi-plugin-python3 2.0.28 Debian maintainers
Alpine 3.22 uwsgi + uwsgi-python3 2.0.30 Alpine maintainers

These are maintained by official distribution teams and receive security backports.

3. Version Considerations

  • Debian: 2.0.28 (3 patch versions behind pip 2.0.31)
  • Alpine: 2.0.30 (1 patch version behind pip 2.0.31)

The downside is that we no longer get Renovate / Dependabot PRs for updates of uwsgi.
The patch-level differences are typically minor bug fixes. Security patches are backported to system packages within their release cycle. I can't remember any time that these small patches broke Defect Dojo. In general it might be better to rely on official binaries instead of compiling our own possibly with suboptimal settings or small changes depending on where/how they are built. But I'm open for discussion/happy to close if we don't get consensus.

Switch from psycopg[c] to psycopg[binary] to use pre-compiled wheels
instead of compiling the C extension from source. This significantly
speeds up Docker image builds.

Changes:
- requirements.txt: psycopg[c] -> psycopg[binary]
- Remove libpq-dev from all Dockerfiles (build and release stages)

The psycopg[binary] package bundles its own libpq, so system libpq-dev
is no longer needed for either compilation or runtime.

Both options provide the same performance (fast C implementation).

Reference: https://www.psycopg.org/psycopg3/docs/basic/install.html
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.
Remove pycurl from requirements.txt and use OS-provided packages instead:
- Debian: python3-pycurl (7.45.6)
- Alpine: py3-curl (7.45.6)

Benefits:
- Eliminates pycurl compilation during Docker builds
- Removes need for curl-dev/libcurl4-openssl-dev build dependencies
- Faster Docker image builds
- Consistent pycurl version across Debian and Alpine images

pycurl is only needed for Celery SQS broker support. It is not directly
imported by DefectDojo code - it's a transitive dependency that Celery
uses when configured with an SQS broker (DD_CELERY_BROKER_SCHEME=sqs).

The system packages provide the same functionality without requiring
compilation toolchains in the Docker build stage.
@github-actions github-actions Bot removed New Migration Adding a new migration file. Take care when merging. apiv2 docs unittests ui parser labels Dec 29, 2025
@valentijnscholten
Copy link
Copy Markdown
Member Author

Turns out it doesn't work on Alpine because alpine comes with Python 3.12 by default, so the uwsgi plugin apks is compiled against Python 3.12 while we use Python 3.13. In Debian it works (for now) as Trixie uses Python 3.13 out of the box.
I fixed it a little bit dirty in this PR to have the Alpine builds fall back to pip for uwsgi installation.
This feels a bit hacky. And once we want to go to Python 3.14 we will have the same problem on Debian.

Two options:

  1. Forget about this PR and keep using pip to install uwsgi and accept it takes a long time to build
  2. Forget about having our own python version and just use the default that comes with Alpine or Debian.

I think option 2 is not really what we want, so this leaves option 1.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 5, 2026

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant