Skip to content

Commit b5550d3

Browse files
authored
Docker: Video recorder/uploader listen on session events (#3070)
* Docker: Video recorder/uploader listen on session events * Handle session events for standalone --------- Signed-off-by: Viet Nguyen Duc <viet.dnguyen@katalon.com>
1 parent a3092ec commit b5550d3

13 files changed

+1118
-6
lines changed

Base/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ RUN ARCH=$(if [ "$(dpkg --print-architecture)" = "amd64" ]; then echo "x86_64";
193193
USER ${SEL_UID}:${SEL_GID}
194194

195195
RUN python3 -m venv $VENV_PATH \
196-
&& $VENV_PATH/bin/python3 -m pip install --upgrade pip psutil requests \
196+
&& $VENV_PATH/bin/python3 -m pip install --upgrade pip psutil requests pyzmq \
197197
&& wget -q https://github.com/Supervisor/supervisor/archive/refs/heads/main.zip -O /tmp/supervisor.zip \
198198
&& unzip /tmp/supervisor.zip -d /tmp \
199199
&& cd /tmp/supervisor-main \

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ test_node_docker: hub standalone_docker standalone_chrome standalone_firefox sta
11151115
echo VIDEO_TAG=$(FFMPEG_TAG_VERSION)-$(BUILD_DATE) >> .env ; \
11161116
echo TEST_DRAIN_AFTER_SESSION_COUNT=$(or $(TEST_DRAIN_AFTER_SESSION_COUNT), 0) >> .env ; \
11171117
echo TEST_PARALLEL_HARDENING=$(or $(TEST_PARALLEL_HARDENING), "false") >> .env ; \
1118-
echo LOG_LEVEL=$(or $(LOG_LEVEL), "INFO") >> .env ; \
1118+
echo LOG_LEVEL=$(or $(LOG_LEVEL), "FINE") >> .env ; \
11191119
echo REQUEST_TIMEOUT=$(or $(REQUEST_TIMEOUT), 300) >> .env ; \
11201120
echo SELENIUM_ENABLE_MANAGED_DOWNLOADS=$(or $(SELENIUM_ENABLE_MANAGED_DOWNLOADS), "false") >> .env ; \
11211121
echo TEST_DELAY_AFTER_TEST=$(or $(TEST_DELAY_AFTER_TEST), 2) >> .env ; \

Standalone/Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ ENV SE_SESSION_REQUEST_TIMEOUT="300" \
2727
SE_RELAX_CHECKS="true" \
2828
SE_REJECT_UNSUPPORTED_CAPS="true" \
2929
SE_OTEL_SERVICE_NAME="selenium-standalone" \
30-
SE_NODE_ENABLE_MANAGED_DOWNLOADS="true"
30+
SE_NODE_ENABLE_MANAGED_DOWNLOADS="true" \
31+
SE_BIND_BUS="false" \
32+
SE_EVENT_BUS_IMPLEMENTATION=""
3133

3234
EXPOSE 4444
35+
EXPOSE 4443
36+
EXPOSE 4442

Standalone/start-selenium-standalone.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ if [ ! -z "${SE_EVENT_BUS_HEARTBEAT_PERIOD}" ]; then
103103
append_se_opts "--eventbus-heartbeat-period" "${SE_EVENT_BUS_HEARTBEAT_PERIOD}"
104104
fi
105105

106+
if [ ! -z "${SE_EVENT_BUS_IMPLEMENTATION}" ]; then
107+
append_se_opts "--events-implementation" "${SE_EVENT_BUS_IMPLEMENTATION}"
108+
fi
109+
110+
if [ "${SE_BIND_BUS}" = "true" ]; then
111+
append_se_opts "--bind-bus" "${SE_BIND_BUS}"
112+
if [ -z "${SE_EVENT_BUS_IMPLEMENTATION}" ]; then
113+
append_se_opts "--events-implementation" "org.openqa.selenium.events.zeromq.ZeroMqEventBus"
114+
fi
115+
fi
116+
106117
if [ "${SE_ENABLE_TLS}" = "true" ]; then
107118
# Configure truststore for the server
108119
if [ ! -z "$SE_JAVA_SSL_TRUST_STORE" ]; then

Video/recorder.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[program:video-recording]
22
priority=10
3-
command=/opt/bin/video.sh
3+
command=python3 /opt/bin/video_recorder.py
44
killasgroup=true
55
autostart=%(ENV_SE_RECORD_VIDEO)s
66
startsecs=0

Video/uploader.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[program:video-upload]
22
priority=5
3-
command=/opt/bin/upload.sh
3+
command=python3 /opt/bin/video_uploader.py
44
killasgroup=true
55
autostart=%(ENV_SE_VIDEO_UPLOAD_ENABLED)s
66
startsecs=0

Video/video_recorder.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Video service entry point that switches between:
4+
1. Unified event-driven service (SE_EVENT_DRIVEN_SERVICES=true)
5+
2. Traditional shell-based polling (SE_EVENT_DRIVEN_SERVICES=false or unset)
6+
7+
When event-driven mode is enabled, this launches a single unified service
8+
that handles both recording and uploading with shared state management.
9+
"""
10+
11+
import os
12+
import subprocess
13+
import sys
14+
15+
16+
def main():
17+
event_driven = os.environ.get("SE_EVENT_DRIVEN_SERVICES", "false").lower() == "true"
18+
19+
if event_driven:
20+
print("Starting unified event-driven video service...")
21+
print("This service handles both recording and uploading with shared state.")
22+
try:
23+
import asyncio
24+
25+
from video_service import main as service_main
26+
27+
asyncio.run(service_main())
28+
except ImportError as e:
29+
print(f"Failed to import video service: {e}")
30+
print("Ensure pyzmq is installed: pip install pyzmq")
31+
print("Falling back to shell-based recording...")
32+
subprocess.run(["/opt/bin/video.sh"], check=True)
33+
else:
34+
print("Starting shell-based video recording...")
35+
subprocess.run(["/opt/bin/video.sh"], check=True)
36+
37+
38+
if __name__ == "__main__":
39+
main()

0 commit comments

Comments
 (0)