Spaces:
Sleeping
Sleeping
| FROM python:3.11-slim | |
| # Create user first | |
| RUN useradd -m -u 1000 user | |
| # Create necessary directories | |
| RUN mkdir -p /tmp/fasttext_cache /app/logs && \ | |
| chown -R user:user /tmp/fasttext_cache /app/logs | |
| # Install curl for healthcheck | |
| RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/* | |
| # Create startup script | |
| RUN echo '#!/bin/bash\n\ | |
| echo "Starting application..."\n\ | |
| echo "Checking MODEL_URL accessibility..."\n\ | |
| curl --head --silent --fail ${MODEL_URL} || (echo "ERROR: Cannot access MODEL_URL" && exit 1)\n\ | |
| echo "MODEL_URL is accessible"\n\ | |
| echo "Starting uvicorn server..."\n\ | |
| exec uvicorn main:app --host 0.0.0.0 --port 7860 --log-level info' > /app/start.sh && \ | |
| chmod +x /app/start.sh && \ | |
| chown user:user /app/start.sh | |
| # Switch to user after setting up permissions | |
| USER user | |
| ENV PATH="/home/user/.local/bin:$PATH" | |
| ENV MODEL_URL="https://huggingface.co/Miroir/cc.fr.300.reduced/resolve/main/cc.fr.300.reduced.vec" | |
| ENV PYTHONUNBUFFERED=1 | |
| WORKDIR /app | |
| COPY --chown=user requirements.txt requirements.txt | |
| # Install dependencies | |
| RUN pip install --no-cache-dir --upgrade pip && \ | |
| pip install --no-cache-dir --upgrade -r requirements.txt | |
| COPY --chown=user . . | |
| # Create data directory for game state | |
| RUN mkdir -p /app/data && chown user:user /app/data | |
| # Add healthcheck | |
| HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ | |
| CMD curl -f http://localhost:7860/ || exit 1 | |
| CMD ["/app/start.sh"] |