Update Dockerfile
Browse files- Dockerfile +104 -14
Dockerfile
CHANGED
|
@@ -9,6 +9,7 @@ RUN apt-get update && apt-get install -y \
|
|
| 9 |
unzip \
|
| 10 |
xvfb \
|
| 11 |
python3 \
|
|
|
|
| 12 |
curl \
|
| 13 |
libgtk-3-0 \
|
| 14 |
libnotify4 \
|
|
@@ -22,6 +23,9 @@ RUN apt-get update && apt-get install -y \
|
|
| 22 |
libasound2 \
|
| 23 |
&& rm -rf /var/lib/apt/lists/*
|
| 24 |
|
|
|
|
|
|
|
|
|
|
| 25 |
# Set working directory
|
| 26 |
WORKDIR /app
|
| 27 |
|
|
@@ -31,12 +35,12 @@ RUN wget -q https://github.com/feelingsurf/viewer/releases/download/2.5.0/Feelin
|
|
| 31 |
rm FeelingSurfViewer-linux-x64-2.5.0.zip && \
|
| 32 |
chmod +x FeelingSurfViewer
|
| 33 |
|
| 34 |
-
# Create status page
|
| 35 |
RUN echo '<!DOCTYPE html>\n\
|
| 36 |
<html>\n\
|
| 37 |
<head>\n\
|
| 38 |
-
<title>FeelingSurf Viewer</title>\n\
|
| 39 |
-
<meta http-equiv="refresh" content="
|
| 40 |
<style>\n\
|
| 41 |
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\
|
| 42 |
.container { background: white; padding: 40px; border-radius: 20px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); max-width: 600px; }\n\
|
|
@@ -46,25 +50,94 @@ RUN echo '<!DOCTYPE html>\n\
|
|
| 46 |
.info { margin-top: 20px; color: #555; line-height: 1.8; }\n\
|
| 47 |
.info strong { color: #333; }\n\
|
| 48 |
.badge { display: inline-block; background: #e7f3ff; color: #0066cc; padding: 4px 12px; border-radius: 12px; font-size: 14px; margin: 5px 5px 5px 0; }\n\
|
|
|
|
|
|
|
|
|
|
| 49 |
</style>\n\
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
</head>\n\
|
| 51 |
<body>\n\
|
| 52 |
<div class="container">\n\
|
| 53 |
<div class="status pulse">✅ FeelingSurf Viewer Active</div>\n\
|
| 54 |
<div class="info">\n\
|
| 55 |
-
<p><strong>Status:</strong> <span class="badge">Running</span></p>\n\
|
| 56 |
<p><strong>User:</strong> alllogin</p>\n\
|
| 57 |
<p><strong>Mode:</strong> Headless Browser</p>\n\
|
| 58 |
<p><strong>Version:</strong> 2.5.0</p>\n\
|
| 59 |
-
<p
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
</div>\n\
|
| 61 |
</div>\n\
|
| 62 |
</body>\n\
|
| 63 |
</html>' > /app/status.html
|
| 64 |
|
| 65 |
-
# Create
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
RUN echo '#!/bin/bash\n\
|
| 67 |
-
echo "Starting FeelingSurf Viewer..."\n\
|
|
|
|
| 68 |
\n\
|
| 69 |
# Get current Hugging Face IP address\n\
|
| 70 |
echo "=== Current Hugging Face Space Information ==="\n\
|
|
@@ -79,30 +152,47 @@ echo "============================================="\n\
|
|
| 79 |
echo ""\n\
|
| 80 |
\n\
|
| 81 |
# Start Xvfb (virtual display)\n\
|
|
|
|
| 82 |
Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &\n\
|
| 83 |
export DISPLAY=:99\n\
|
| 84 |
-
\n\
|
| 85 |
-
# Wait for Xvfb to start\n\
|
| 86 |
sleep 2\n\
|
| 87 |
\n\
|
| 88 |
# Start FeelingSurf in background\n\
|
|
|
|
| 89 |
cd /app\n\
|
| 90 |
./FeelingSurfViewer --access-token d6e659ba6b59c9866fba8ff01bc56e04 --no-sandbox 2>&1 | tee /tmp/viewer.log &\n\
|
| 91 |
-
\n\
|
| 92 |
-
# Wait for viewer to initialize\n\
|
| 93 |
sleep 5\n\
|
| 94 |
\n\
|
| 95 |
-
# Start
|
| 96 |
-
echo "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
echo ""\n\
|
| 98 |
echo "=== FeelingSurf Viewer Logs ==="\n\
|
| 99 |
tail -f /tmp/viewer.log &\n\
|
| 100 |
-
|
|
|
|
|
|
|
| 101 |
chmod +x /app/start.sh
|
| 102 |
|
| 103 |
# Set environment
|
| 104 |
ENV access_token="d6e659ba6b59c9866fba8ff01bc56e04"
|
| 105 |
ENV DISPLAY=:99
|
|
|
|
| 106 |
|
| 107 |
EXPOSE 7860
|
| 108 |
|
|
|
|
| 9 |
unzip \
|
| 10 |
xvfb \
|
| 11 |
python3 \
|
| 12 |
+
python3-pip \
|
| 13 |
curl \
|
| 14 |
libgtk-3-0 \
|
| 15 |
libnotify4 \
|
|
|
|
| 23 |
libasound2 \
|
| 24 |
&& rm -rf /var/lib/apt/lists/*
|
| 25 |
|
| 26 |
+
# Install Python packages for keep-alive
|
| 27 |
+
RUN pip3 install flask requests APScheduler
|
| 28 |
+
|
| 29 |
# Set working directory
|
| 30 |
WORKDIR /app
|
| 31 |
|
|
|
|
| 35 |
rm FeelingSurfViewer-linux-x64-2.5.0.zip && \
|
| 36 |
chmod +x FeelingSurfViewer
|
| 37 |
|
| 38 |
+
# Create enhanced status page with auto-refresh and activity
|
| 39 |
RUN echo '<!DOCTYPE html>\n\
|
| 40 |
<html>\n\
|
| 41 |
<head>\n\
|
| 42 |
+
<title>FeelingSurf Viewer - Always Active</title>\n\
|
| 43 |
+
<meta http-equiv="refresh" content="5">\n\
|
| 44 |
<style>\n\
|
| 45 |
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\
|
| 46 |
.container { background: white; padding: 40px; border-radius: 20px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); max-width: 600px; }\n\
|
|
|
|
| 50 |
.info { margin-top: 20px; color: #555; line-height: 1.8; }\n\
|
| 51 |
.info strong { color: #333; }\n\
|
| 52 |
.badge { display: inline-block; background: #e7f3ff; color: #0066cc; padding: 4px 12px; border-radius: 12px; font-size: 14px; margin: 5px 5px 5px 0; }\n\
|
| 53 |
+
.heartbeat { background: #dcfce7; color: #16a34a; }\n\
|
| 54 |
+
.activity { background: #f3f4f6; padding: 15px; border-radius: 10px; margin-top: 20px; font-size: 14px; }\n\
|
| 55 |
+
.timestamp { color: #888; font-size: 12px; }\n\
|
| 56 |
</style>\n\
|
| 57 |
+
<script>\n\
|
| 58 |
+
// Keep-alive ping every 30 seconds\n\
|
| 59 |
+
setInterval(() => {\n\
|
| 60 |
+
fetch("/ping").catch(() => {});\n\
|
| 61 |
+
}, 30000);\n\
|
| 62 |
+
\n\
|
| 63 |
+
// Update timestamp\n\
|
| 64 |
+
setInterval(() => {\n\
|
| 65 |
+
document.getElementById("time").textContent = new Date().toLocaleTimeString();\n\
|
| 66 |
+
}, 1000);\n\
|
| 67 |
+
</script>\n\
|
| 68 |
</head>\n\
|
| 69 |
<body>\n\
|
| 70 |
<div class="container">\n\
|
| 71 |
<div class="status pulse">✅ FeelingSurf Viewer Active</div>\n\
|
| 72 |
<div class="info">\n\
|
| 73 |
+
<p><strong>Status:</strong> <span class="badge heartbeat">🟢 Always Running</span></p>\n\
|
| 74 |
<p><strong>User:</strong> alllogin</p>\n\
|
| 75 |
<p><strong>Mode:</strong> Headless Browser</p>\n\
|
| 76 |
<p><strong>Version:</strong> 2.5.0</p>\n\
|
| 77 |
+
<p><strong>Last Activity:</strong> <span id="time" class="timestamp"></span></p>\n\
|
| 78 |
+
<div class="activity">\n\
|
| 79 |
+
<strong>🛡️ Anti-Sleep Features:</strong><br>\n\
|
| 80 |
+
• Auto-refresh every 5 seconds<br>\n\
|
| 81 |
+
• Background keep-alive pings<br>\n\
|
| 82 |
+
• Continuous activity logging<br>\n\
|
| 83 |
+
• Self-ping mechanism active\n\
|
| 84 |
+
</div>\n\
|
| 85 |
</div>\n\
|
| 86 |
</div>\n\
|
| 87 |
</body>\n\
|
| 88 |
</html>' > /app/status.html
|
| 89 |
|
| 90 |
+
# Create Flask keep-alive server
|
| 91 |
+
RUN echo 'from flask import Flask, send_file\n\
|
| 92 |
+
from apscheduler.schedulers.background import BackgroundScheduler\n\
|
| 93 |
+
import requests\n\
|
| 94 |
+
import os\n\
|
| 95 |
+
import logging\n\
|
| 96 |
+
from datetime import datetime\n\
|
| 97 |
+
\n\
|
| 98 |
+
app = Flask(__name__)\n\
|
| 99 |
+
logging.basicConfig(level=logging.INFO)\n\
|
| 100 |
+
\n\
|
| 101 |
+
# Store last activity time\n\
|
| 102 |
+
last_activity = datetime.now()\n\
|
| 103 |
+
\n\
|
| 104 |
+
@app.route("/")\n\
|
| 105 |
+
def index():\n\
|
| 106 |
+
global last_activity\n\
|
| 107 |
+
last_activity = datetime.now()\n\
|
| 108 |
+
return send_file("/app/status.html")\n\
|
| 109 |
+
\n\
|
| 110 |
+
@app.route("/ping")\n\
|
| 111 |
+
def ping():\n\
|
| 112 |
+
global last_activity\n\
|
| 113 |
+
last_activity = datetime.now()\n\
|
| 114 |
+
return {"status": "alive", "time": str(last_activity)}\n\
|
| 115 |
+
\n\
|
| 116 |
+
@app.route("/health")\n\
|
| 117 |
+
def health():\n\
|
| 118 |
+
return {"status": "healthy", "last_activity": str(last_activity)}\n\
|
| 119 |
+
\n\
|
| 120 |
+
# Self-ping function to prevent sleep\n\
|
| 121 |
+
def self_ping():\n\
|
| 122 |
+
try:\n\
|
| 123 |
+
# Ping self\n\
|
| 124 |
+
requests.get("http://localhost:7860/ping", timeout=5)\n\
|
| 125 |
+
app.logger.info(f"[Keep-Alive] Self-ping successful at {datetime.now()}")\n\
|
| 126 |
+
except Exception as e:\n\
|
| 127 |
+
app.logger.error(f"[Keep-Alive] Self-ping failed: {e}")\n\
|
| 128 |
+
\n\
|
| 129 |
+
# Schedule self-ping every 2 minutes\n\
|
| 130 |
+
scheduler = BackgroundScheduler()\n\
|
| 131 |
+
scheduler.add_job(func=self_ping, trigger="interval", seconds=120)\n\
|
| 132 |
+
scheduler.start()\n\
|
| 133 |
+
\n\
|
| 134 |
+
if __name__ == "__main__":\n\
|
| 135 |
+
app.run(host="0.0.0.0", port=7860)' > /app/keep_alive_server.py
|
| 136 |
+
|
| 137 |
+
# Create startup script with enhanced monitoring
|
| 138 |
RUN echo '#!/bin/bash\n\
|
| 139 |
+
echo "��� Starting FeelingSurf Viewer with Anti-Sleep Protection..."\n\
|
| 140 |
+
echo "================================================"\n\
|
| 141 |
\n\
|
| 142 |
# Get current Hugging Face IP address\n\
|
| 143 |
echo "=== Current Hugging Face Space Information ==="\n\
|
|
|
|
| 152 |
echo ""\n\
|
| 153 |
\n\
|
| 154 |
# Start Xvfb (virtual display)\n\
|
| 155 |
+
echo "🖥️ Starting virtual display..."\n\
|
| 156 |
Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &\n\
|
| 157 |
export DISPLAY=:99\n\
|
|
|
|
|
|
|
| 158 |
sleep 2\n\
|
| 159 |
\n\
|
| 160 |
# Start FeelingSurf in background\n\
|
| 161 |
+
echo "🌊 Starting FeelingSurf Viewer..."\n\
|
| 162 |
cd /app\n\
|
| 163 |
./FeelingSurfViewer --access-token d6e659ba6b59c9866fba8ff01bc56e04 --no-sandbox 2>&1 | tee /tmp/viewer.log &\n\
|
|
|
|
|
|
|
| 164 |
sleep 5\n\
|
| 165 |
\n\
|
| 166 |
+
# Start activity monitor\n\
|
| 167 |
+
echo "📊 Starting activity monitor..."\n\
|
| 168 |
+
(\n\
|
| 169 |
+
while true; do\n\
|
| 170 |
+
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\
|
| 171 |
+
sleep 300 # Log every 5 minutes\n\
|
| 172 |
+
done\n\
|
| 173 |
+
) &\n\
|
| 174 |
+
\n\
|
| 175 |
+
# Start Flask keep-alive server\n\
|
| 176 |
+
echo "🛡️ Starting Flask keep-alive server on port 7860..."\n\
|
| 177 |
+
echo ""\n\
|
| 178 |
+
echo "=== Anti-Sleep Protection Active ==="\n\
|
| 179 |
+
echo "✓ Auto-refresh enabled"\n\
|
| 180 |
+
echo "✓ Self-ping every 2 minutes"\n\
|
| 181 |
+
echo "✓ Activity logging enabled"\n\
|
| 182 |
+
echo "✓ Health monitoring active"\n\
|
| 183 |
+
echo "==================================="\n\
|
| 184 |
echo ""\n\
|
| 185 |
echo "=== FeelingSurf Viewer Logs ==="\n\
|
| 186 |
tail -f /tmp/viewer.log &\n\
|
| 187 |
+
\n\
|
| 188 |
+
# Start Flask server (this keeps the container running)\n\
|
| 189 |
+
python3 /app/keep_alive_server.py' > /app/start.sh && \
|
| 190 |
chmod +x /app/start.sh
|
| 191 |
|
| 192 |
# Set environment
|
| 193 |
ENV access_token="d6e659ba6b59c9866fba8ff01bc56e04"
|
| 194 |
ENV DISPLAY=:99
|
| 195 |
+
ENV PYTHONUNBUFFERED=1
|
| 196 |
|
| 197 |
EXPOSE 7860
|
| 198 |
|