Spaces:
Runtime error
Runtime error
Hoe commited on
Commit ·
3221d82
1
Parent(s): 9bd9952
Fix: run uvicorn as a python module
Browse files- Dockerfile +7 -7
Dockerfile
CHANGED
|
@@ -2,27 +2,27 @@ FROM python:3.11-slim
|
|
| 2 |
|
| 3 |
# 1. Setup the user and the directory
|
| 4 |
RUN useradd -m -u 1000 user
|
| 5 |
-
# Create the directory and GIVE ownership to the user immediately
|
| 6 |
RUN mkdir -p /home/user/app && chown user:user /home/user/app
|
| 7 |
WORKDIR /home/user/app
|
| 8 |
|
| 9 |
# 2. Install 'uv'
|
| 10 |
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
|
| 11 |
|
| 12 |
-
# 3. Switch to the user
|
| 13 |
USER user
|
| 14 |
|
| 15 |
-
# 4. Copy the project files
|
| 16 |
COPY --chown=user . .
|
| 17 |
|
| 18 |
-
# 5. Run the sync
|
| 19 |
-
#
|
| 20 |
-
RUN /usr/local/bin/uv sync --all-extras
|
|
|
|
| 21 |
|
| 22 |
# 6. Set Hugging Face environment
|
| 23 |
ENV PORT=7860
|
| 24 |
EXPOSE 7860
|
| 25 |
|
| 26 |
# 7. Start the API
|
| 27 |
-
#
|
| 28 |
CMD ["/usr/local/bin/uv", "run", "python", "-m", "uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 2 |
|
| 3 |
# 1. Setup the user and the directory
|
| 4 |
RUN useradd -m -u 1000 user
|
|
|
|
| 5 |
RUN mkdir -p /home/user/app && chown user:user /home/user/app
|
| 6 |
WORKDIR /home/user/app
|
| 7 |
|
| 8 |
# 2. Install 'uv'
|
| 9 |
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
|
| 10 |
|
| 11 |
+
# 3. Switch to the user
|
| 12 |
USER user
|
| 13 |
|
| 14 |
+
# 4. Copy the project files
|
| 15 |
COPY --chown=user . .
|
| 16 |
|
| 17 |
+
# 5. Run the sync AND explicitly add uvicorn/fastapi
|
| 18 |
+
# This ensures even if they are missing from pyproject.toml, they get installed
|
| 19 |
+
RUN /usr/local/bin/uv sync --all-extras && \
|
| 20 |
+
/usr/local/bin/uv add uvicorn fastapi
|
| 21 |
|
| 22 |
# 6. Set Hugging Face environment
|
| 23 |
ENV PORT=7860
|
| 24 |
EXPOSE 7860
|
| 25 |
|
| 26 |
# 7. Start the API
|
| 27 |
+
# We use 'uv run' to ensure we are inside the virtualenv
|
| 28 |
CMD ["/usr/local/bin/uv", "run", "python", "-m", "uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "7860"]
|