Skip to content

Commit 2b83805

Browse files
committed
feat: Improve browser task isolation and resource management
- Create isolated browser contexts for each task to prevent conflicts - Replace global browser context with task-specific instances - Add proper resource cleanup in finally blocks to prevent memory leaks - Extract hardcoded values as constants for better maintainability - Add comprehensive type hints throughout the codebase - Improve error handling and logging - Reorganize imports and improve code structure - Update Dockerfile to use Playwright's bundled browser instead of custom Chrome - Ensure each task runs in its own isolated environment with unique debugging ports - Fix potential race conditions when multiple tasks access the same context
1 parent 7f5d84c commit 2b83805

File tree

3 files changed

+287
-271
lines changed

3 files changed

+287
-271
lines changed

Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ RUN apt-get update -y && \
1313
# Install Python before the project for caching
1414
RUN uv python install 3.13
1515

16+
1617
WORKDIR /app
1718
RUN --mount=type=cache,target=/root/.cache/uv \
1819
--mount=type=bind,source=uv.lock,target=uv.lock \
@@ -35,8 +36,6 @@ RUN apt-get update && \
3536
tigervnc-tools \
3637
nodejs \
3738
npm \
38-
chromium \
39-
chromium-driver \
4039
fonts-freefont-ttf \
4140
fonts-ipafont-gothic \
4241
fonts-wqy-zenhei \
@@ -56,8 +55,7 @@ COPY --from=builder --chown=app:app /app /app
5655
ENV PATH="/app/.venv/bin:$PATH" \
5756
DISPLAY=:0 \
5857
CHROME_BIN=/usr/bin/chromium \
59-
CHROMIUM_FLAGS="--no-sandbox --headless --disable-gpu --disable-software-rasterizer --disable-dev-shm-usage" \
60-
CHROME_PATH="/usr/bin/chromium"
58+
CHROMIUM_FLAGS="--no-sandbox --headless --disable-gpu --disable-software-rasterizer --disable-dev-shm-usage"
6159

6260
# Combine VNC setup commands to reduce layers
6361
RUN mkdir -p ~/.vnc && \
@@ -69,6 +67,9 @@ RUN mkdir -p ~/.vnc && \
6967
chmod +x /app/boot.sh
7068

7169

70+
RUN playwright install --with-deps --no-shell chromium
71+
72+
7273
EXPOSE 8000
7374

7475
ENTRYPOINT ["/bin/bash", "/app/boot.sh"]

0 commit comments

Comments
 (0)