|
1 | | -# Use a Python image with uv pre-installed |
2 | | -FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim |
| 1 | +FROM python:3.13-slim |
3 | 2 |
|
4 | | -# Install the project into `/app` |
| 3 | +# Set the working directory inside the container |
5 | 4 | WORKDIR /app |
6 | 5 |
|
7 | | -# Enable bytecode compilation |
8 | | -ENV UV_COMPILE_BYTECODE=1 |
| 6 | +# Copy the requirements file to the working directory |
| 7 | +COPY requirements.txt . |
9 | 8 |
|
10 | | -# Copy from the cache instead of linking since it's a mounted volume |
11 | | -ENV UV_LINK_MODE=copy |
| 9 | +# Install the Python dependencies |
| 10 | +RUN pip install -r requirements.txt |
12 | 11 |
|
13 | | -# Ensure installed tools can be executed out of the box |
14 | | -ENV UV_TOOL_BIN_DIR=/usr/local/bin |
| 12 | +# Copy the application code to the working directory |
| 13 | +COPY . . |
15 | 14 |
|
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 |
| 15 | +# Expose the port on which the application will run |
| 16 | +EXPOSE 8000 |
21 | 17 |
|
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 |
29 | | -ENV PATH="/app/.venv/bin:$PATH" |
30 | | - |
31 | | -# Reset the entrypoint, don't invoke `uv` |
32 | | -ENTRYPOINT [] |
33 | | - |
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"] |
| 18 | +# Run the FastAPI application using uvicorn server |
| 19 | +CMD ["uvicorn", "fastapi:app", "--host", "0.0.0.0", "--port", "8000"] |
0 commit comments