Skip to content

Commit e54ce4e

Browse files
committed
devops: added Docker image
1 parent fd3f33f commit e54ce4e

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed

.dockerignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
playwright/__pycache__/
2+
playwright/drivers/driver*
3+
playwright/driver-*
4+
driver/node_modules/
5+
driver/out/
6+
driver/package-lock.json
7+
playwright.egg-info/
8+
build/
9+
dist/
10+
**/*.pyc
11+
env/
12+
htmlcov/
13+
.coverage
14+
.DS_Store
15+
.vscode/
16+
.eggs
17+
_repo_version.py
18+
coverage.xml
19+
junit/
20+
htmldocs/
21+
22+
!/dist/*manylinux1_x86_64.whl

.github/workflows/test_docker.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Test Docker
2+
on:
3+
push:
4+
paths:
5+
- '.github/workflows/test_docker.yml'
6+
- 'driver/**'
7+
branches:
8+
- master
9+
pull_request:
10+
paths:
11+
- '.github/workflows/test_docker.yml'
12+
- 'driver/**'
13+
branches:
14+
- master
15+
jobs:
16+
build:
17+
timeout-minutes: 60
18+
runs-on: ubuntu-20.04
19+
steps:
20+
- uses: actions/checkout@v2
21+
- name: Set up Node.js
22+
uses: actions/setup-node@v1
23+
with:
24+
node-version: 12.x
25+
- name: Get Node PKG Cache dir
26+
id: node-pkg-cache
27+
run: |
28+
node -e "const path = require('path'); const fs = require('fs'); const cachePath = path.join(os.tmpdir(), 'pkg-cache'); fs.mkdirSync(cachePath); console.log('::set-output name=dir::' + cachePath)"
29+
- name: Cache driver
30+
id: cache-primes
31+
uses: actions/cache@v2
32+
with:
33+
path: ${{ steps.node-pkg-cache.outputs.dir }}
34+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
35+
- name: Set up Python
36+
uses: actions/setup-python@v2
37+
with:
38+
python-version: 3.8
39+
- name: Install dependencies
40+
run: |
41+
python -m pip install --upgrade pip
42+
pip install -r local-requirements.txt
43+
pip install -e .
44+
- name: Build driver
45+
run: python build_driver.py
46+
env:
47+
PKG_CACHE_PATH: ${{ steps.node-pkg-cache.outputs.dir }}
48+
- name: Build package
49+
run: python build_package.py
50+
- name: Install
51+
run: python -m playwright install
52+
- name: Build Docker image
53+
run: docker build -t playwright-python:localbuild .
54+
- name: Test
55+
run: |
56+
CONTAINER_ID="$(docker run --rm -v $(pwd):/root/playwright --name playwright-docker-test -d -t playwright-python:localbuild /bin/bash)"
57+
docker exec --workdir /root/playwright/ "${CONTAINER_ID}" pip install -r local-requirements.txt
58+
docker exec --workdir /root/playwright/ "${CONTAINER_ID}" xvfb-run pytest -vv

Dockerfile

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
FROM ubuntu:focal
2+
3+
# 1. Install latest Python
4+
RUN apt-get update && apt-get install -y python3 python3-pip && \
5+
update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1 && \
6+
update-alternatives --install /usr/bin/python python /usr/bin/python3 1
7+
8+
# 2. Install WebKit dependencies
9+
RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
10+
libwoff1 \
11+
libopus0 \
12+
libwebp6 \
13+
libwebpdemux2 \
14+
libenchant1c2a \
15+
libgudev-1.0-0 \
16+
libsecret-1-0 \
17+
libhyphen0 \
18+
libgdk-pixbuf2.0-0 \
19+
libegl1 \
20+
libnotify4 \
21+
libxslt1.1 \
22+
libevent-2.1-7 \
23+
libgles2 \
24+
libxcomposite1 \
25+
libatk1.0-0 \
26+
libatk-bridge2.0-0 \
27+
libepoxy0 \
28+
libgtk-3-0 \
29+
libharfbuzz-icu0
30+
31+
# 3. Install gstreamer and plugins to support video playback in WebKit.
32+
RUN apt-get update && apt-get install -y --no-install-recommends \
33+
libgstreamer-gl1.0-0 \
34+
libgstreamer-plugins-bad1.0-0 \
35+
gstreamer1.0-plugins-good \
36+
gstreamer1.0-libav
37+
38+
# 4. Install Chromium dependencies
39+
RUN apt-get update && apt-get install -y --no-install-recommends \
40+
libnss3 \
41+
libxss1 \
42+
libasound2 \
43+
fonts-noto-color-emoji \
44+
libxtst6
45+
46+
# 5. Install Firefox dependencies
47+
RUN apt-get update && apt-get install -y --no-install-recommends \
48+
libdbus-glib-1-2 \
49+
libxt6
50+
51+
# 6. Install ffmpeg to bring in audio and video codecs necessary for playing videos in Firefox.
52+
RUN apt-get update && apt-get install -y --no-install-recommends \
53+
ffmpeg
54+
55+
# 7. (Optional) Install XVFB if there's a need to run browsers in headful mode
56+
RUN apt-get update && apt-get install -y --no-install-recommends \
57+
xvfb
58+
59+
# 8. Feature-parity with node.js base images.
60+
RUN apt-get update && apt-get install -y --no-install-recommends git ssh
61+
62+
# === BAKE BROWSERS INTO IMAGE ===
63+
64+
# 1. Add tip-of-tree Playwright Python package to install its browsers.
65+
# The package should be built beforehand from tip-of-tree Playwright.
66+
COPY ./dist/playwright*manylinux1*.whl /tmp/playwright-1.0-py3-none-manylinux1_x86_64.whl
67+
68+
# 2. Install playwright and then delete the installation.
69+
# Browsers will remain downloaded in `/root/.cache/ms-playwright`.
70+
RUN mkdir /tmp/pw && cd /tmp/pw && \
71+
pip install /tmp/playwright-1.0-py3-none-manylinux1_x86_64.whl && \
72+
python -m playwright install && \
73+
rm -rf /tmp/pw && rm /tmp/playwright-1.0-py3-none-manylinux1_x86_64.whl

0 commit comments

Comments
 (0)