| FROM python:3.9-slim | |
| WORKDIR /app | |
| # Create a user to run the app (Hugging Face Spaces requirement) | |
| RUN useradd -m -u 1000 user | |
| # Install required packages | |
| COPY requirements.txt /app/ | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| RUN pip install --no-cache-dir gunicorn | |
| # Copy the rest of the application | |
| COPY . /app/ | |
| # Set ownership to the non-root user so the app can create and write to game.db | |
| RUN chown -R user:user /app | |
| # Switch to the non-root user | |
| USER user | |
| # Expose port 7860 which is the default for Hugging Face Spaces | |
| EXPOSE 7860 | |
| # Initialize the database and then start gunicorn | |
| CMD ["sh", "-c", "python -c 'from app import init_db; init_db()' && gunicorn -b 0.0.0.0:7860 app:app"] | |