PepBielsaBot / Dockerfile
thehnx's picture
feat: add HF Spaces deployment (Dockerfile + /health endpoint for UptimeRobot)
e2c6c50
Raw
History Blame Contribute Delete
2.09 kB
# ─────────────────────────────────────────────────────────────────────────────
# PepBielsa Monitor Bot — Dockerfile for Hugging Face Spaces
# ─────────────────────────────────────────────────────────────────────────────
# HF Spaces runs Docker containers and exposes port 7860 to the web.
# UptimeRobot pings https://<space>.hf.space/health every 5 min to keep it alive.
# ─────────────────────────────────────────────────────────────────────────────
FROM python:3.11-slim
# Prevents Python from writing .pyc files and enables stdout/stderr logging.
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PORT=7860
WORKDIR /app
# Install OS-level dependencies first (cached layer).
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
libffi-dev \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies (cached unless requirements.txt changes).
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application source.
COPY . .
# Create directories the bot writes to at runtime.
RUN mkdir -p temp_media
# HF Spaces runs containers as a non-root user by default.
# Create a dedicated user for security best-practices.
RUN useradd -m -u 1000 botuser \
&& chown -R botuser:botuser /app
USER botuser
# HF Spaces expects the container to listen on port 7860.
EXPOSE 7860
# Health-check so Docker/HF knows the service is alive.
HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/health')" || exit 1
CMD ["python", "main.py"]