LogicGoInfotechSpaces's picture
Improve entrypoint script creation in Dockerfile
76c83b6
raw
history blame
1.61 kB
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
RUN mkdir -p uploads results
# 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/bash' > /entrypoint.sh && \
echo 'if [ -n "$FIREBASE_CREDENTIALS" ]; then' >> /entrypoint.sh && \
echo ' echo "$FIREBASE_CREDENTIALS" > colorize-662df-firebase-adminsdk-fbsvc-e080668793.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
# 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}"]