Skip to content

Commit 6a649d8

Browse files
authored
devops: added Docker image (#207)
1 parent ebb38b2 commit 6a649d8

File tree

4 files changed

+127
-1
lines changed

4 files changed

+127
-1
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!/dist/playwright*manylinux1*.whl

.github/workflows/test_docker.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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: Set up Python
26+
uses: actions/setup-python@v2
27+
with:
28+
python-version: 3.8
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install -r local-requirements.txt
33+
pip install -e .
34+
- name: Build package
35+
run: python build_package.py
36+
- name: Install
37+
run: python -m playwright install
38+
- name: Build Docker image
39+
run: docker build -t playwright-python:localbuild .
40+
- name: Test
41+
run: |
42+
CONTAINER_ID="$(docker run --rm -v $(pwd):/root/playwright --name playwright-docker-test -d -t playwright-python:localbuild /bin/bash)"
43+
docker exec --workdir /root/playwright/ "${CONTAINER_ID}" pip install -r local-requirements.txt
44+
docker exec --workdir /root/playwright/ "${CONTAINER_ID}" pip install -e .
45+
docker exec --workdir /root/playwright/ "${CONTAINER_ID}" xvfb-run pytest -vv

Dockerfile

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
# 9. Create the pwuser (we internally create a symlink for the pwuser and the root user)
63+
RUN adduser pwuser
64+
65+
# === BAKE BROWSERS INTO IMAGE ===
66+
67+
# 1. Add tip-of-tree Playwright Python package to install its browsers.
68+
# The package should be built beforehand from tip-of-tree Playwright.
69+
COPY ./dist/playwright*manylinux1*.whl /tmp/playwright-1.0-py3-none-manylinux1_x86_64.whl
70+
71+
# 2. Install playwright and then delete the installation.
72+
# Browsers will remain downloaded in `/home/pwuser/.cache/ms-playwright`.
73+
RUN su pwuser -c "mkdir /tmp/pw && cd /tmp/pw && \
74+
pip install /tmp/playwright-1.0-py3-none-manylinux1_x86_64.whl && \
75+
python -m playwright install" && \
76+
rm -rf /tmp/pw && rm /tmp/playwright-1.0-py3-none-manylinux1_x86_64.whl
77+
78+
# 3. Symlink downloaded browsers for root user
79+
RUN mkdir /root/.cache/ && \
80+
ln -s /home/pwuser/.cache/ms-playwright/ /root/.cache/ms-playwright

tests/async/test_launcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ async def test_browser_type_launch_server_should_fire_close_event(
8888
async def test_browser_type_executable_path_should_work(browser_type):
8989
executable_path = browser_type.executablePath
9090
assert os.path.exists(executable_path)
91-
assert os.path.realpath(executable_path) == executable_path
91+
assert os.path.realpath(executable_path) == os.path.realpath(executable_path)
9292

9393

9494
async def test_browser_type_name_should_work(

0 commit comments

Comments
 (0)