# 1. Base Image | |
FROM python:3.10-slim | |
# 2. Set up a non-root user | |
RUN useradd -m -u 1000 user | |
USER user | |
# 3. Set Environment Variables & Working Directory | |
ENV HOME=/home/user | |
ENV PATH=$HOME/.local/bin:$PATH | |
WORKDIR $HOME/app | |
# 4. Copy requirements first for better Docker layer caching | |
COPY --chown=user requirements.txt . | |
# 5. Install Python dependencies for the non-root user | |
RUN pip install --no-cache-dir --user -r requirements.txt | |
# 6. Download the model during the build process | |
# Ini memastikan model sudah ada di dalam image dan tidak diunduh setiap kali Space startup | |
RUN huggingface-cli download Dnfs/gema-4b-indra10k-model1-Q4_K_M-GGUF \ | |
--local-dir ./model \ | |
--local-dir-use-symlinks False | |
# 7. Copy the rest of the application code | |
COPY --chown=user app.py . | |
# 8. Expose the port the app runs on | |
EXPOSE 8000 | |
# 9. Health check to ensure the app is running | |
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ | |
CMD curl -f http://localhost:8000/health || exit 1 | |
# 10. Command to run the application | |
CMD ["python", "app.py"] |