Skip to content

Commit 40922c1

Browse files
github-actions[bot]Федор Батоноговclaude
authored
Replace pip with uv for faster dependency installation in Linux images (#162) (#191)
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: Федор Батоногов <fedor@MacBook-Air-Fedor.local> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent cd6911f commit 40922c1

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

Dockerfile-py3-linux

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ ENV PYTHONUNBUFFERED=1
1515
# Copy the entrypoint script
1616
COPY entrypoint-linux.sh /entrypoint.sh
1717

18+
# Install uv
19+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/
20+
1821
# Install dependencies, PyInstaller, and set execute permissions for the entrypoint
19-
RUN pip install --no-cache-dir pyinstaller==$PYINSTALLER_VERSION \
22+
RUN uv pip install --system --no-cache pyinstaller==$PYINSTALLER_VERSION \
2023
&& chmod +x /entrypoint.sh
2124

2225
# Set the working directory and mount the volume

Dockerfile-py3-linux-slim

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,25 @@ LABEL maintainer="f.batonogov@yandex.ru"
99
# Define PyInstaller version as an argument
1010
ARG PYINSTALLER_VERSION=6.17.0
1111

12-
# Configure Python Package Index URLs for pip
12+
# Configure Python Package Index URLs
1313
ENV PYPI_URL=https://pypi.python.org/
1414
ENV PYPI_INDEX_URL=https://pypi.python.org/simple
1515
ENV PYTHONUNBUFFERED=1
1616

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

20+
# Install uv
21+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/
22+
2023
# Install dependencies and PyInstaller in a single RUN command to reduce image layers
2124
RUN apt update && \
2225
apt install --no-install-recommends -y \
2326
binutils \
2427
gcc \
2528
zlib1g-dev && \
2629
rm -rf /var/lib/apt/lists/* && \
27-
pip install --no-cache-dir pyinstaller==$PYINSTALLER_VERSION && \
30+
uv pip install --system --no-cache pyinstaller==$PYINSTALLER_VERSION && \
2831
chmod +x /entrypoint.sh
2932

3033
# Set the working directory and create a volume for source code

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Add `pyinstaller==6.9.0` to your `requirements.txt`.
102102

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

105-
Yes, by supplying the `PYPI_URL` and `PYPI_INDEX_URL` environment variables that point to your PyPi mirror.
105+
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.
106106

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

entrypoint-linux.sh

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,18 @@ SPECFILE=${SPECFILE:-$(find . -maxdepth 1 -type f -name '*.spec' -print -quit)}
2424

2525
if [[ "$PYPI_URL" != "https://pypi.python.org/" ]] || \
2626
[[ "$PYPI_INDEX_URL" != "https://pypi.python.org/simple" ]]; then
27-
# the funky looking regexp just extracts the hostname, excluding port
28-
# to be used as a trusted-host.
29-
mkdir -p /root/.pip
30-
echo "[global]" > /root/.pip/pip.conf
31-
echo "index = $PYPI_URL" >> /root/.pip/pip.conf
32-
echo "index-url = $PYPI_INDEX_URL" >> /root/.pip/pip.conf
33-
echo "trusted-host = $(echo $PYPI_URL | perl -pe 's|^.*?://(.*?)(:.*?)?/.*$|$1|')" >> /root/.pip/pip.conf
34-
35-
echo "Using custom pip.conf: "
36-
cat /root/.pip/pip.conf
27+
export UV_INDEX_URL="$PYPI_INDEX_URL"
28+
# Extract hostname to allow insecure (non-HTTPS) private mirrors
29+
export UV_INSECURE_HOST="$(echo $PYPI_URL | perl -pe 's|^.*?://(.*?)(:.*?)?/.*$|$1|')"
30+
31+
echo "Using custom PyPI index: $UV_INDEX_URL"
32+
echo "Insecure host: $UV_INSECURE_HOST"
3733
fi
3834

3935
cd $WORKDIR
4036

4137
if [ -f requirements.txt ]; then
42-
pip3 install -r requirements.txt
38+
uv pip install --system -r requirements.txt
4339
fi # [ -f requirements.txt ]
4440

4541
echo "$@"

0 commit comments

Comments
 (0)