rasabot / Dockerfile
atkiya110's picture
Update Dockerfile
c4bf835 verified
FROM python:3.10-slim
# ── Non-root user ─────────────────────────────────────────────────────────────
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH \
RASA_TELEMETRY_ENABLED=false \
PYTHONUNBUFFERED=1 \
# Keep HuggingFace / torch caches writable by uid 1000
HF_HOME=/home/user/.cache/huggingface \
TRANSFORMERS_CACHE=/home/user/.cache/transformers
WORKDIR $HOME/app
# ── Python deps ───────────────────────────────────────────────────────────────
# Install order matters:
# 1. numpy pinned first β€” Rasa 3.6.x breaks on numpy β‰₯ 1.24
# 2. aiogram / jax pinned for compatibility
# 3. rasa itself (pulls in most heavy deps)
# 4. project-specific requirements last
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir \
numpy==1.23.5 \
aiogram==2.25.1 \
jax==0.4.17 \
jaxlib==0.4.17 && \
pip install --no-cache-dir rasa==3.6.20 && \
pip install --no-cache-dir -r requirements.txt
# ── Application code ──────────────────────────────────────────────────────────
COPY --chown=user . .
ENV PYTHONPATH=$HOME/app:$PYTHONPATH
# Ensure Components is a proper Python package
RUN touch Components/__init__.py
# ── Pre-download translation model weights ────────────────────────────────────
# Helsinki-NLP/opus-mt-bn-en is used by Components/translate_to_english.py.
# Baking weights into the image avoids a cold-start download at runtime.
RUN python -c "\
from transformers import MarianMTModel, MarianTokenizer; \
MarianTokenizer.from_pretrained('Helsinki-NLP/opus-mt-bn-en'); \
MarianMTModel.from_pretrained('Helsinki-NLP/opus-mt-bn-en'); \
print('[BUILD] opus-mt-bn-en downloaded.')"
# ── Sanity-check the custom component ────────────────────────────────────────
RUN python -c "\
from Components.multilingual_featurizer import MultilingualFeaturizer; \
print('[BUILD] MultilingualFeaturizer import OK.')"
# ── Train the Rasa model ──────────────────────────────────────────────────────
# --fixed-model-name keeps the artifact name predictable so the CMD can find it.
RUN rasa train --fixed-model-name model
# ── Runtime ───────────────────────────────────────────────────────────────────
EXPOSE 7860
CMD ["rasa", "run", \
"--enable-api", \
"--cors", "*", \
"--port", "7860", \
"--debug"]