project5 / Dockerfile
GitHub Action
Deploy to HuggingFace Spaces from main branch
66a0674
FROM python:3.11-slim
# Installer Poetry et les dépendances système pour SQLite
RUN apt-get update && apt-get install -y \
sqlite3 \
libsqlite3-dev \
&& rm -rf /var/lib/apt/lists/* \
&& pip install poetry
# Configuration Poetry
ENV POETRY_NO_INTERACTION=1 \
POETRY_VENV_IN_PROJECT=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache \
VIRTUAL_ENV=/code/.venv \
PATH="/code/.venv/bin:$PATH"
WORKDIR /code
# Copier les fichiers de dépendances
COPY pyproject.toml poetry.lock ./
# Copier le code source d'abord
COPY . .
# Configurer Poetry pour créer le venv dans le projet
RUN poetry config virtualenvs.in-project true && \
poetry install --only main --no-interaction --no-ansi
# Installer toutes les dépendances et le projet
#RUN poetry install --only=main && rm -rf $POETRY_CACHE_DIR
# Configuration pour SQLite et HuggingFace Spaces
ENV DATABASE_URL="sqlite:///:memory:" \
ENVIRONMENT="production" \
PORT=7860
ENV ML_MODEL_PATH=../model/model.pkl
# Exposer le port requis par HF Spaces
EXPOSE 7860
# Rendre le script d'initialisation exécutable
RUN chmod +x init_db.py
# Commande de démarrage avec initialisation de la base
CMD ["sh", "-c", " poetry env activate && cd src && poetry run uvicorn project5.main:app --host 0.0.0.0 --port 7860"]