-
Notifications
You must be signed in to change notification settings - Fork 69
Upgrade to Ubuntu 24.04 LTS and Python 3.12 with modern uv dependency management #1100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
c74494e
5ab9d70
c876f64
4ee1ae2
89057d2
6794d0f
b40c4c1
b8b02e2
aa8d6e5
1523e09
ee18df0
a7b0a3c
9485e81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,19 @@ | ||
| FROM ubuntu:22.04 | ||
| FROM ubuntu:24.04 | ||
|
|
||
| ENV DEBIAN_FRONTEND noninteractive | ||
| ENV LANG en_US.UTF-8 | ||
| ENV LANGUAGE en_US:en | ||
| ENV LC_ALL en_US.UTF-8 | ||
| ENV PYTHONUNBUFFERED 1 | ||
|
|
||
| # uv environment variables | ||
| # Copy (don't hardlink) files into /.venv. Avoid issues with Docker's FS | ||
| # https://docs.astral.sh/uv/reference/environment/ | ||
| ENV UV_LINK_MODE=copy | ||
| ENV UV_PYTHON_DOWNLOADS=never | ||
| ENV UV_PROJECT_ENVIRONMENT=/.venv | ||
|
|
||
|
|
||
| RUN apt-get -y update | ||
| RUN apt-get -y install \ | ||
| curl \ | ||
|
|
@@ -23,39 +31,48 @@ RUN apt-get -y install \ | |
| libmysqlclient-dev \ | ||
| libfreetype6 \ | ||
| libjpeg-dev \ | ||
| sqlite \ | ||
| netcat \ | ||
| sqlite3 \ | ||
| netcat-openbsd \ | ||
| telnet \ | ||
| lsb-release | ||
|
|
||
| # Requirements are installed here to ensure they will be cached. | ||
| # https://docs.docker.com/build/cache/#use-the-dedicated-run-cache | ||
| COPY ./requirements /requirements | ||
| RUN pip install --upgrade pip | ||
| RUN --mount=type=cache,target=/root/.cache/pip pip install -r /requirements/development.txt | ||
| RUN --mount=type=cache,target=/root/.cache/pip pip install -r /requirements/production.txt | ||
| # Install uv for fast package management | ||
| # https://docs.astral.sh/uv/guides/integration/docker/#installing-uv | ||
| ADD https://astral.sh/uv/install.sh /uv-installer.sh | ||
| RUN sh /uv-installer.sh && rm /uv-installer.sh | ||
| ENV PATH="/root/.local/bin/:$PATH" | ||
|
|
||
| # Copy project files for dependency resolution | ||
| # uv.lock ensures reproducible builds | ||
| COPY pyproject.toml uv.lock ./ | ||
|
|
||
| # Comment this if you don't need the page/topic analyzer. | ||
| # The analyzer is used to target ads better based on page content. | ||
| # Its requirements are huge and include PyTorch and other ML tools. | ||
| # If not needed, make sure to set `ADSERVER_ANALYZER_BACKEND=` (empty string) | ||
| # in your environment file `./envs/local/django`. | ||
| RUN --mount=type=cache,target=/root/.cache/pip pip install -r /requirements/analyzer.txt | ||
| # Install dependencies using uv sync | ||
| # This creates a virtual environment at /.venv (not in /app) | ||
| # This installs all dependencies from uv.lock, ensuring consistency | ||
| # --frozen: Don't update the lockfile | ||
| # --no-install-project: Don't install the project itself | ||
| # If you do not want the analyzer dependencies (which are LARGE), you can use: | ||
| # RUN --mount=type=cache,target=/root/.cache/uv \ | ||
| # uv sync --frozen --no-install-project --extra dev --extra production | ||
| RUN --mount=type=cache,target=/root/.cache/uv \ | ||
| uv sync --frozen --no-install-project --all-extras | ||
|
|
||
| COPY ./docker-compose/django/start /start | ||
| RUN chmod +x /start | ||
|
|
||
| # Launch a shell within the container with this script | ||
| COPY ./docker-compose/django/shell /shell | ||
| RUN chmod +x /shell | ||
|
|
||
| COPY ./docker-compose/django/celery/worker/start /start-celeryworker | ||
| RUN chmod +x /start-celeryworker | ||
|
|
||
| COPY ./docker-compose/django/celery/beat/start /start-celerybeat | ||
| RUN chmod +x /start-celerybeat | ||
|
|
||
| # Ensure that ``python`` is in the PATH so that ``./manage.py`` works | ||
| RUN ln -s /usr/bin/python3 /usr/bin/python | ||
|
|
||
| # Load model | ||
| RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('multi-qa-MiniLM-L6-cos-v1', cache_folder='/tmp/sentence_transformers')" | ||
| # Not needed if you don't use the analyzer | ||
| RUN uv run python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('multi-qa-MiniLM-L6-cos-v1', cache_folder='/tmp/sentence_transformers')" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably just remove this at this point? I don't think we really want to be running local models and require a download of this for docker?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's get rid of local models, etc. in a separate PR. I already feel like this PR has gotten heavy. I can prioritize this and it should be relatively straight-forward. |
||
|
|
||
| # Setup the locale | ||
| RUN locale-gen en_US.UTF-8 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -o errexit | ||
| set -o pipefail | ||
| set -o nounset | ||
|
|
||
|
|
||
| # Use the venv created by `uv sync` in the Dockerfile | ||
| source /.venv/bin/activate | ||
|
|
||
| # Start shell with the venv activated | ||
| /bin/bash |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,8 +43,8 @@ This section is more to document steps than to encourage you to develop outside | |
| Requirements | ||
| ~~~~~~~~~~~~ | ||
|
|
||
| - Python 3.10 | ||
| - Nodejs (tested with v14) | ||
| - Python 3.12 | ||
| - Nodejs (tested with v20) | ||
|
|
||
| Front-end assets | ||
| ~~~~~~~~~~~~~~~~ | ||
|
|
@@ -57,10 +57,18 @@ To build the assets:: | |
| Install Python dependencies | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| First, install uv if you haven't already: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| $ curl -LsSf https://astral.sh/uv/install.sh | sh | ||
|
|
||
| Then install dependencies: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| $ pip install -r requirements/development.txt | ||
| $ pre-commit install # Install a code style pre-commit hook | ||
| $ uv sync --all-extras # Install all dependencies including dev tools | ||
| $ uv run pre-commit install # Install a code style pre-commit hook | ||
|
|
||
| Run the server | ||
|
||
| ~~~~~~~~~~~~~~ | ||
|
|
@@ -69,19 +77,19 @@ Run migrations: | |
|
|
||
| .. code-block:: bash | ||
|
|
||
| $ python manage.py migrate | ||
| $ uv run ./manage.py migrate | ||
|
|
||
| Create a superuser: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| $ python manage.py createsuperuser | ||
| $ uv run ./manage.py createsuperuser | ||
|
|
||
| Run the server: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| $ python manage.py runserver | ||
| $ uv run ./manage.py runserver | ||
|
|
||
| Running the tests | ||
| ----------------- | ||
|
|
@@ -90,8 +98,8 @@ To run the unit tests: | |
|
|
||
| .. code-block:: bash | ||
|
|
||
| $ pip install -r requirements/testing.txt | ||
| $ make test | ||
| $ uv tool install tox --with tox-uv | ||
| $ tox | ||
|
|
||
| Run a specific test: | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we were also talking about installing Python via uv, instead of depending on the system? Seems worth doing during this larger refactor since we're already changing a bunch of stuff, but not too set on it it you don't want to add more here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do that. It's a pretty trivial change. Stick with 3.12 though or go to 3.14?