1- FROM ubuntu:22 .04
1+ FROM ubuntu:24 .04
22
33ENV DEBIAN_FRONTEND noninteractive
44ENV LANG en_US.UTF-8
55ENV LANGUAGE en_US:en
66ENV LC_ALL en_US.UTF-8
77ENV PYTHONUNBUFFERED 1
88
9+ # uv environment variables
10+ # Copy (don't hardlink) files into /.venv. Avoid issues with Docker's FS
11+ # https://docs.astral.sh/uv/reference/environment/
12+ ENV UV_LINK_MODE=copy
13+ ENV UV_PROJECT_ENVIRONMENT=/.venv
14+
15+
916RUN apt-get -y update
1017RUN apt-get -y install \
1118 curl \
@@ -17,45 +24,56 @@ RUN apt-get -y install \
1724 libxslt1-dev \
1825 locales \
1926 build-essential \
20- python3-pip \
21- python3-dev \
2227 postgresql-client \
2328 libmysqlclient-dev \
2429 libfreetype6 \
2530 libjpeg-dev \
26- sqlite \
27- netcat \
31+ sqlite3 \
32+ netcat-openbsd \
2833 telnet \
2934 lsb-release
3035
31- # Requirements are installed here to ensure they will be cached.
32- # https://docs.docker.com/build/cache/#use-the-dedicated-run-cache
33- COPY ./requirements /requirements
34- RUN pip install --upgrade pip
35- RUN --mount=type=cache,target=/root/.cache/pip pip install -r /requirements/development.txt
36- RUN --mount=type=cache,target=/root/.cache/pip pip install -r /requirements/production.txt
36+ # Install uv for fast package management
37+ # https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
38+ ADD https://astral.sh/uv/install.sh /uv-installer.sh
39+ RUN sh /uv-installer.sh && rm /uv-installer.sh
40+ ENV PATH="/root/.local/bin/:$PATH"
41+
42+ # Copy project files for dependency resolution
43+ # uv.lock ensures reproducible builds
44+ COPY pyproject.toml uv.lock ./
3745
38- # Comment this if you don't need the page/topic analyzer.
39- # The analyzer is used to target ads better based on page content.
40- # Its requirements are huge and include PyTorch and other ML tools.
41- # If not needed, make sure to set `ADSERVER_ANALYZER_BACKEND=` (empty string)
42- # in your environment file `./envs/local/django`.
43- RUN --mount=type=cache,target=/root/.cache/pip pip install -r /requirements/analyzer.txt
46+ # Install Python through uv
47+ # Get the version pinned by pyproject.toml
48+ RUN uv python install
49+
50+ # Install dependencies using uv sync
51+ # This creates a virtual environment at /.venv (not in /app)
52+ # This installs all dependencies from uv.lock, ensuring consistency
53+ # --frozen: Don't update the lockfile
54+ # --no-install-project: Don't install the project itself
55+ # If you do not want the analyzer dependencies (which are LARGE), you can use:
56+ # RUN --mount=type=cache,target=/root/.cache/uv \
57+ # uv sync --frozen --no-install-project --extra dev --extra production
58+ RUN --mount=type=cache,target=/root/.cache/uv \
59+ uv sync --frozen --no-install-project --all-extras
4460
4561COPY ./docker-compose/django/start /start
4662RUN chmod +x /start
4763
64+ # Launch a shell within the container with this script
65+ COPY ./docker-compose/django/shell /shell
66+ RUN chmod +x /shell
67+
4868COPY ./docker-compose/django/celery/worker/start /start-celeryworker
4969RUN chmod +x /start-celeryworker
5070
5171COPY ./docker-compose/django/celery/beat/start /start-celerybeat
5272RUN chmod +x /start-celerybeat
5373
54- # Ensure that ``python`` is in the PATH so that ``./manage.py`` works
55- RUN ln -s /usr/bin/python3 /usr/bin/python
56-
5774# Load model
58- RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('multi-qa-MiniLM-L6-cos-v1', cache_folder='/tmp/sentence_transformers')"
75+ # Not needed if you don't use the analyzer
76+ RUN uv run python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('multi-qa-MiniLM-L6-cos-v1', cache_folder='/tmp/sentence_transformers')"
5977
6078# Setup the locale
6179RUN locale-gen en_US.UTF-8
0 commit comments