This commit is contained in:
50
Dockerfile
50
Dockerfile
@@ -1,49 +1,13 @@
|
|||||||
FROM python:3.13-slim AS builder
|
FROM python:3.13.9-slim
|
||||||
|
|
||||||
# Prevent Python from writing .pyc files and enable unbuffered stdout/stderr
|
RUN apk update
|
||||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
RUN apk upgrade
|
||||||
PYTHONUNBUFFERED=1 \
|
|
||||||
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
|
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install build deps required to build wheels and tools needed to fetch uv
|
COPY requirements.txt .
|
||||||
RUN apt-get update \
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
&& apt-get install -y --no-install-recommends build-essential gcc curl ca-certificates \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# Install uv into this stage by copying official uv binaries from the uv image
|
COPY . .
|
||||||
COPY --from=ghcr.io/astral-sh/uv:python3.13-trixie-slim /uv /uvx /bin/
|
|
||||||
|
|
||||||
# Copy only metadata first so dependency installs can be cached
|
ENTRYPOINT [ "python", "api_service.py" ]
|
||||||
COPY pyproject.toml ./
|
|
||||||
|
|
||||||
# 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 . /app
|
|
||||||
|
|
||||||
FROM python:3.13-slim
|
|
||||||
|
|
||||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
|
||||||
PYTHONUNBUFFERED=1 \
|
|
||||||
API_PORT=8001
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Bring uv into the final image so we can run the app with it
|
|
||||||
COPY --from=ghcr.io/astral-sh/uv:python3.13-trixie-slim /uv /uvx /bin/
|
|
||||||
|
|
||||||
# Copy the prepared environment from the builder and the application
|
|
||||||
COPY --from=builder /install /app/.venv
|
|
||||||
COPY --from=builder /app /app
|
|
||||||
|
|
||||||
ENV PATH="/app/.venv/bin:$PATH"
|
|
||||||
|
|
||||||
EXPOSE ${API_PORT}
|
|
||||||
|
|
||||||
# Use uv to run the app inside the synced environment
|
|
||||||
CMD ["uv", "run", "python", "api_service.py"]
|
|
||||||
Reference in New Issue
Block a user