Merge pull request 'test: add path, switch to uv [release-patch]' (#3) from dev into main
Reviewed-on: #3
This commit was merged in pull request #3.
This commit is contained in:
38
Dockerfile
38
Dockerfile
@@ -3,23 +3,25 @@ FROM python:3.13-slim AS builder
|
|||||||
# Prevent Python from writing .pyc files and enable unbuffered stdout/stderr
|
# Prevent Python from writing .pyc files and enable unbuffered stdout/stderr
|
||||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||||
PYTHONUNBUFFERED=1 \
|
PYTHONUNBUFFERED=1 \
|
||||||
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
|
||||||
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
|
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install build deps required to build wheels
|
# Install build deps required to build wheels and tools needed to fetch uv
|
||||||
RUN apt-get update \
|
RUN apt-get update \
|
||||||
&& apt-get install -y --no-install-recommends build-essential gcc \
|
&& apt-get install -y --no-install-recommends build-essential gcc curl ca-certificates \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Upgrade packaging tools and install runtime dependencies into a separate prefix
|
# Install uv into this stage by copying official uv binaries from the uv image
|
||||||
COPY requirements.txt ./
|
COPY --from=ghcr.io/astral-sh/uv:python3.13-trixie-slim /uv /uvx /bin/
|
||||||
RUN pip install --upgrade pip setuptools wheel \
|
|
||||||
&& pip install --prefix=/install --no-cache-dir \
|
# Copy only metadata first so dependency installs can be cached
|
||||||
--extra-index-url https://git.theprivateserver.de/api/packages/PHB/pypi/simple/ \
|
COPY pyproject.toml ./
|
||||||
-r requirements.txt \
|
|
||||||
&& rm -rf /root/.cache/pip
|
# Use uv to resolve & install the project's dependencies (no project source yet)
|
||||||
|
# This creates a .venv containing all dependencies which we move to /install
|
||||||
|
RUN uv sync --no-install-project --no-editable \
|
||||||
|
&& mv .venv /install
|
||||||
|
|
||||||
# Copy application source (only used to include app files in final image)
|
# Copy application source (only used to include app files in final image)
|
||||||
COPY . /app
|
COPY . /app
|
||||||
@@ -32,12 +34,16 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy installed packages from the builder image into the final image
|
# Bring uv into the final image so we can run the app with it
|
||||||
COPY --from=builder /install /usr/local
|
COPY --from=ghcr.io/astral-sh/uv:python3.13-trixie-slim /uv /uvx /bin/
|
||||||
# Copy application sources
|
|
||||||
|
# Copy the prepared environment from the builder and the application
|
||||||
|
COPY --from=builder /install /app/.venv
|
||||||
COPY --from=builder /app /app
|
COPY --from=builder /app /app
|
||||||
|
|
||||||
EXPOSE 8001
|
ENV PATH="/app/.venv/bin:$PATH"
|
||||||
|
|
||||||
# Run using uvicorn; the app is defined in `api_service.py` as `app`
|
EXPOSE ${API_PORT}
|
||||||
CMD ["uvicorn", "api_service:app", "--host", "0.0.0.0", "--port", "8001"]
|
|
||||||
|
# Use uv to run the app inside the synced environment
|
||||||
|
CMD ["uv", "run", "python", "api_service.py"]
|
||||||
|
|||||||
Reference in New Issue
Block a user