Skip to content

Support uv in addition to pip when extending the Docker image #37785

@yehoshuadimarsky

Description

@yehoshuadimarsky

Description

I am trying to use the new phenomenal tool uv to add python packages on top of the base Airflow image. I kept running into the issue of uv not supporting non-virtual-envs, but this is now supported with version 0.1.12

Here is my sample Dockerfile. I cannot get it to work with either of these new flags: --python or --system.

FROM apache/airflow:slim-2.7.3-python3.10

ENV PIP_DISABLE_PIP_VERSION_CHECK=1
ENV PIP_ROOT_USER_ACTION="ignore"

USER root

RUN apt-get update \
  && apt-get install -y --no-install-recommends \
        build-essential libmariadb-dev \
  && apt-get autoremove -yqq --purge \
  && apt-get clean \
  && rm -rf /var/lib/apt/lists/*

USER airflow

RUN pip install "uv==0.1.12"

COPY requirements.txt /
COPY constraints.txt /

# with --python
RUN uv pip install --no-cache -r /requirements.txt -c /constraints.txt --python $(which python)

# with --system
# RUN uv pip install --no-cache -r /requirements.txt -c /constraints.txt --system

In both cases, I get this error:

=> ERROR [6/6] RUN uv pip install --no-cache -r /requirements.txt -c /constraints.txt --python $(which python  18.5s
------                                                                                                                
 > [6/6] RUN uv pip install --no-cache -r /requirements.txt -c /constraints.txt --python $(which python):             
4.061 Resolved 239 packages in 3.48s                                                                                  
16.86 Downloaded 238 packages in 12.79s                                                                               
18.07 error: failed to remove file `/usr/local/lib/python3.10/site-packages/_distutils_hack/__init__.py`
18.07   Caused by: Permission denied (os error 13)
------
Dockerfile.airflow2:22
--------------------
  20 |     COPY constraints.txt /
  21 |     
  22 | >>> RUN uv pip install --no-cache -r /requirements.txt -c /constraints.txt --python $(which python)
  23 |     
  24 |     # RUN uv pip install --no-cache -r /requirements.txt -c /constraints.txt --system
--------------------
ERROR: failed to solve: process "/bin/bash -o pipefail -o errexit -o nounset -o nolog -c uv pip install --no-cache -r /requirements.txt -c /constraints.txt --python $(which python)" did not complete successfully: exit code: 2

I thought, ok, let me run it as USER root, but then I get an error about installing pip packages as root, from here: https://airflow.apache.org/docs/docker-stack/build.html#adding-new-pypi-packages-individually

Any suggestions on using uv with the Airflow Docker image?

Thanks

Use case/motivation

No response

Related issues

I see that Airflow has already adopted uv internally for its CI here and see (https://github.com/apache/airflow/issues?q=uv), so I think this should be doable for the external Docker image as well

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions