product_attribute / Dockerfile
kshitiz14's picture
Update Dockerfile
a77d489 verified
Raw History Blame Contribute Delete
1.51 kB
# Product Attribute Extraction API - Docker image
# Compatible with Hugging Face Docker Spaces (port 7860, non-root user)
# and with plain local `docker run` / docker-compose.
FROM python:3.12-slim
# HF Spaces containers run as a non-root user; create one matching their
# convention (uid 1000) so file permissions work whether this builds on
# HF Spaces or locally.
RUN useradd -m -u 1000 user
WORKDIR /app
# System deps kept minimal; scikit-learn wheels are pure-python/precompiled
# so no build-essential is needed on slim.
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy project
COPY --chown=user data/ ./data/
COPY --chown=user src/ ./src/
COPY --chown=user app.py .
USER user
# Build the labeled dataset and train the model at image build time, so the
# container starts up with a ready-to-serve model.joblib baked in (no
# training step needed at runtime/startup).
RUN cd data && python3 build_dataset.py && cd ../src && python3 train.py
# Hugging Face Docker Spaces require the app to listen on port 7860.
EXPOSE 7860
# Basic container healthcheck against the /health endpoint.
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD python3 -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/health')" || exit 1
# app.py at the repo root is the entrypoint (HF Spaces convention); it
# wires up the extraction pipeline living in src/.
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]