Spaces:
Paused
Paused
Update Dockerfile
Browse files- Dockerfile +30 -102
Dockerfile
CHANGED
|
@@ -2,22 +2,23 @@ FROM node:18-bullseye-slim
|
|
| 2 |
|
| 3 |
USER root
|
| 4 |
|
| 5 |
-
# 1. Install System
|
| 6 |
-
# We
|
| 7 |
RUN apt-get update && \
|
| 8 |
-
apt-get install -y wget ffmpeg dumb-init
|
| 9 |
apt-get autoremove -y && \
|
| 10 |
rm -rf /var/lib/apt/lists/*
|
| 11 |
|
| 12 |
-
# 2. Setup
|
| 13 |
WORKDIR /stremio
|
|
|
|
| 14 |
RUN mkdir -p /root/.stremio-server
|
| 15 |
|
| 16 |
-
# 3. Download Engine
|
| 17 |
RUN wget https://dl.strem.io/four/v4.4.168/server.js -O server.js
|
| 18 |
RUN wget https://dl.strem.io/four/v4.4.168/stremio.asar -O stremio.asar
|
| 19 |
|
| 20 |
-
# 4. Install Proxy
|
| 21 |
RUN npm install http-proxy
|
| 22 |
|
| 23 |
# 5. Environment Variables
|
|
@@ -26,122 +27,49 @@ ENV CASTING_DISABLED=1
|
|
| 26 |
ENV STREAMING_DISABLED=0
|
| 27 |
ENV PORT=11470
|
| 28 |
|
| 29 |
-
# 6.
|
| 30 |
-
#
|
| 31 |
RUN echo "const http = require('http'); \
|
| 32 |
const httpProxy = require('http-proxy'); \
|
| 33 |
-
const
|
| 34 |
-
const os = require('os'); \
|
| 35 |
-
const fs = require('fs'); \
|
| 36 |
-
\
|
| 37 |
-
// --- STATS ENGINE --- \
|
| 38 |
-
let stats = { \
|
| 39 |
-
current: 0, \
|
| 40 |
-
max: 0, \
|
| 41 |
-
min: 0, \
|
| 42 |
-
avg: 0, \
|
| 43 |
-
totalBytes: 0, \
|
| 44 |
-
samples: 0, \
|
| 45 |
-
startTime: Date.now() \
|
| 46 |
-
}; \
|
| 47 |
-
\
|
| 48 |
-
let lastRx = 0; \
|
| 49 |
-
// Try to read initial network counter \
|
| 50 |
-
try { lastRx = parseInt(fs.readFileSync('/sys/class/net/eth0/statistics/rx_bytes', 'utf8')); } catch(e) {} \
|
| 51 |
-
\
|
| 52 |
-
// Update Stats every second \
|
| 53 |
-
setInterval(() => { \
|
| 54 |
-
try { \
|
| 55 |
-
const currRx = parseInt(fs.readFileSync('/sys/class/net/eth0/statistics/rx_bytes', 'utf8')); \
|
| 56 |
-
const diff = currRx - lastRx; \
|
| 57 |
-
lastRx = currRx; \
|
| 58 |
-
\
|
| 59 |
-
// Convert bytes/sec to Mbps \
|
| 60 |
-
const mbps = (diff * 8) / (1000 * 1000); \
|
| 61 |
-
stats.current = mbps; \
|
| 62 |
-
\
|
| 63 |
-
// Update Max \
|
| 64 |
-
if (mbps > stats.max) stats.max = mbps; \
|
| 65 |
-
\
|
| 66 |
-
// Update Min (Only count active usage > 0.1 Mbps) \
|
| 67 |
-
if (mbps > 0.1) { \
|
| 68 |
-
if (stats.min === 0 || mbps < stats.min) stats.min = mbps; \
|
| 69 |
-
} \
|
| 70 |
-
\
|
| 71 |
-
// Update Avg \
|
| 72 |
-
stats.totalBytes += diff; \
|
| 73 |
-
stats.samples++; \
|
| 74 |
-
// Avg calculation \
|
| 75 |
-
stats.avg = (stats.totalBytes * 8) / stats.samples / 1000000; \
|
| 76 |
-
\
|
| 77 |
-
} catch(e) {} \
|
| 78 |
-
}, 1000); \
|
| 79 |
-
\
|
| 80 |
-
// --- PROXY SERVER --- \
|
| 81 |
-
const proxy = httpProxy.createProxyServer({ changeOrigin: true, xfwd: true }); \
|
| 82 |
const STREMIO_TARGET = 'http://127.0.0.1:11470'; \
|
| 83 |
\
|
| 84 |
-
proxy.on('error', (err, req, res)
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
} \
|
| 89 |
}); \
|
| 90 |
\
|
| 91 |
const server = http.createServer((req, res) => { \
|
| 92 |
-
// Serve Dashboard on Home Page \
|
| 93 |
if (req.url === '/' || req.url === '/health') { \
|
| 94 |
-
let disk = 'Unknown', ram = 'Unknown', uptime = 'Unknown'; \
|
| 95 |
-
try { \
|
| 96 |
-
disk = execSync(\"df -h / | tail -1 | awk '{print \$3 \\\" / \\\" \$2}'\").toString().trim(); \
|
| 97 |
-
ram = execSync(\"free -m | grep Mem | awk '{print \$3 \\\"MB / \\\" \$2 \\\"MB\\\"}'\").toString().trim(); \
|
| 98 |
-
const upSec = os.uptime(); \
|
| 99 |
-
uptime = Math.floor(upSec / 3600) + 'h ' + Math.floor((upSec % 3600) / 60) + 'm'; \
|
| 100 |
-
} catch (e) {} \
|
| 101 |
-
\
|
| 102 |
-
const duration = ((Date.now() - stats.startTime) / 1000 / 60 / 60).toFixed(2); \
|
| 103 |
-
\
|
| 104 |
-
const html = \` \
|
| 105 |
-
<body style='background:#0d1117; color:#3fb950; font-family:monospace; display:flex; flex-direction:column; align-items:center; justify-content:center; height:100vh; margin:0;'> \
|
| 106 |
-
<div style='border: 1px solid #3fb950; padding: 25px; border-radius: 12px; min-width: 320px; box-shadow: 0 0 20px rgba(63, 185, 80, 0.2); background:#161b22;'> \
|
| 107 |
-
<h2 style='margin:0 0 15px 0; text-align:center; border-bottom: 1px solid #30363d; padding-bottom:10px;'>🚀 NETWORK METRICS</h2> \
|
| 108 |
-
\
|
| 109 |
-
<div style='margin-bottom: 20px; text-align:center;'> \
|
| 110 |
-
<div style='font-size: 32px; color:white; font-weight:bold;'>⬇️ \${stats.current.toFixed(2)} Mbps</div> \
|
| 111 |
-
<div style='font-size:12px; color:#8b949e;'>Live Throughput</div> \
|
| 112 |
-
</div> \
|
| 113 |
-
\
|
| 114 |
-
<div style='display:grid; grid-template-columns: 1fr 1fr; gap: 15px; font-size: 13px; color:#c9d1d9; border-top: 1px solid #30363d; padding-top:15px;'> \
|
| 115 |
-
<div>📈 Max: <span style='color:white'>\${stats.max.toFixed(2)}</span> Mbps</div> \
|
| 116 |
-
<div>📉 Min: <span style='color:white'>\${stats.min.toFixed(2)}</span> Mbps</div> \
|
| 117 |
-
<div>📊 Avg: <span style='color:white'>\${stats.avg.toFixed(2)}</span> Mbps</div> \
|
| 118 |
-
<div>⏱️ Run: <span style='color:white'>\${duration}</span> Hrs</div> \
|
| 119 |
-
</div> \
|
| 120 |
-
\
|
| 121 |
-
<div style='margin-top: 20px; border-top: 1px solid #30363d; padding-top: 15px; font-size: 12px; color:#8b949e;'> \
|
| 122 |
-
<p>💾 Disk: \${disk} | 🧠 RAM: \${ram}</p> \
|
| 123 |
-
<p>⚡ Uptime: \${uptime}</p> \
|
| 124 |
-
</div> \
|
| 125 |
-
</div> \
|
| 126 |
-
<script>setTimeout(() => location.reload(), 2000);</script> \
|
| 127 |
-
</body>\`; \
|
| 128 |
res.writeHead(200, { 'Content-Type': 'text/html' }); \
|
| 129 |
-
res.end(
|
| 130 |
} else { \
|
| 131 |
proxy.web(req, res, { target: STREMIO_TARGET }); \
|
| 132 |
} \
|
| 133 |
}); \
|
| 134 |
\
|
| 135 |
server.listen(7860, '0.0.0.0', () => { \
|
| 136 |
-
console.log('
|
|
|
|
|
|
|
|
|
|
| 137 |
});" > /stremio/proxy.js
|
| 138 |
|
| 139 |
-
# 7. Startup Script
|
|
|
|
| 140 |
RUN echo "#!/bin/bash \n\
|
| 141 |
node /stremio/proxy.js & \n\
|
|
|
|
| 142 |
sleep 2 \n\
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
| 144 |
|
|
|
|
| 145 |
EXPOSE 7860
|
|
|
|
|
|
|
| 146 |
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
|
| 147 |
-
CMD ["/stremio/start.sh"]
|
|
|
|
| 2 |
|
| 3 |
USER root
|
| 4 |
|
| 5 |
+
# 1. Install System Dependencies
|
| 6 |
+
# We install ffmpeg (for the engine) and dumb-init (to handle processes properly)
|
| 7 |
RUN apt-get update && \
|
| 8 |
+
apt-get install -y wget ffmpeg dumb-init && \
|
| 9 |
apt-get autoremove -y && \
|
| 10 |
rm -rf /var/lib/apt/lists/*
|
| 11 |
|
| 12 |
+
# 2. Setup Directories
|
| 13 |
WORKDIR /stremio
|
| 14 |
+
# Fix the ENOENT error by pre-creating the config folder
|
| 15 |
RUN mkdir -p /root/.stremio-server
|
| 16 |
|
| 17 |
+
# 3. Download Stremio Engine
|
| 18 |
RUN wget https://dl.strem.io/four/v4.4.168/server.js -O server.js
|
| 19 |
RUN wget https://dl.strem.io/four/v4.4.168/stremio.asar -O stremio.asar
|
| 20 |
|
| 21 |
+
# 4. Install Proxy Dependency
|
| 22 |
RUN npm install http-proxy
|
| 23 |
|
| 24 |
# 5. Environment Variables
|
|
|
|
| 27 |
ENV STREAMING_DISABLED=0
|
| 28 |
ENV PORT=11470
|
| 29 |
|
| 30 |
+
# 6. Create the Proxy Script (The Interface)
|
| 31 |
+
# I added extra logging here so you SEE it start.
|
| 32 |
RUN echo "const http = require('http'); \
|
| 33 |
const httpProxy = require('http-proxy'); \
|
| 34 |
+
const proxy = httpProxy.createProxyServer({}); \
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
const STREMIO_TARGET = 'http://127.0.0.1:11470'; \
|
| 36 |
\
|
| 37 |
+
proxy.on('error', function (err, req, res) { \
|
| 38 |
+
console.error('Proxy Error:', err.message); \
|
| 39 |
+
res.writeHead(500, { 'Content-Type': 'text/plain' }); \
|
| 40 |
+
res.end('Proxy Error: Stremio is booting...'); \
|
|
|
|
| 41 |
}); \
|
| 42 |
\
|
| 43 |
const server = http.createServer((req, res) => { \
|
|
|
|
| 44 |
if (req.url === '/' || req.url === '/health') { \
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
res.writeHead(200, { 'Content-Type': 'text/html' }); \
|
| 46 |
+
res.end('<body style=\"background:black;color:#00ff00;font-family:monospace;display:flex;align-items:center;justify-content:center;height:100vh;\"><h1>✅ STREMIO IS LIVE<br><span style=\"color:white;font-size:12px\">FFMPEG: Detected | Engine: Running</span></h1></body>'); \
|
| 47 |
} else { \
|
| 48 |
proxy.web(req, res, { target: STREMIO_TARGET }); \
|
| 49 |
} \
|
| 50 |
}); \
|
| 51 |
\
|
| 52 |
server.listen(7860, '0.0.0.0', () => { \
|
| 53 |
+
console.log('----------------------------------------'); \
|
| 54 |
+
console.log('✅ PROXY STARTED ON PORT 7860'); \
|
| 55 |
+
console.log('👉 WAITING FOR STREMIO ENGINE...'); \
|
| 56 |
+
console.log('----------------------------------------'); \
|
| 57 |
});" > /stremio/proxy.js
|
| 58 |
|
| 59 |
+
# 7. Create a Robust Startup Script
|
| 60 |
+
# This prints status messages so you don't feel lost.
|
| 61 |
RUN echo "#!/bin/bash \n\
|
| 62 |
node /stremio/proxy.js & \n\
|
| 63 |
+
PID_PROXY=\$! \n\
|
| 64 |
sleep 2 \n\
|
| 65 |
+
echo '🚀 STARTING STREMIO ENGINE...' \n\
|
| 66 |
+
node /stremio/server.js & \n\
|
| 67 |
+
PID_SERVER=\$! \n\
|
| 68 |
+
wait \$PID_SERVER" > /stremio/start.sh && chmod +x /stremio/start.sh
|
| 69 |
|
| 70 |
+
# 8. Expose Port
|
| 71 |
EXPOSE 7860
|
| 72 |
+
|
| 73 |
+
# 9. Run with dumb-init (prevents zombie processes)
|
| 74 |
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
|
| 75 |
+
CMD ["/stremio/start.sh"]
|