MorphGuard / Dockerfile
juanquy's picture
fix: restrict Setup navigation to admin and enable access-log output on HF Spaces
f75d026
Raw
History Blame Contribute Delete
2.69 kB
# MorphGuard – HuggingFace Spaces Dockerfile
# Runs the full Flask app on port 7860 (HF Spaces proxy port)
FROM python:3.12-slim
# --------------------------------------------------------------------------- #
# Environment
# --------------------------------------------------------------------------- #
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
DEBIAN_FRONTEND=noninteractive \
PIP_BREAK_SYSTEM_PACKAGES=1 \
MorphGuard_HOME=/app \
FLASK_ENV=production \
# Tell the app to skip PostgreSQL / Ethereum / drone features on HF Spaces
HF_SPACE=1
# --------------------------------------------------------------------------- #
# System dependencies (OpenCV-headless needs libglib; ffmpeg for video utils)
# --------------------------------------------------------------------------- #
WORKDIR $MorphGuard_HOME
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
ffmpeg \
libglib2.0-0 \
libsm6 \
libxext6 \
git \
curl \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# --------------------------------------------------------------------------- #
# Python dependencies (HF-safe subset only)
# --------------------------------------------------------------------------- #
RUN pip install --no-cache-dir --upgrade pip
COPY requirements-hf.txt .
RUN pip install --no-cache-dir -r requirements-hf.txt
# --------------------------------------------------------------------------- #
# Application code
# --------------------------------------------------------------------------- #
COPY . .
RUN chown -R 1000:1000 /app
# --------------------------------------------------------------------------- #
# Download model weights at build time so the container starts instantly.
# HF_TOKEN must be set as a Space Secret in the HF Space settings.
# --------------------------------------------------------------------------- #
RUN --mount=type=secret,id=HF_TOKEN \
HF_TOKEN=$(cat /run/secrets/HF_TOKEN 2>/dev/null || echo "") \
python download_models.py || echo "WARNING: model download failed – app will start in fallback mode"
# --------------------------------------------------------------------------- #
# Runtime directories
# --------------------------------------------------------------------------- #
RUN mkdir -p logs static/uploads && chmod -R 777 logs static/uploads
# HuggingFace Spaces routes external traffic to port 7860
EXPOSE 7860
# Use sync workers – no eventlet/gevent needed on HF Spaces
# 1 worker keeps memory low on the free CPU tier
CMD ["gunicorn", "--workers", "1", "--timeout", "120", "--bind", "0.0.0.0:7860", "--access-logfile", "-", "app:app"]