-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
64 lines (53 loc) · 1.85 KB
/
docker-entrypoint.sh
File metadata and controls
64 lines (53 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
set -e
XVFB_ENABLED="${BROWSER_XVFB_ENABLED:-false}"
XVFB_DISPLAY="${BROWSER_XVFB_DISPLAY:-:99}"
XVFB_SCREEN="${BROWSER_XVFB_SCREEN_RESOLUTION:-1920x1080x24}"
wait_for_xvfb() {
local max_attempts=10
local attempt=0
while [ $attempt -lt $max_attempts ]; do
if xdpyinfo -display "$XVFB_DISPLAY" >/dev/null 2>&1; then
echo "Xvfb is ready on display $XVFB_DISPLAY"
return 0
fi
attempt=$((attempt + 1))
sleep 0.5
done
echo "Warning: Xvfb failed to start within timeout"
return 1
}
if [ "$XVFB_ENABLED" = "true" ]; then
echo "Starting Xvfb on display $XVFB_DISPLAY with screen resolution $XVFB_SCREEN"
DISPLAY_NUM=$(echo "$XVFB_DISPLAY" | sed 's/://g')
LOCK_FILE="/tmp/.X${DISPLAY_NUM}-lock"
if [ -f "$LOCK_FILE" ]; then
echo "Removing stale lock file: $LOCK_FILE"
rm -f "$LOCK_FILE"
fi
if [ "${BROWSER_XVFB_ALLOW_TCP:-false}" = "true" ]; then
echo "Starting Xvfb with TCP listening enabled (for VNC)"
Xvfb "$XVFB_DISPLAY" -screen 0 "$XVFB_SCREEN" -listen tcp -ac &
else
echo "Starting Xvfb with TCP disabled (secure mode)"
Xvfb "$XVFB_DISPLAY" -screen 0 "$XVFB_SCREEN" -nolisten tcp &
fi
XVFB_PID=$!
if wait_for_xvfb; then
export DISPLAY="$XVFB_DISPLAY"
echo "Xvfb started successfully (PID: $XVFB_PID)"
else
echo "Error: Xvfb failed to start properly"
kill "$XVFB_PID" 2>/dev/null || true
exit 1
fi
trap "echo 'Stopping Xvfb...'; kill $XVFB_PID 2>/dev/null || true" EXIT
else
echo "Xvfb disabled, using native headless mode"
fi
echo "Browser configuration:"
echo " Engine: ${BROWSER_ENGINE:-chromium}"
echo " Headless: ${BROWSER_HEADLESS:-true}"
echo " Stealth Mode: ${BROWSER_STEALTH_MODE:-false}"
echo " Xvfb Enabled: $XVFB_ENABLED"
exec ./main