Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 2 additions & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
"ms-python.pylint",
"njpwerner.autodocstring",
"kevinrose.vsc-python-indent",
"visualstudioexptteam.vscodeintellicode",
"ev.container-lambda-playwright-python",
"github.vscode-github-actions",
"ms-python.debugpy"
],
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.defaultInterpreterPath": "/workspaces/lambda-playwright-python/.venv/bin/python",
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
Expand All @@ -37,6 +35,6 @@
"forwardPorts": [
5678
],
"postCreateCommand": "pip install -r requirements.txt",
"postCreateCommand": "set -e; PYVER=$(/var/lang/bin/python -c 'import sys; print(f\"{sys.version_info.major}.{sys.version_info.minor}\")'); if [ \"$PYVER\" != \"3.14\" ]; then echo \"WARNING: Expected Python 3.14 in container, got $PYVER. Run: Dev Containers: Rebuild Container\"; fi; /var/lang/bin/python -m venv .venv; ./.venv/bin/python -m pip install -U pip setuptools wheel; ./.venv/bin/python -m pip install -r requirements.txt",
"remoteUser": "root"
}
5 changes: 3 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ jobs:
registry-type: public

- name: Build and push to DockerHub
uses: docker/build-push-action@v4
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/arm64
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/lambda-playwright-python:latest
${{ secrets.DOCKERHUB_USERNAME }}/lambda-playwright-python:${{ github.sha }}
Expand All @@ -66,7 +67,7 @@ jobs:
cache-to: type=gha,mode=max

- name: Build and push to Amazon ECR Public
uses: docker/build-push-action@v4
uses: docker/build-push-action@v6
with:
context: .
push: true
Expand Down
6 changes: 4 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{
"recommendations": [
"ms-vscode-remote.remote-containers",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-azuretools.vscode-docker",
"foxundermoon.shell-format",
"ms-python.black-formatter",
"ms-python.flake8",
"ms-python.pylint",
"ms-python.debugpy",
"njpwerner.autodocstring",
"kevinrose.vsc-python-indent",
"visualstudioexptteam.vscodeintellicode",
"ev.container-lambda-playwright-python"
"github.vscode-github-actions"
]
}
7 changes: 5 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
"python.defaultInterpreterPath": "/workspaces/lambda-playwright-python/.venv/bin/python",
"editor.formatOnSave": true,
"editor.rulers": [
100
Expand All @@ -17,7 +17,7 @@
}
},
"[dockerfile]": {
"editor.defaultFormatter": "ms-azuretools.vscode-docker"
"editor.defaultFormatter": "foxundermoon.shell-format"
},
"python.analysis.typeCheckingMode": "basic",
"python.analysis.autoImportCompletions": true,
Expand All @@ -42,5 +42,8 @@
"docker.defaultPlatform": "linux/arm64",
"docker.containers.description": {
"lambda-playwright": "Playwright Python Lambda Base Image"
},
"containers.containers.description": {
"lambda-playwright": "Playwright Python Lambda Base Image"
}
}
12 changes: 5 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Use AWS Lambda Python 3.13 base image
FROM public.ecr.aws/lambda/python:3.13-arm64
# Use AWS Lambda Python 3.14 base image
FROM public.ecr.aws/lambda/python:3.14-arm64

# Set environment variables
ENV PYTHONUNBUFFERED=1 \
DEBIAN_FRONTEND=noninteractive \
PLAYWRIGHT_BROWSERS_PATH=/opt/playwright \
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 \
PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/opt/playwright/chromium-*/chrome

# Install system dependencies for Chromium only
Expand Down Expand Up @@ -46,12 +44,12 @@ RUN microdnf install -y \

# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt && \
RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel && \
python -m pip install --no-cache-dir -r requirements.txt && \
rm -rf /root/.cache/pip

# Install Playwright browsers and set proper permissions
RUN playwright install chromium && \
RUN python -m playwright install chromium && \
chmod -R 777 /opt/playwright && \
find /opt/playwright -type f -name "chrome" -exec chmod +x {} \; && \
# Create necessary directories
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This repository contains a base Docker image for running Playwright with Python

## Features

- Python 3.13 support with latest performance improvements
- Python 3.14 support with latest performance improvements
- Playwright with headless Chromium browser
- AWS Lambda ARM64 compatibility
- Optimized for serverless environments
Expand All @@ -28,7 +28,7 @@ This repository contains a base Docker image for running Playwright with Python
- Docker
- VS Code with Remote - Containers extension
- AWS CLI (for ECR deployment)
- Python 3.13+
- Python 3.14+

### VS Code Dev Container

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
build:
context: .
dockerfile: Dockerfile
image: sjw744/lambda-playwright-python:latest
image: sjw7444/lambda-playwright-python:latest
platform: linux/arm64
volumes:
- .:/var/task
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
playwright == 1.54.0
playwright==1.58.0
pytest-playwright==0.7.2
pytest == 9.0.2
pytest==9.0.2
pytest-cov>=6.0.0
11 changes: 10 additions & 1 deletion tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

from playwright.sync_api import sync_playwright

LAUNCH_ARGS = [
"--no-sandbox",
"--disable-setuid-sandbox",
"--disable-dev-shm-usage",
"--disable-gpu",
"--no-zygote",
"--single-process",
]


def test_playwright_installation():
"""Test that Playwright and Chromium are properly installed."""
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
browser = p.chromium.launch(headless=True, args=LAUNCH_ARGS)
assert browser is not None
browser.close()
11 changes: 10 additions & 1 deletion tests/test_playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

from playwright.sync_api import sync_playwright

LAUNCH_ARGS = [
"--no-sandbox",
"--disable-setuid-sandbox",
"--disable-dev-shm-usage",
"--disable-gpu",
"--no-zygote",
"--single-process",
]


def test_basic_navigation():
"""Test basic browser navigation."""
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
browser = p.chromium.launch(headless=True, args=LAUNCH_ARGS)
page = browser.new_page()
page.goto("https://example.com")
assert page.title() == "Example Domain"
Expand Down
Loading