| 
1 |  | -FROM ghcr.io/astral-sh/uv:latest  | 
 | 1 | +# Use a Python image with uv pre-installed  | 
 | 2 | +FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim  | 
2 | 3 | 
 
  | 
 | 4 | +# Install the project into `/app`  | 
3 | 5 | WORKDIR /app  | 
4 | 6 | 
 
  | 
5 |  | -# Копируем все файлы проекта сразу  | 
6 |  | -COPY . .  | 
 | 7 | +# Enable bytecode compilation  | 
 | 8 | +ENV UV_COMPILE_BYTECODE=1  | 
7 | 9 | 
 
  | 
8 |  | -# Устанавливаем зависимости  | 
9 |  | -RUN uv sync --no-dev  | 
 | 10 | +# Copy from the cache instead of linking since it's a mounted volume  | 
 | 11 | +ENV UV_LINK_MODE=copy  | 
10 | 12 | 
 
  | 
 | 13 | +# Ensure installed tools can be executed out of the box  | 
 | 14 | +ENV UV_TOOL_BIN_DIR=/usr/local/bin  | 
 | 15 | + | 
 | 16 | +# Install the project's dependencies using the lockfile and settings  | 
 | 17 | +RUN --mount=type=cache,target=/root/.cache/uv \  | 
 | 18 | +    --mount=type=bind,source=uv.lock,target=uv.lock \  | 
 | 19 | +    --mount=type=bind,source=pyproject.toml,target=pyproject.toml \  | 
 | 20 | +    uv sync --locked --no-install-project --no-dev  | 
 | 21 | + | 
 | 22 | +# Then, add the rest of the project source code and install it  | 
 | 23 | +# Installing separately from its dependencies allows optimal layer caching  | 
 | 24 | +COPY . /app  | 
 | 25 | +RUN --mount=type=cache,target=/root/.cache/uv \  | 
 | 26 | +    uv sync --locked --no-dev  | 
 | 27 | + | 
 | 28 | +# Place executables in the environment at the front of the path  | 
11 | 29 | ENV PATH="/app/.venv/bin:$PATH"  | 
12 | 30 | 
 
  | 
13 |  | -EXPOSE 8000  | 
 | 31 | +# Reset the entrypoint, don't invoke `uv`  | 
 | 32 | +ENTRYPOINT []  | 
14 | 33 | 
 
  | 
15 |  | -CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]  | 
 | 34 | +# Run the FastAPI application by default  | 
 | 35 | +# Uses `fastapi dev` to enable hot-reloading when the `watch` sync occurs  | 
 | 36 | +# Uses `--host 0.0.0.0` to allow access from outside the container  | 
 | 37 | +CMD ["uvicorn", "main:app", \  | 
 | 38 | +    "--host", "0.0.0.0", \  | 
 | 39 | +    "--port", "8000", \  | 
 | 40 | +    "--workers", "1", \  | 
 | 41 | +    "--limit-concurrency", "100", \  | 
 | 42 | +    "--limit-max-requests", "1000", \  | 
 | 43 | +    "--timeout-keep-alive", "5", \  | 
 | 44 | +    "--access-log"]  | 
0 commit comments