| 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"] |