shivamsshhiivvaamm commited on
Commit
29d6521
·
verified ·
1 Parent(s): acfb734

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +40 -3
Dockerfile CHANGED
@@ -1,14 +1,51 @@
 
 
 
1
  FROM python:3.11-slim
2
 
 
 
 
 
 
 
 
 
 
 
 
3
  WORKDIR /app
4
 
 
5
  COPY requirements.txt .
6
- RUN pip install --no-cache-dir -r requirements.txt
7
 
8
- COPY . .
 
 
 
 
 
 
9
 
10
- ENV PYTHONUNBUFFERED=1
 
 
 
 
 
 
 
 
 
 
 
11
 
 
12
  EXPOSE 7860
13
 
 
 
 
 
 
14
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ # Dockerfile for Resource Calculator Project
2
+ # Optimized for FastAPI with robust network handling and health checks
3
+
4
  FROM python:3.11-slim
5
 
6
+ # Build arguments for network timeout handling (as per reference)
7
+ ARG PIP_DEFAULT_TIMEOUT=1000
8
+ ARG PIP_RETRIES=5
9
+
10
+ # Set environment variables
11
+ ENV PIP_DEFAULT_TIMEOUT=${PIP_DEFAULT_TIMEOUT}
12
+ ENV PIP_RETRIES=${PIP_RETRIES}
13
+ ENV PYTHONUNBUFFERED=1
14
+ ENV PORT=8000
15
+
16
+ # Set working directory
17
  WORKDIR /app
18
 
19
+ # Copy requirements file
20
  COPY requirements.txt .
 
21
 
22
+ # Install Python dependencies in optimized batches (as per reference style)
23
+ # Note: Removed OpenCV/YOLO dependencies as they are not needed for this project
24
+ RUN pip install --no-cache-dir --timeout=1000 \
25
+ fastapi>=0.104.0 \
26
+ uvicorn[standard]>=0.24.0 \
27
+ pydantic>=2.0.0 \
28
+ aiofiles
29
 
30
+ # Copy application files explicitly
31
+ COPY main.py .
32
+ COPY calculator.py .
33
+ COPY config.py .
34
+ COPY index.html .
35
+ COPY style.css .
36
+ COPY script.js .
37
+
38
+ # Create a non-privileged user for security
39
+ RUN useradd -m -u 1000 user
40
+ RUN chown -R user:user /app
41
+ USER user
42
 
43
+ # Expose port 8000
44
  EXPOSE 7860
45
 
46
+ # Health check (as per reference)
47
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
48
+ CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/')" || exit 1
49
+
50
+ # Run the application
51
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]