Skip to content

Commit 14291fa

Browse files
author
nightcityblade
committed
fix(docker): keep browser setup in one layer
1 parent 29bae06 commit 14291fa

2 files changed

Lines changed: 21 additions & 17 deletions

File tree

Dockerfile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,15 @@ RUN pip install --no-cache-dir --upgrade pip && \
173173
python -c "import crawl4ai; print('✅ crawl4ai is ready to rock!')" && \
174174
python -c "from playwright.sync_api import sync_playwright; print('✅ Playwright is feeling dramatic!')"
175175

176-
RUN crawl4ai-setup
177-
178-
RUN playwright install --with-deps \
176+
RUN crawl4ai-setup \
177+
&& playwright install --with-deps chromium \
178+
&& crawl4ai-doctor \
179179
&& mkdir -p /home/appuser/.cache/ms-playwright \
180180
&& cp -r /root/.cache/ms-playwright/chromium-* \
181181
/root/.cache/ms-playwright/chromium_headless_shell-* \
182182
/home/appuser/.cache/ms-playwright/ \
183183
&& chown -R appuser:appuser /home/appuser/.cache/ms-playwright \
184-
&& rm -rf /root/.cache/ms-playwright
185-
186-
RUN crawl4ai-doctor \
184+
&& rm -rf /root/.cache/ms-playwright \
187185
&& find "${APP_HOME}" -maxdepth 1 -type f -name '*.core' -delete
188186

189187
# Ensure all cache directories belong to appuser

deploy/docker/tests/test_security_container_posture.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,25 @@ def test_playwright_headless_shell_is_copied_to_runtime_cache(self, dockerfile):
7474
assert "chromium_headless_shell-*" in cache_copy.group("artifacts")
7575

7676
def test_build_artifacts_removed_before_layer_commit(self, dockerfile):
77-
for command, cleanup in (
78-
("playwright install --with-deps", "rm -rf /root/.cache/ms-playwright"),
79-
("crawl4ai-doctor", "-name '*.core' -delete"),
77+
layer = re.search(
78+
r"^RUN crawl4ai-setup(?P<body>(?:(?!^[A-Z]+\s).)*)",
79+
dockerfile,
80+
re.MULTILINE | re.DOTALL,
81+
)
82+
assert layer, "Dockerfile must run crawl4ai-setup"
83+
positions = []
84+
for command in (
85+
"playwright install --with-deps chromium",
86+
"crawl4ai-doctor",
87+
"cp -r /root/.cache/ms-playwright/chromium-*",
88+
"rm -rf /root/.cache/ms-playwright",
89+
"-name '*.core' -delete",
8090
):
81-
layer = re.search(
82-
rf"^RUN {re.escape(command)}(?P<body>(?:(?!^[A-Z]+\s).)*)",
83-
dockerfile,
84-
re.MULTILINE | re.DOTALL,
85-
)
86-
assert layer, f"Dockerfile must run {command}"
87-
assert cleanup in layer.group(
91+
assert command in layer.group(
8892
"body"
89-
), f"{cleanup} must run in the {command} layer"
93+
), f"{command} must run in the crawl4ai-setup layer"
94+
positions.append(layer.group("body").index(command))
95+
assert positions == sorted(positions), "Docker build steps must remain ordered"
9096

9197
def test_runs_as_non_root(self, dockerfile):
9298
assert re.search(r"^USER\s+appuser", dockerfile, re.MULTILINE)

0 commit comments

Comments
 (0)