diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index b771c27..a6c074e 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -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, @@ -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" } \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 028aaf3..5e7281c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -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 }} @@ -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 diff --git a/.vscode/extensions.json b/.vscode/extensions.json index d6604f8..80cd6c9 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -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" ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 856e1ed..8762d8b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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 @@ -17,7 +17,7 @@ } }, "[dockerfile]": { - "editor.defaultFormatter": "ms-azuretools.vscode-docker" + "editor.defaultFormatter": "foxundermoon.shell-format" }, "python.analysis.typeCheckingMode": "basic", "python.analysis.autoImportCompletions": true, @@ -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" } } \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 4de74b3..cc9abdb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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 diff --git a/README.md b/README.md index e3db6fe..b19f556 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index b7972e9..ca32345 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/requirements.txt b/requirements.txt index ddff0b1..a6345d5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/tests/test_basic.py b/tests/test_basic.py index 1f4c3d8..58ed8cc 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -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() diff --git a/tests/test_playwright.py b/tests/test_playwright.py index acfc7f1..af30622 100644 --- a/tests/test_playwright.py +++ b/tests/test_playwright.py @@ -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"