File size: 1,072 Bytes
3080fd5 6d2ea02 3080fd5 6d2ea02 3080fd5 6d2ea02 3080fd5 6d2ea02 3080fd5 6d2ea02 3080fd5 8f0965e 3080fd5 6d2ea02 3080fd5 6d2ea02 3080fd5 8f0965e 3080fd5 6d2ea02 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# 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"] |