Skip to content

Commit b9b9d8f

Browse files
committed
fix: improve Docker Python environment setup for reliable builds
Python environment improvements: - Add essential build dependencies (python3-dev, g++, make, pkg-config) - Add libffi-dev and libssl-dev for cryptographic packages - Simplify requirements copying (remove pyproject.toml dependency) - Use proper uv virtual environment setup with explicit PATH - Add verbose output for debugging dependency installation - Remove redundant gRPC installation (already in requirements.txt) Build dependencies added: - gcc, g++: C/C++ compilers for native extensions - make: Build automation tool - pkg-config: Package configuration tool - libffi-dev: Foreign Function Interface library - libssl-dev: SSL/TLS library for secure connections - python3-dev: Python development headers These changes should resolve the Docker build failures related to Python package compilation, particularly for gRPC and other native extensions that require compilation during installation. Signed-off-by: longhao <[email protected]>
1 parent f9d38c2 commit b9b9d8f

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

Dockerfile

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,32 @@ FROM python:3.11-slim AS python-base
3434

3535
WORKDIR /app
3636

37-
# Install system dependencies
37+
# Install system dependencies for building Python packages
3838
RUN apt-get update && apt-get install -y \
3939
gcc \
40+
g++ \
41+
make \
42+
pkg-config \
43+
libffi-dev \
44+
libssl-dev \
45+
python3-dev \
4046
&& rm -rf /var/lib/apt/lists/*
4147

4248
# Install UV
43-
RUN pip install uv
49+
RUN pip install --no-cache-dir uv
4450

4551
# Copy Python requirements
46-
COPY pyproject.toml ./
47-
COPY requirements*.txt ./
52+
COPY requirements.txt ./
4853

49-
# Install Python dependencies
50-
RUN uv venv /opt/venv && \
51-
/opt/venv/bin/pip install grpcio grpcio-tools && \
52-
/opt/venv/bin/pip install -r requirements.txt
54+
# Create virtual environment and install dependencies using uv
55+
RUN uv venv /opt/venv
56+
ENV VIRTUAL_ENV=/opt/venv
57+
ENV PATH="/opt/venv/bin:$PATH"
58+
59+
# Install Python dependencies using uv with verbose output
60+
RUN echo "Installing Python dependencies..." && \
61+
cat requirements.txt && \
62+
uv pip install --verbose -r requirements.txt
5363

5464
# Stage 3: Final runtime image
5565
FROM python:3.11-slim

0 commit comments

Comments
 (0)