At41rv commited on
Commit
126b92c
·
verified ·
1 Parent(s): 0cb06a0

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +24 -23
Dockerfile CHANGED
@@ -1,31 +1,32 @@
1
- # Dockerfile (for your proxy Space)
2
- # --------------------
3
- # Use a Python base image (using a more specific and stable version)
4
- FROM python:3.9-slim-buster
5
 
6
- # Create a non-root user for security best practices
7
- RUN useradd -m -u 1000 user
8
- USER user
9
-
10
- # Set the working directory inside the container
11
  WORKDIR /app
12
 
13
- # Ensure pip is up-to-date and then install dependencies from requirements.txt
14
- # This two-step process can sometimes be more robust in Docker environments.
15
- COPY --chown=user:user requirements.txt .
16
- RUN pip install --no-cache-dir --upgrade pip && \
17
- pip install --no-cache-dir -r requirements.txt
 
 
18
 
19
- # Add the user's local bin directory to the PATH to ensure executables like uvicorn are found
20
- ENV PATH="/home/user/.local/bin:$PATH"
21
 
22
- # Copy your application code
23
- COPY --chown=user:user . .
24
 
25
- # Expose the port Hugging Face Spaces expects (7860)
 
 
 
 
26
  EXPOSE 7860
27
 
28
- # Command to run your FastAPI application with Uvicorn
29
- # Using 'python -m uvicorn' is generally more robust as it explicitly tells Python
30
- # to run uvicorn as a module, ensuring it's found within the environment.
31
- CMD ["python", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
1
+ FROM python:3.10-slim
 
 
 
2
 
3
+ # Set working directory
 
 
 
 
4
  WORKDIR /app
5
 
6
+ # Install system dependencies
7
+ RUN apt-get update && apt-get install -y \
8
+ gcc \
9
+ && rm -rf /var/lib/apt/lists/*
10
+
11
+ # Copy requirements first for better caching
12
+ COPY requirements.txt .
13
 
14
+ # Install Python dependencies
15
+ RUN pip install --no-cache-dir -r requirements.txt
16
 
17
+ # Copy application code
18
+ COPY app.py .
19
 
20
+ # Create non-root user for security
21
+ RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
22
+ USER appuser
23
+
24
+ # Expose port
25
  EXPOSE 7860
26
 
27
+ # Health check
28
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
29
+ CMD python -c "import requests; requests.get('http://localhost:7860/health')"
30
+
31
+ # Run the application
32
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]