fix: failed to solve: process /bin/sh -c pip install --no-cache-dir -r requirements.txt did not complete successfully

This commit is contained in:
k
2026-04-21 19:49:47 +08:00
parent 3f901df82b
commit 0782aed4e6
2 changed files with 39 additions and 33 deletions
+21 -15
View File
@@ -1,34 +1,40 @@
FROM python:3.11-slim
# ── Stage 1: build ───────────────────────────────────────────────────────────
# Compiles native extensions (ckzg, asyncpg, cryptography) so the final image
# only carries the compiled .so files, not the build toolchain.
FROM python:3.11-slim AS builder
# System deps needed for native extensions:
# gcc, libpq-dev → asyncpg (Postgres driver)
# libffi-dev → cryptography
# build-essential → general C compilation fallback
# curl → healthcheck probe
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc build-essential libpq-dev libffi-dev curl \
gcc build-essential cmake libpq-dev libffi-dev \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
WORKDIR /build
# Upgrade pip + install wheel first so pre-built wheels are preferred
RUN pip install --no-cache-dir --upgrade pip wheel setuptools
# Install Python deps (separate layer for cache efficiency)
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
# App source
# ── Stage 2: runtime ─────────────────────────────────────────────────────────
FROM python:3.11-slim
# Only runtime shared libs needed (libpq for asyncpg, libgomp for numpy if used)
RUN apt-get update && apt-get install -y --no-install-recommends \
libpq5 curl \
&& rm -rf /var/lib/apt/lists/*
# Copy compiled packages from builder
COPY --from=builder /install /usr/local
WORKDIR /app
COPY . .
# Make entrypoint executable
RUN chmod +x entrypoint.sh
# Non-root user for security
# Non-root user
RUN useradd -m appuser && chown -R appuser /app
USER appuser
EXPOSE 8000
# Runs: alembic upgrade head → uvicorn
ENTRYPOINT ["./entrypoint.sh"]