Brave-Haven / Dockerfile
Osama-Ahmed-27's picture
Update Dockerfile
ef6e60a verified
# syntax=docker/dockerfile:1
FROM python:3.11-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on
# System deps (build tools for many HF/ML wheels)
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY requirements.txt .
RUN python -m pip install --upgrade pip && pip install -r requirements.txt
# (Optional) Pre-pull small HF models to reduce cold starts (edit/remove as needed)
# RUN python - <<'PY'
# from transformers import AutoTokenizer, AutoModel
# AutoTokenizer.from_pretrained("distilbert-base-uncased")
# AutoModel.from_pretrained("distilbert-base-uncased")
# PY
COPY . .
# Cloud Run injects $PORT; default to 8080 locally
ENV PORT=8080
EXPOSE 8080
# Gunicorn + UvicornWorker is a solid production default for ASGI
ENV WEB_CONCURRENCY=1
CMD exec gunicorn -k uvicorn.workers.UvicornWorker -w ${WEB_CONCURRENCY} -b 0.0.0.0:${PORT} app:app
#
# Lightweight Python image
# FROM python:3.10-slim
# # -----------------------------
# # System dependencies
# # -----------------------------
# RUN apt-get update && apt-get install -y --no-install-recommends \
# ffmpeg git build-essential libsndfile1 \
# && rm -rf /var/lib/apt/lists/*
# # # -----------------------------
# # # Hugging Face & cache setup (writeable dirs)
# # # -----------------------------
# # RUN mkdir -p /data/nltk_data \
# # /data/huggingface/transformers \
# # /data/huggingface/datasets \
# # /data/tmp && chmod -R 777 /data
# # ENV NLTK_DATA=/data/nltk_data
# # ENV HF_HOME=/data/huggingface
# # ENV TRANSFORMERS_CACHE=/data/huggingface/transformers
# # ENV HF_DATASETS_CACHE=/data/huggingface/datasets
# # ENV TMPDIR=/data/tmp
# # -----------------------------
# # Python deps
# # -----------------------------
# WORKDIR /app
# COPY requirements.txt .
# RUN pip install --no-cache-dir -r requirements.txt
# # -----------------------------
# # Copy app
# # -----------------------------
# COPY app.py .
# # Hugging Face Spaces expects the service on port 7860
# ENV PORT=7860
# # -----------------------------
# # Start FastAPI with Uvicorn
# # -----------------------------
# CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]