This commit is contained in:
dxin
2025-10-16 11:46:36 +08:00
parent 8e0d47683b
commit aa16443f1d
2 changed files with 47 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
FROM python:3.12-slim AS builder
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
UV_LINK_MODE=copy \
UV_VERSION=0.4.17 \
UV_PROJECT_ENVIRONMENT=/opt/venv
WORKDIR /app
# Install build prerequisites, fetch uv, then remove leftover apt metadata.
RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates build-essential && \
rm -rf /var/lib/apt/lists/*
RUN curl -LsSf https://astral.sh/uv/install.sh | sh -s -- --version "${UV_VERSION}"
# Pre-copy manifests for better layer caching.
COPY pyproject.toml uv.lock requirements.txt ./
RUN /root/.local/bin/uv sync --frozen --no-dev --python /usr/local/bin/python && \
/root/.local/bin/uv cache prune --ci
FROM python:3.12-slim AS runtime
ARG APP_PORT=8000
ENV APP_ENV=local \
APP_PORT=${APP_PORT}
WORKDIR /app
# Runtime dependencies required by packages like faiss-cpu.
RUN apt-get update && apt-get install -y --no-install-recommends libgomp1 && \
rm -rf /var/lib/apt/lists/*
# Bring in the pre-built virtual environment from the builder stage.
COPY --from=builder /opt/venv /opt/venv
# Ship only the application sources in the runtime image.
COPY . .
ENV PATH="/opt/venv/bin:${PATH}" \
VIRTUAL_ENV="/opt/venv"
EXPOSE ${APP_PORT}
CMD ["sh", "-c", "python server.py --host ${HOST:-0.0.0.0} --port ${APP_PORT:-8000}"]