Yuvan666 commited on
Commit
a81ead9
·
1 Parent(s): a65c2f7

fix: cloudflared .deb install, noVNC on 0.0.0.0:7860, exact supervisor config

Browse files
Files changed (3) hide show
  1. Dockerfile +7 -7
  2. app.py +8 -26
  3. supervisord.conf +31 -21
Dockerfile CHANGED
@@ -1,5 +1,5 @@
1
  # =============================================================================
2
- # ALTYZEN Stealth Browser Stack - Cloudflare Tunnel Edition
3
  # =============================================================================
4
 
5
  FROM python:3.11-slim
@@ -7,7 +7,7 @@ FROM python:3.11-slim
7
  ENV DEBIAN_FRONTEND=noninteractive
8
  ENV DISPLAY=:99
9
 
10
- # Install system dependencies
11
  RUN apt-get update && apt-get install -y --no-install-recommends \
12
  xvfb \
13
  fluxbox \
@@ -40,11 +40,11 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
40
  fonts-noto-color-emoji \
41
  && rm -rf /var/lib/apt/lists/*
42
 
43
- # Install cloudflared - download with verification
44
- RUN curl -L --output /usr/local/bin/cloudflared \
45
- https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 && \
46
- chmod +x /usr/local/bin/cloudflared && \
47
- /usr/local/bin/cloudflared --version
48
 
49
  # Install noVNC from GitHub
50
  RUN git clone --depth 1 https://github.com/novnc/noVNC.git /opt/novnc && \
 
1
  # =============================================================================
2
+ # ALTYZEN Stealth Browser Stack - Final VNC + Cloudflare Tunnel
3
  # =============================================================================
4
 
5
  FROM python:3.11-slim
 
7
  ENV DEBIAN_FRONTEND=noninteractive
8
  ENV DISPLAY=:99
9
 
10
+ # Install system dependencies including VNC/Xvfb
11
  RUN apt-get update && apt-get install -y --no-install-recommends \
12
  xvfb \
13
  fluxbox \
 
40
  fonts-noto-color-emoji \
41
  && rm -rf /var/lib/apt/lists/*
42
 
43
+ # Install cloudflared using .deb package
44
+ RUN curl -L --output cloudflared.deb https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb && \
45
+ dpkg -i cloudflared.deb && \
46
+ rm cloudflared.deb && \
47
+ cloudflared --version
48
 
49
  # Install noVNC from GitHub
50
  RUN git clone --depth 1 https://github.com/novnc/noVNC.git /opt/novnc && \
app.py CHANGED
@@ -1,8 +1,7 @@
1
  """
2
- Stealth Browser Stack - Persistent Playwright Session
3
- ======================================================
4
- Runs a visible browser on :99 that can be viewed via Cloudflare Tunnel.
5
- The browser stays alive and accepts tasks via API.
6
  """
7
 
8
  import os
@@ -30,7 +29,6 @@ app.add_middleware(
30
  allow_headers=["*"],
31
  )
32
 
33
- # Global browser session (persistent)
34
  browser_session: Optional[BrowserSession] = None
35
 
36
 
@@ -51,13 +49,11 @@ class TaskResponse(BaseModel):
51
 
52
  @app.get("/")
53
  async def root():
54
- """Status endpoint - HF sees this as a normal running app."""
55
  return {
56
  "service": "Stealth Browser Worker",
57
  "status": "running",
58
  "display": os.environ.get("DISPLAY", "NOT SET"),
59
- "tunnel": "cloudflared active",
60
- "access": "Use your Cloudflare subdomain to view the browser"
61
  }
62
 
63
 
@@ -67,28 +63,22 @@ async def health():
67
  "status": "healthy",
68
  "display": os.environ.get("DISPLAY", ":99"),
69
  "browser_active": browser_session is not None and browser_session.is_active,
70
- "timestamp": datetime.now().isoformat(),
71
- "openrouter_key": "SET" if os.getenv("OPENROUTER_API_KEY") else "NOT SET"
72
  }
73
 
74
 
75
  @app.post("/run-task", response_model=TaskResponse)
76
  async def run_task(request: TaskRequest):
77
- """Run a validation task - visible in the VNC stream via Cloudflare."""
78
  global browser_session
79
 
80
  start_time = datetime.now()
81
  logger.info(f"📥 Task: {request.task_id} ({request.task_type})")
82
- logger.info(f"📦 Data: {request.data}")
83
- logger.info("👁️ Watch the browser via your Cloudflare tunnel!")
84
 
85
  try:
86
  if request.task_type in ["validate_order", "validate_email"]:
87
  order_data = {**request.data, "task_id": request.task_id}
88
  result = await validate_order(order_data, browser_session)
89
-
90
  execution_time = int((datetime.now() - start_time).total_seconds() * 1000)
91
- logger.info(f"✅ Task {request.task_id} completed in {execution_time}ms")
92
 
93
  return TaskResponse(
94
  task_id=request.task_id,
@@ -103,12 +93,7 @@ async def run_task(request: TaskRequest):
103
  except Exception as e:
104
  execution_time = int((datetime.now() - start_time).total_seconds() * 1000)
105
  logger.error(f"❌ Task {request.task_id} failed: {e}")
106
- return TaskResponse(
107
- task_id=request.task_id,
108
- status="error",
109
- error=str(e),
110
- execution_time_ms=execution_time
111
- )
112
 
113
 
114
  @app.on_event("startup")
@@ -116,10 +101,7 @@ async def startup():
116
  global browser_session
117
  logger.info("🚀 Stealth Browser Stack starting...")
118
  logger.info(f"📺 Display: {os.environ.get('DISPLAY', ':99')}")
119
- logger.info(f"📍 OpenRouter: {'SET' if os.getenv('OPENROUTER_API_KEY') else 'NOT SET'}")
120
- logger.info(f"🔒 Cloudflare Tunnel: {'TOKEN SET' if os.getenv('CLOUDFLARE_TUNNEL_TOKEN') else 'NOT SET'}")
121
 
122
- # Initialize persistent browser session
123
  try:
124
  browser_session = await BrowserSession.create()
125
  logger.info("✅ Persistent browser session created!")
@@ -127,7 +109,7 @@ async def startup():
127
  logger.error(f"⚠️ Could not create browser session: {e}")
128
  browser_session = None
129
 
130
- logger.info("✅ Worker ready! Access via your Cloudflare subdomain.")
131
 
132
 
133
  @app.on_event("shutdown")
@@ -140,5 +122,5 @@ async def shutdown():
140
 
141
  if __name__ == "__main__":
142
  import uvicorn
143
- # Run on internal port 8000, Cloudflare tunnel exposes noVNC on 6080
144
  uvicorn.run(app, host="0.0.0.0", port=8000)
 
1
  """
2
+ Stealth Browser Stack - FastAPI on 0.0.0.0:7860
3
+ ================================================
4
+ Note: noVNC handles 7860, this is a backup API server on 8000
 
5
  """
6
 
7
  import os
 
29
  allow_headers=["*"],
30
  )
31
 
 
32
  browser_session: Optional[BrowserSession] = None
33
 
34
 
 
49
 
50
  @app.get("/")
51
  async def root():
 
52
  return {
53
  "service": "Stealth Browser Worker",
54
  "status": "running",
55
  "display": os.environ.get("DISPLAY", "NOT SET"),
56
+ "tunnel": "cloudflared active"
 
57
  }
58
 
59
 
 
63
  "status": "healthy",
64
  "display": os.environ.get("DISPLAY", ":99"),
65
  "browser_active": browser_session is not None and browser_session.is_active,
66
+ "timestamp": datetime.now().isoformat()
 
67
  }
68
 
69
 
70
  @app.post("/run-task", response_model=TaskResponse)
71
  async def run_task(request: TaskRequest):
 
72
  global browser_session
73
 
74
  start_time = datetime.now()
75
  logger.info(f"📥 Task: {request.task_id} ({request.task_type})")
 
 
76
 
77
  try:
78
  if request.task_type in ["validate_order", "validate_email"]:
79
  order_data = {**request.data, "task_id": request.task_id}
80
  result = await validate_order(order_data, browser_session)
 
81
  execution_time = int((datetime.now() - start_time).total_seconds() * 1000)
 
82
 
83
  return TaskResponse(
84
  task_id=request.task_id,
 
93
  except Exception as e:
94
  execution_time = int((datetime.now() - start_time).total_seconds() * 1000)
95
  logger.error(f"❌ Task {request.task_id} failed: {e}")
96
+ return TaskResponse(task_id=request.task_id, status="error", error=str(e), execution_time_ms=execution_time)
 
 
 
 
 
97
 
98
 
99
  @app.on_event("startup")
 
101
  global browser_session
102
  logger.info("🚀 Stealth Browser Stack starting...")
103
  logger.info(f"📺 Display: {os.environ.get('DISPLAY', ':99')}")
 
 
104
 
 
105
  try:
106
  browser_session = await BrowserSession.create()
107
  logger.info("✅ Persistent browser session created!")
 
109
  logger.error(f"⚠️ Could not create browser session: {e}")
110
  browser_session = None
111
 
112
+ logger.info("✅ Worker ready!")
113
 
114
 
115
  @app.on_event("shutdown")
 
122
 
123
  if __name__ == "__main__":
124
  import uvicorn
125
+ # Agent runs on port 8000, noVNC handles 7860
126
  uvicorn.run(app, host="0.0.0.0", port=8000)
supervisord.conf CHANGED
@@ -1,6 +1,6 @@
1
  ; =============================================================================
2
- ; Supervisord - Stealth Browser Stack
3
- ; noVNC on 7860, Cloudflare Tunnel bridges to public hostname
4
  ; =============================================================================
5
 
6
  [supervisord]
@@ -17,8 +17,10 @@ user=root
17
  command=/usr/bin/Xvfb :99 -screen 0 1280x720x24 -ac +extension GLX +render -noreset
18
  autorestart=true
19
  priority=100
20
- stdout_logfile=/var/log/supervisor/xvfb.log
21
- stderr_logfile=/var/log/supervisor/xvfb_err.log
 
 
22
 
23
  ; =============================================================================
24
  ; Process 2: Fluxbox - Window Manager
@@ -27,8 +29,10 @@ stderr_logfile=/var/log/supervisor/xvfb_err.log
27
  command=/bin/bash -c "sleep 2 && DISPLAY=:99 /usr/bin/fluxbox"
28
  autorestart=true
29
  priority=200
30
- stdout_logfile=/var/log/supervisor/fluxbox.log
31
- stderr_logfile=/var/log/supervisor/fluxbox_err.log
 
 
32
 
33
  ; =============================================================================
34
  ; Process 3: x11vnc - VNC Server on port 5900
@@ -37,32 +41,36 @@ stderr_logfile=/var/log/supervisor/fluxbox_err.log
37
  command=/bin/bash -c "sleep 3 && /usr/bin/x11vnc -display :99 -forever -shared -nopw -rfbport 5900 -xkb"
38
  autorestart=true
39
  priority=300
40
- stdout_logfile=/var/log/supervisor/x11vnc.log
41
- stderr_logfile=/var/log/supervisor/x11vnc_err.log
 
 
42
 
43
  ; =============================================================================
44
- ; Process 4: noVNC - HTML5 VNC Client on PORT 7860 (HF requires this)
45
  ; =============================================================================
46
  [program:novnc]
47
- command=/bin/bash -c "sleep 5 && /opt/novnc/utils/novnc_proxy --vnc localhost:5900 --listen 7860 --web /opt/novnc"
48
  autorestart=true
49
  priority=400
50
- stdout_logfile=/var/log/supervisor/novnc.log
51
- stderr_logfile=/var/log/supervisor/novnc_err.log
 
 
52
 
53
  ; =============================================================================
54
- ; Process 5: Cloudflare Tunnel - Bridges localhost:7860 to public hostname
55
- ; Token from environment variable CLOUDFLARE_TUNNEL_TOKEN
56
  ; =============================================================================
57
  [program:cloudflared]
58
- command=/bin/bash -c "sleep 8 && /usr/local/bin/cloudflared tunnel --no-autoupdate run --token %(ENV_CLOUDFLARE_TUNNEL_TOKEN)s"
59
  autorestart=true
60
- priority=450
61
- stdout_logfile=/var/log/supervisor/cloudflared.log
62
- stderr_logfile=/var/log/supervisor/cloudflared_err.log
 
63
 
64
  ; =============================================================================
65
- ; Process 6: Python Agent - Browser automation
66
  ; =============================================================================
67
  [program:agent]
68
  command=/bin/bash -c "sleep 12 && DISPLAY=:99 python /app/app.py"
@@ -72,5 +80,7 @@ autorestart=true
72
  priority=500
73
  startretries=10
74
  startsecs=15
75
- stdout_logfile=/var/log/supervisor/agent.log
76
- stderr_logfile=/var/log/supervisor/agent_err.log
 
 
 
1
  ; =============================================================================
2
+ ; Supervisord - VNC Stack + Cloudflare Tunnel
3
+ ; noVNC on 0.0.0.0:7860
4
  ; =============================================================================
5
 
6
  [supervisord]
 
17
  command=/usr/bin/Xvfb :99 -screen 0 1280x720x24 -ac +extension GLX +render -noreset
18
  autorestart=true
19
  priority=100
20
+ stdout_logfile=/dev/stdout
21
+ stdout_logfile_maxbytes=0
22
+ stderr_logfile=/dev/stderr
23
+ stderr_logfile_maxbytes=0
24
 
25
  ; =============================================================================
26
  ; Process 2: Fluxbox - Window Manager
 
29
  command=/bin/bash -c "sleep 2 && DISPLAY=:99 /usr/bin/fluxbox"
30
  autorestart=true
31
  priority=200
32
+ stdout_logfile=/dev/stdout
33
+ stdout_logfile_maxbytes=0
34
+ stderr_logfile=/dev/stderr
35
+ stderr_logfile_maxbytes=0
36
 
37
  ; =============================================================================
38
  ; Process 3: x11vnc - VNC Server on port 5900
 
41
  command=/bin/bash -c "sleep 3 && /usr/bin/x11vnc -display :99 -forever -shared -nopw -rfbport 5900 -xkb"
42
  autorestart=true
43
  priority=300
44
+ stdout_logfile=/dev/stdout
45
+ stdout_logfile_maxbytes=0
46
+ stderr_logfile=/dev/stderr
47
+ stderr_logfile_maxbytes=0
48
 
49
  ; =============================================================================
50
+ ; Process 4: noVNC - HTML5 VNC Client on 0.0.0.0:7860
51
  ; =============================================================================
52
  [program:novnc]
53
+ command=/bin/bash -c "sleep 5 && /opt/novnc/utils/novnc_proxy --vnc localhost:5900 --listen 0.0.0.0:7860 --web /opt/novnc"
54
  autorestart=true
55
  priority=400
56
+ stdout_logfile=/dev/stdout
57
+ stdout_logfile_maxbytes=0
58
+ stderr_logfile=/dev/stderr
59
+ stderr_logfile_maxbytes=0
60
 
61
  ; =============================================================================
62
+ ; Process 5: Cloudflare Tunnel
 
63
  ; =============================================================================
64
  [program:cloudflared]
65
+ command=cloudflared tunnel --no-autoupdate run --token %(ENV_CLOUDFLARE_TUNNEL_TOKEN)s
66
  autorestart=true
67
+ stdout_logfile=/dev/stdout
68
+ stdout_logfile_maxbytes=0
69
+ stderr_logfile=/dev/stderr
70
+ stderr_logfile_maxbytes=0
71
 
72
  ; =============================================================================
73
+ ; Process 6: Python Agent
74
  ; =============================================================================
75
  [program:agent]
76
  command=/bin/bash -c "sleep 12 && DISPLAY=:99 python /app/app.py"
 
80
  priority=500
81
  startretries=10
82
  startsecs=15
83
+ stdout_logfile=/dev/stdout
84
+ stdout_logfile_maxbytes=0
85
+ stderr_logfile=/dev/stderr
86
+ stderr_logfile_maxbytes=0