Durand D'souza commited on
Commit
f21e7bc
·
unverified ·
1 Parent(s): d05e7ba
Files changed (1) hide show
  1. Dockerfile +23 -17
Dockerfile CHANGED
@@ -1,26 +1,32 @@
1
- # Use the official Python 3.10.9 image
2
- FROM python:3.12-slim-bookworm
3
- # The installer requires curl (and certificates) to download the release archive
4
- RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates
5
 
6
- # Download the latest installer
7
- ADD https://astral.sh/uv/install.sh /uv-installer.sh
8
 
9
- # Run the installer then remove it
10
- RUN sh /uv-installer.sh && rm /uv-installer.sh
11
 
12
- # Ensure the installed binary is on the `PATH`
13
- ENV PATH="/root/.local/bin/:$PATH"
14
 
15
- # Copy the project into the image
16
- ADD . /app
 
 
 
17
 
18
- # Sync the project into a new environment, using the frozen lockfile
19
- WORKDIR /app
 
 
 
20
 
21
- ENV UV_CACHE_DIR=/opt/uv-cache/
 
22
 
23
- RUN uv sync --frozen
 
24
 
25
  # Start the FastAPI app on port 7860, the default port expected by Spaces
26
- CMD ["uv", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ # Use a Python image with uv pre-installed
2
+ FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
 
 
3
 
4
+ # Install the project into `/app`
5
+ WORKDIR /app
6
 
7
+ # Enable bytecode compilation
8
+ ENV UV_COMPILE_BYTECODE=1
9
 
10
+ # Copy from the cache instead of linking since it's a mounted volume
11
+ ENV UV_LINK_MODE=copy
12
 
13
+ # Install the project's dependencies using the lockfile and settings
14
+ RUN --mount=type=cache,target=/root/.cache/uv \
15
+ --mount=type=bind,source=uv.lock,target=uv.lock \
16
+ --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
17
+ uv sync --frozen --no-install-project --no-dev
18
 
19
+ # Then, add the rest of the project source code and install it
20
+ # Installing separately from its dependencies allows optimal layer caching
21
+ ADD . /app
22
+ RUN --mount=type=cache,target=/root/.cache/uv \
23
+ uv sync --frozen --no-dev
24
 
25
+ # Place executables in the environment at the front of the path
26
+ ENV PATH="/app/.venv/bin:$PATH"
27
 
28
+ # Reset the entrypoint, don't invoke `uv`
29
+ ENTRYPOINT []
30
 
31
  # Start the FastAPI app on port 7860, the default port expected by Spaces
32
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]