| 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 '<!DOCTYPE html>\n\ |
| <html>\n\ |
| <head>\n\ |
| <title>FeelingSurf Viewer - Always Active</title>\n\ |
| <meta http-equiv="refresh" content="5">\n\ |
| <style>\n\ |
| body { font-family: system-ui; margin: 0; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); min-height: 100vh; display: flex; align-items: center; justify-content: center; }\n\ |
| .container { background: white; padding: 40px; border-radius: 20px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); max-width: 600px; }\n\ |
| .status { color: #28a745; font-size: 32px; font-weight: bold; margin-bottom: 20px; }\n\ |
| .pulse { animation: pulse 2s infinite; }\n\ |
| @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }\n\ |
| .info { margin-top: 20px; color: #555; line-height: 1.8; }\n\ |
| .info strong { color: #333; }\n\ |
| .badge { display: inline-block; background: #e7f3ff; color: #0066cc; padding: 4px 12px; border-radius: 12px; font-size: 14px; margin: 5px 5px 5px 0; }\n\ |
| .heartbeat { background: #dcfce7; color: #16a34a; }\n\ |
| .activity { background: #f3f4f6; padding: 15px; border-radius: 10px; margin-top: 20px; font-size: 14px; }\n\ |
| .timestamp { color: #888; font-size: 12px; }\n\ |
| </style>\n\ |
| <script>\n\ |
| |
| setInterval(() => {\n\ |
| fetch("/ping").catch(() => {});\n\ |
| }, 30000);\n\ |
| \n\ |
| |
| setInterval(() => {\n\ |
| document.getElementById("time").textContent = new Date().toLocaleTimeString();\n\ |
| }, 1000);\n\ |
| </script>\n\ |
| </head>\n\ |
| <body>\n\ |
| <div class="container">\n\ |
| <div class="status pulse">β
FeelingSurf Viewer Active</div>\n\ |
| <div class="info">\n\ |
| <p><strong>Status:</strong> <span class="badge heartbeat">π’ Always Running</span></p>\n\ |
| <p><strong>User:</strong> alllogin</p>\n\ |
| <p><strong>Mode:</strong> Headless Browser</p>\n\ |
| <p><strong>Version:</strong> 2.5.0</p>\n\ |
| <p><strong>Last Activity:</strong> <span id="time" class="timestamp"></span></p>\n\ |
| <div class="activity">\n\ |
| <strong>π‘οΈ Anti-Sleep Features:</strong><br>\n\ |
| β’ Auto-refresh every 5 seconds<br>\n\ |
| β’ Background keep-alive pings<br>\n\ |
| β’ Continuous activity logging<br>\n\ |
| β’ Self-ping mechanism active\n\ |
| </div>\n\ |
| </div>\n\ |
| </div>\n\ |
| </body>\n\ |
| </html>' > /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"] |