Harshit Ghosh commited on
Commit ·
410e48e
1
Parent(s): 81dc127
Deploy Phase 4: Docker and Celery setup
Browse files- Dockerfile +42 -0
- start.sh +13 -0
Dockerfile
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use an official Python runtime as a parent image
|
| 2 |
+
FROM python:3.12-slim
|
| 3 |
+
|
| 4 |
+
# Set environment variables
|
| 5 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
| 6 |
+
ENV PYTHONUNBUFFERED=1
|
| 7 |
+
ENV PORT=7860
|
| 8 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
| 9 |
+
|
| 10 |
+
# Install system dependencies for OpenCV and DICOM processing
|
| 11 |
+
RUN apt-get update && apt-get install -y \
|
| 12 |
+
libgl1-mesa-glx \
|
| 13 |
+
libglib2.0-0 \
|
| 14 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 15 |
+
|
| 16 |
+
# Set work directory
|
| 17 |
+
WORKDIR /app
|
| 18 |
+
|
| 19 |
+
# Create a non-root user (Hugging Face Spaces requirement)
|
| 20 |
+
RUN useradd -m -u 1000 user
|
| 21 |
+
|
| 22 |
+
# Install Python dependencies
|
| 23 |
+
COPY requirements.txt .
|
| 24 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 25 |
+
|
| 26 |
+
# Copy the rest of the application
|
| 27 |
+
COPY . .
|
| 28 |
+
|
| 29 |
+
# Create necessary directories and set permissions for the non-root user
|
| 30 |
+
RUN mkdir -p uploads logs instance \
|
| 31 |
+
&& chown -R user:user /app \
|
| 32 |
+
&& chmod -R 755 /app \
|
| 33 |
+
&& chmod +x start.sh
|
| 34 |
+
|
| 35 |
+
# Switch to the non-root user
|
| 36 |
+
USER user
|
| 37 |
+
|
| 38 |
+
# Expose the port Hugging Face Spaces uses
|
| 39 |
+
EXPOSE 7860
|
| 40 |
+
|
| 41 |
+
# Run the startup script
|
| 42 |
+
CMD ["./start.sh"]
|
start.sh
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# Start Celery worker in background
|
| 4 |
+
# We use concurrency=2 to avoid memory overload on the 16GB free tier
|
| 5 |
+
celery -A tasks worker --loglevel=info --concurrency=2 &
|
| 6 |
+
CELERY_PID=$!
|
| 7 |
+
|
| 8 |
+
# Trap SIGTERM and SIGINT for graceful shutdown
|
| 9 |
+
trap "kill $CELERY_PID; exit 0" SIGTERM SIGINT
|
| 10 |
+
|
| 11 |
+
# Start Gunicorn in foreground
|
| 12 |
+
# Hugging Face Spaces expects the app to listen on port 7860
|
| 13 |
+
gunicorn -w 4 -b 0.0.0.0:${PORT:-7860} app_new:app
|