Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ RUN echo "Python version:" \
&& echo "All installed Python packages:" \
&& pip freeze
# % elif cookiecutter.package_manager == 'uv'
# Snapshot the base image's playwright version before COPY/uv sync so we can pin to it later
# and stay aligned with the browser binaries baked into /pw-browsers.
RUN pip install -U pip setuptools \
&& pip install 'uv<1'
&& pip install 'uv<1' \
&& (hash playwright 2>/dev/null && playwright --version | cut -d ' ' -f 2 > /tmp/.base-playwright-version || true)

ENV UV_PROJECT_ENVIRONMENT="/usr/local"

Expand All @@ -51,15 +54,20 @@ COPY pyproject.toml uv.lock ./
RUN echo "Python version:" \
&& python --version \
&& echo "Installing dependencies:" \
# Check if playwright is already installed
&& PLAYWRIGHT_INSTALLED=$(pip freeze | grep -q playwright && echo "true" || echo "false") \
&& if [ "$PLAYWRIGHT_INSTALLED" = "true" ]; then \
echo "Playwright already installed, excluding from uv sync" \
&& uv sync --frozen --no-install-project --no-editable -q --no-dev --inexact --no-install-package playwright; \
&& PLAYWRIGHT_BASE_VERSION=$(cat /tmp/.base-playwright-version 2>/dev/null || echo "") \
&& if [ -n "$PLAYWRIGHT_BASE_VERSION" ]; then \
echo "Playwright $PLAYWRIGHT_BASE_VERSION pre-installed in base image; excluding from uv sync" \
&& uv sync --frozen --no-install-project --no-editable -q --no-dev --inexact --no-install-package playwright \
&& CURRENT_PLAYWRIGHT_VERSION=$(playwright --version 2>/dev/null | cut -d ' ' -f 2) \
&& if [ "$CURRENT_PLAYWRIGHT_VERSION" != "$PLAYWRIGHT_BASE_VERSION" ]; then \
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do this check every time, what is the point of the --no-install-package playwright? It looks like a belt-and-suspenders thing to me.

echo "Pinning playwright back to $PLAYWRIGHT_BASE_VERSION (was $CURRENT_PLAYWRIGHT_VERSION) to match shipped browsers" \
&& uv pip install --reinstall --no-deps "playwright==$PLAYWRIGHT_BASE_VERSION"; \
fi; \
else \
echo "Playwright not found, installing all dependencies" \
echo "Playwright not found in base image, installing all dependencies as resolved in the lockfile" \
&& uv sync --frozen --no-install-project --no-editable -q --no-dev --inexact; \
fi \
&& rm -f /tmp/.base-playwright-version \
&& echo "All installed Python packages:" \
&& pip freeze
# % elif cookiecutter.package_manager == 'pip'
Expand Down
Loading