FROM ubuntu:22.04
# Prevent interactive prompts
ENV DEBIAN_FRONTEND=noninteractive
# Install dependencies
RUN apt-get update && apt-get install -y \
wget \
unzip \
xvfb \
python3 \
python3-pip \
curl \
libgtk-3-0 \
libnotify4 \
libnss3 \
libxss1 \
libxtst6 \
xdg-utils \
libatspi2.0-0 \
libdrm2 \
libgbm1 \
libasound2 \
&& rm -rf /var/lib/apt/lists/*
# Install Python packages for keep-alive
RUN pip3 install flask requests APScheduler
# Set working directory
WORKDIR /app
# Download and extract FeelingSurf (use x64 version for Hugging Face)
RUN wget -q https://github.com/feelingsurf/viewer/releases/download/2.5.0/FeelingSurfViewer-linux-x64-2.5.0.zip && \
unzip -q FeelingSurfViewer-linux-x64-2.5.0.zip && \
rm FeelingSurfViewer-linux-x64-2.5.0.zip && \
chmod +x FeelingSurfViewer
# Create enhanced status page with auto-refresh and activity
RUN echo '\n\
\n\
\n\
FeelingSurf Viewer - Always Active\n\
\n\
\n\
\n\
\n\
\n\
\n\
✅ FeelingSurf Viewer Active
\n\
\n\
Status: 🟢 Always Running
\n\
User: alllogin
\n\
Mode: Headless Browser
\n\
Version: 2.5.0
\n\
Last Activity:
\n\
\n\
🛡️ Anti-Sleep Features:
\n\
• Auto-refresh every 5 seconds
\n\
• Background keep-alive pings
\n\
• Continuous activity logging
\n\
• Self-ping mechanism active\n\
\n\
\n\
\n\
\n\
' > /app/status.html
# Create Flask keep-alive server
RUN echo 'from flask import Flask, send_file\n\
from apscheduler.schedulers.background import BackgroundScheduler\n\
import requests\n\
import os\n\
import logging\n\
from datetime import datetime\n\
\n\
app = Flask(__name__)\n\
logging.basicConfig(level=logging.INFO)\n\
\n\
# Store last activity time\n\
last_activity = datetime.now()\n\
\n\
@app.route("/")\n\
def index():\n\
global last_activity\n\
last_activity = datetime.now()\n\
return send_file("/app/status.html")\n\
\n\
@app.route("/ping")\n\
def ping():\n\
global last_activity\n\
last_activity = datetime.now()\n\
return {"status": "alive", "time": str(last_activity)}\n\
\n\
@app.route("/health")\n\
def health():\n\
return {"status": "healthy", "last_activity": str(last_activity)}\n\
\n\
# Self-ping function to prevent sleep\n\
def self_ping():\n\
try:\n\
# Ping self\n\
requests.get("http://localhost:7860/ping", timeout=5)\n\
app.logger.info(f"[Keep-Alive] Self-ping successful at {datetime.now()}")\n\
except Exception as e:\n\
app.logger.error(f"[Keep-Alive] Self-ping failed: {e}")\n\
\n\
# Schedule self-ping every 2 minutes\n\
scheduler = BackgroundScheduler()\n\
scheduler.add_job(func=self_ping, trigger="interval", seconds=120)\n\
scheduler.start()\n\
\n\
if __name__ == "__main__":\n\
app.run(host="0.0.0.0", port=7860)' > /app/keep_alive_server.py
# Create startup script with enhanced monitoring
RUN echo '#!/bin/bash\n\
echo "🚀 Starting FeelingSurf Viewer with Anti-Sleep Protection..."\n\
echo "================================================"\n\
\n\
# Get current Hugging Face IP address\n\
echo "=== Current Hugging Face Space Information ==="\n\
CURRENT_IP=$(curl -s -H "Accept: application/json" https://api.ipify.org?format=json | grep -oE "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}")\n\
if [ -n "$CURRENT_IP" ]; then\n\
echo "🌐 Current Public IP: $CURRENT_IP"\n\
echo "📍 Hugging Face Space IP: $CURRENT_IP"\n\
else\n\
echo "⚠️ Could not determine current IP address"\n\
fi\n\
echo "============================================="\n\
echo ""\n\
\n\
# Start Xvfb (virtual display)\n\
echo "🖥️ Starting virtual display..."\n\
Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &\n\
export DISPLAY=:99\n\
sleep 2\n\
\n\
# Start FeelingSurf in background\n\
echo "🌊 Starting FeelingSurf Viewer..."\n\
cd /app\n\
./FeelingSurfViewer --access-token d6e659ba6b59c9866fba8ff01bc56e04 --no-sandbox 2>&1 | tee /tmp/viewer.log &\n\
sleep 5\n\
\n\
# Start activity monitor\n\
echo "📊 Starting activity monitor..."\n\
(\n\
while true; do\n\
echo "[$(date)] ✓ System active - Memory: $(free -h | grep Mem | awk '\''{print $3}'\'' ) CPU Load: $(uptime | awk -F'\''load average:'\'' '\''{ print $2 }'\'' | cut -d, -f1)"\n\
sleep 300 # Log every 5 minutes\n\
done\n\
) &\n\
\n\
# Start Flask keep-alive server\n\
echo "🛡️ Starting Flask keep-alive server on port 7860..."\n\
echo ""\n\
echo "=== Anti-Sleep Protection Active ==="\n\
echo "✓ Auto-refresh enabled"\n\
echo "✓ Self-ping every 2 minutes"\n\
echo "✓ Activity logging enabled"\n\
echo "✓ Health monitoring active"\n\
echo "==================================="\n\
echo ""\n\
echo "=== FeelingSurf Viewer Logs ==="\n\
tail -f /tmp/viewer.log &\n\
\n\
# Start Flask server (this keeps the container running)\n\
python3 /app/keep_alive_server.py' > /app/start.sh && \
chmod +x /app/start.sh
# Set environment
ENV access_token="d6e659ba6b59c9866fba8ff01bc56e04"
ENV DISPLAY=:99
ENV PYTHONUNBUFFERED=1
EXPOSE 7860
CMD ["/app/start.sh"]