Commit bc168bb5 authored by Федор Батоногов's avatar Федор Батоногов
Browse files

Replace pip with uv for faster dependency installation in Linux images (#162)



Use uv as the package installer in Linux (full + slim) Dockerfiles and
entrypoint. The PYPI_URL/PYPI_INDEX_URL env vars are preserved for
backward compatibility and translated to UV_INDEX_URL/UV_INSECURE_HOST.

Co-Authored-By: default avatarClaude Opus 4.6 <noreply@anthropic.com>
parent cd6911f6
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -15,8 +15,11 @@ ENV PYTHONUNBUFFERED=1
# Copy the entrypoint script
COPY entrypoint-linux.sh /entrypoint.sh

# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/

# Install dependencies, PyInstaller, and set execute permissions for the entrypoint
RUN pip install --no-cache-dir pyinstaller==$PYINSTALLER_VERSION \
RUN uv pip install --system --no-cache pyinstaller==$PYINSTALLER_VERSION \
    && chmod +x /entrypoint.sh

# Set the working directory and mount the volume
+6 −3
Original line number Diff line number Diff line
@@ -9,14 +9,17 @@ LABEL maintainer="f.batonogov@yandex.ru"
# Define PyInstaller version as an argument
ARG PYINSTALLER_VERSION=6.17.0

# Configure Python Package Index URLs for pip
# Configure Python Package Index URLs
ENV PYPI_URL=https://pypi.python.org/
ENV PYPI_INDEX_URL=https://pypi.python.org/simple
ENV PYTHONUNBUFFERED=1

# Copy entrypoint script early to ensure its available before dependency installation
# Copy entrypoint script early to ensure it's available before dependency installation
COPY entrypoint-linux.sh /entrypoint.sh

# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/

# Install dependencies and PyInstaller in a single RUN command to reduce image layers
RUN apt update && \
    apt install --no-install-recommends -y \
@@ -24,7 +27,7 @@ RUN apt update && \
        gcc \
        zlib1g-dev && \
    rm -rf /var/lib/apt/lists/* && \
    pip install --no-cache-dir pyinstaller==$PYINSTALLER_VERSION && \
    uv pip install --system --no-cache pyinstaller==$PYINSTALLER_VERSION && \
    chmod +x /entrypoint.sh

# Set the working directory and create a volume for source code
+1 −1
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ Add `pyinstaller==6.9.0` to your `requirements.txt`.

### Is it possible to use a package mirror?

Yes, by supplying the `PYPI_URL` and `PYPI_INDEX_URL` environment variables that point to your PyPi mirror.
Yes, by supplying the `PYPI_URL` and `PYPI_INDEX_URL` environment variables that point to your PyPI mirror. On Linux images, these are translated to `UV_INDEX_URL` and `UV_INSECURE_HOST` for [uv](https://github.com/astral-sh/uv), which is used as the package installer.

### How do I use image in GitLab CI?

+7 −11
Original line number Diff line number Diff line
@@ -24,22 +24,18 @@ SPECFILE=${SPECFILE:-$(find . -maxdepth 1 -type f -name '*.spec' -print -quit)}

if [[ "$PYPI_URL" != "https://pypi.python.org/" ]] || \
   [[ "$PYPI_INDEX_URL" != "https://pypi.python.org/simple" ]]; then
    # the funky looking regexp just extracts the hostname, excluding port
    # to be used as a trusted-host.
    mkdir -p /root/.pip
    echo "[global]" > /root/.pip/pip.conf
    echo "index = $PYPI_URL" >> /root/.pip/pip.conf
    echo "index-url = $PYPI_INDEX_URL" >> /root/.pip/pip.conf
    echo "trusted-host = $(echo $PYPI_URL | perl -pe 's|^.*?://(.*?)(:.*?)?/.*$|$1|')" >> /root/.pip/pip.conf

    echo "Using custom pip.conf: "
    cat /root/.pip/pip.conf
    export UV_INDEX_URL="$PYPI_INDEX_URL"
    # Extract hostname to allow insecure (non-HTTPS) private mirrors
    export UV_INSECURE_HOST="$(echo $PYPI_URL | perl -pe 's|^.*?://(.*?)(:.*?)?/.*$|$1|')"

    echo "Using custom PyPI index: $UV_INDEX_URL"
    echo "Insecure host: $UV_INSECURE_HOST"
fi

cd $WORKDIR

if [ -f requirements.txt ]; then
    pip3 install -r requirements.txt
    uv pip install --system -r requirements.txt
fi # [ -f requirements.txt ]

echo "$@"