Stoic-2910 commited on
Commit
5aa6158
·
verified ·
1 Parent(s): debbc6e

Upload Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +42 -0
Dockerfile ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Stage 1: Build dependencies
2
+ FROM python:3.11-slim AS builder
3
+
4
+ # Copy the uv binary from the official image
5
+ COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
6
+
7
+ # Enable bytecode compilation and use copy instead of hardlinks
8
+ ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
9
+
10
+ WORKDIR /app
11
+
12
+ # Copy configuration files
13
+ COPY pyproject.toml uv.lock ./
14
+
15
+ # Install dependencies into a virtual environment
16
+ RUN uv sync --frozen --no-dev
17
+
18
+ # Stage 2: Runtime
19
+ FROM python:3.11-slim AS runtime
20
+
21
+ WORKDIR /app
22
+
23
+ # Copy the virtual environment from the builder
24
+ COPY --from=builder /app/.venv /app/.venv
25
+
26
+ # Ensure the virtual environment is in the PATH
27
+ ENV PATH="/app/.venv/bin:$PATH"
28
+
29
+ # Create non-root user for security
30
+ # Hugging Face Spaces uses UID 1000
31
+ RUN useradd -m -u 1000 appuser
32
+
33
+ # Copy application code
34
+ COPY app/ ./app/
35
+
36
+ # Switch to non-root user
37
+ USER appuser
38
+
39
+ EXPOSE 7860
40
+
41
+ # Run the application using uvicorn from the virtual environment
42
+ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "2"]