Spaces:
Sleeping
Sleeping
Durand D'souza
commited on
UV fix
Browse files- Dockerfile +23 -17
Dockerfile
CHANGED
|
@@ -1,26 +1,32 @@
|
|
| 1 |
-
# Use
|
| 2 |
-
FROM
|
| 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 |
-
#
|
| 7 |
-
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
ENV
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
-
|
|
|
|
| 24 |
|
| 25 |
# Start the FastAPI app on port 7860, the default port expected by Spaces
|
| 26 |
-
CMD ["
|
|
|
|
| 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"]
|