Hoe commited on
Commit
5bfd791
·
1 Parent(s): 9643612

Fix: run uvicorn as a python module

Browse files
Files changed (1) hide show
  1. Dockerfile +9 -10
Dockerfile CHANGED
@@ -7,16 +7,15 @@ WORKDIR /home/user/app
7
  # 2. Install UV
8
  COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
9
 
10
- # 3. Copy files (as root to ensure they transfer correctly)
11
- COPY . .
12
 
13
- # 4. Install dependencies and the workspace
14
- # We install fastapi and uvicorn explicitly to the workspace environment
15
  RUN /usr/local/bin/uv sync --all-extras && \
16
  /usr/local/bin/uv add fastapi uvicorn
17
 
18
- # 5. Fix Permissions
19
- # This prevents the 'Permission Denied' os error 13 on the .venv
20
  RUN chown -R user:user /home/user/app
21
 
22
  # 6. Switch to non-root user
@@ -24,10 +23,10 @@ USER user
24
 
25
  # 7. Environment Setup
26
  ENV PORT=7860
27
- # This allows the inner 'duckdb_loader' folder to be recognized as a package
28
  ENV PYTHONPATH=/home/user/app/duckdb_loader
29
  EXPOSE 7860
30
 
31
- # 8. Start the API
32
- # We point to: [folder].[subfolder].[file]:[app_variable]
33
- CMD ["/usr/local/bin/uv", "run", "python", "-m", "uvicorn", "duckdb_loader.main:app", "--host", "0.0.0.0", "--port", "7860"]
 
7
  # 2. Install UV
8
  COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
9
 
10
+ # 3. Copy files
11
+ COPY --chown=user . .
12
 
13
+ # 4. Install dependencies
14
+ # We install fastapi and uvicorn into the workspace environment
15
  RUN /usr/local/bin/uv sync --all-extras && \
16
  /usr/local/bin/uv add fastapi uvicorn
17
 
18
+ # 5. Fix Permissions (Crucial for Hugging Face)
 
19
  RUN chown -R user:user /home/user/app
20
 
21
  # 6. Switch to non-root user
 
23
 
24
  # 7. Environment Setup
25
  ENV PORT=7860
26
+ # This allows 'import duckdb_loader' to work from the app root
27
  ENV PYTHONPATH=/home/user/app/duckdb_loader
28
  EXPOSE 7860
29
 
30
+ # 8. THE CMD: Navigate the double-nest
31
+ # Package (duckdb_loader) -> Sub-Package (duckdb_loader) -> Module (main) -> Object (app)
32
+ CMD ["/usr/local/bin/uv", "run", "python", "-m", "uvicorn", "duckdb_loader.duckdb_loader.main:app", "--host", "0.0.0.0", "--port", "7860"]