File size: 1,948 Bytes
60c56d7 8294547 60c56d7 8fa7f23 5c1f200 60c56d7 680dd7d 76c83b6 680dd7d 76c83b6 60c56d7 8fa7f23 60c56d7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
FROM python:3.10-slim
# Set working directory
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
libgl1 \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender-dev \
libgomp1 \
git \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements first for better caching
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# Create directories for uploads and results
# Ensure writable data directory exists for Spaces
RUN mkdir -p /data/uploads /data/results && chmod -R 777 /data
# Handle Firebase credentials from environment variable (for Hugging Face Spaces secrets)
# This allows the credentials to be passed as a secret and written to file at runtime
RUN echo '#!/bin/sh' > /entrypoint.sh && \
echo 'set -e' >> /entrypoint.sh && \
echo 'if [ -n "$FIREBASE_CREDENTIALS" ]; then' >> /entrypoint.sh && \
echo ' mkdir -p /data' >> /entrypoint.sh && \
echo ' touch /data/firebase-adminsdk.json' >> /entrypoint.sh && \
echo ' chmod 600 /data/firebase-adminsdk.json' >> /entrypoint.sh && \
echo ' printf "%s" "$FIREBASE_CREDENTIALS" > /data/firebase-adminsdk.json' >> /entrypoint.sh && \
echo 'fi' >> /entrypoint.sh && \
echo 'exec "$@"' >> /entrypoint.sh && \
chmod +x /entrypoint.sh
# Expose port (Hugging Face Spaces uses port 7860)
EXPOSE 7860
# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV BASE_URL=${SPACE_HOST}
ENV PORT=7860
ENV DATA_DIR=/data
ENV OMP_NUM_THREADS=1
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD python -c "import requests; requests.get('http://localhost:7860/health', timeout=5)" || exit 1
# Set entrypoint
ENTRYPOINT ["/entrypoint.sh"]
# Run the application (port will be set via environment variable)
CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-7860}"]
|