Update Dockerfile
Browse files- Dockerfile +26 -82
Dockerfile
CHANGED
|
@@ -1,90 +1,34 @@
|
|
| 1 |
-
|
| 2 |
-
import json
|
| 3 |
-
import os
|
| 4 |
-
import subprocess
|
| 5 |
-
import time
|
| 6 |
-
from aiohttp import web
|
| 7 |
-
from aiortc import RTCPeerConnection, RTCSessionDescription, RTCIceServer, RTCConfiguration
|
| 8 |
|
| 9 |
-
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
|
| 21 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
"""
|
| 28 |
-
try:
|
| 29 |
-
reader, writer = await asyncio.open_connection('127.0.0.1', 4822)
|
| 30 |
|
| 31 |
-
|
| 32 |
-
writer.write(b"6.select,3.x11;")
|
| 33 |
-
await writer.drain()
|
| 34 |
|
| 35 |
-
|
| 36 |
-
# We skip reading them for speed and send our connection string
|
| 37 |
-
# Format: width, height, dpi, etc.
|
| 38 |
-
# 0.,,,0.,,,...;
|
| 39 |
-
connection_args = (
|
| 40 |
-
f"4.size,4.1280,3.720,2.96;" # Res, DPI
|
| 41 |
-
f"5.audio,9.audio/ogg;" # Audio support
|
| 42 |
-
f"5.video,9.video/ogg;" # Video support
|
| 43 |
-
f"7.connect,;" # Final connect
|
| 44 |
-
)
|
| 45 |
-
writer.write(connection_args.encode())
|
| 46 |
-
await writer.drain()
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
while True:
|
| 51 |
-
data = await reader.read(32768)
|
| 52 |
-
if not data: break
|
| 53 |
-
channel.send(data.decode('utf-8', errors='ignore'))
|
| 54 |
|
| 55 |
-
|
| 56 |
-
def on_message(message):
|
| 57 |
-
# Forward input commands (mouse/keys) back to guacd
|
| 58 |
-
writer.write(message.encode())
|
| 59 |
-
|
| 60 |
-
await guac_to_webrtc()
|
| 61 |
-
except Exception as e:
|
| 62 |
-
print(f"Bridge Error: {e}")
|
| 63 |
-
finally:
|
| 64 |
-
writer.close()
|
| 65 |
-
|
| 66 |
-
# --- WebRTC Signaling ---
|
| 67 |
-
|
| 68 |
-
async def offer(request):
|
| 69 |
-
params = await request.json()
|
| 70 |
-
pc = RTCPeerConnection()
|
| 71 |
-
|
| 72 |
-
@pc.on("datachannel")
|
| 73 |
-
def on_dc(channel):
|
| 74 |
-
asyncio.create_task(bridge_x11_commands(channel))
|
| 75 |
-
|
| 76 |
-
await pc.setRemoteDescription(RTCSessionDescription(sdp=params["sdp"], type=params["type"]))
|
| 77 |
-
await pc.setLocalDescription(await pc.createAnswer())
|
| 78 |
-
|
| 79 |
-
return web.Response(
|
| 80 |
-
content_type="application/json",
|
| 81 |
-
text=json.dumps({"sdp": pc.localDescription.sdp, "type": pc.localDescription.type}),
|
| 82 |
-
headers={"Access-Control-Allow-Origin": "*"}
|
| 83 |
-
)
|
| 84 |
-
|
| 85 |
-
if __name__ == "__main__":
|
| 86 |
-
start_backend()
|
| 87 |
-
app = web.Application()
|
| 88 |
-
app.router.add_get("/", lambda r: web.Response(text="hello world"))
|
| 89 |
-
app.router.add_post("/offer", offer)
|
| 90 |
-
web.run_app(app, host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
+
FROM python:3.11-slim-bookworm
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
| 4 |
|
| 5 |
+
# 1. Install guacd (The X11-to-Drawing-Command translator) and Xvfb
|
| 6 |
+
RUN apt-get update && apt-get install -y \
|
| 7 |
+
guacd \
|
| 8 |
+
xvfb \
|
| 9 |
+
wget curl gnupg \
|
| 10 |
+
# Browser Dependencies
|
| 11 |
+
libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libgbm1 \
|
| 12 |
+
libasound2 libpangocairo-1.0-0 libgtk-3-0 fonts-liberation \
|
| 13 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 14 |
|
| 15 |
+
# 2. Install Opera
|
| 16 |
+
RUN curl -fsSL https://deb.opera.com/archive.key | gpg --dearmor -o /usr/share/keyrings/opera-browser-keyring.gpg && \
|
| 17 |
+
echo "deb [signed-by=/usr/share/keyrings/opera-browser-keyring.gpg] https://deb.opera.com/opera-stable/ stable non-free" \
|
| 18 |
+
| tee /etc/apt/sources.list.d/opera-stable.list && \
|
| 19 |
+
apt-get update && \
|
| 20 |
+
apt-get install -y opera-stable
|
| 21 |
|
| 22 |
+
# 3. Setup User
|
| 23 |
+
RUN useradd -m -u 1000 user
|
| 24 |
+
USER user
|
| 25 |
+
WORKDIR /home/user/app
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
RUN pip install aiortc aiohttp
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
COPY --chown=user:user . .
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
ENV DISPLAY=:99
|
| 32 |
+
EXPOSE 7860
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
CMD ["python", "app.py"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|