Skip to content

Commit 92db26f

Browse files
committed
Dockerfile completed
1 parent 148f635 commit 92db26f

File tree

5 files changed

+97
-72
lines changed

5 files changed

+97
-72
lines changed

.dockerignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1+
# hidden unused files
12
.git
3+
.vscode
4+
.gitignore
5+
.travis.yml
6+
7+
# unused folders
8+
docs
9+
test
10+
11+
# unused script and files
12+
alive.bat
13+
browsers.ini.sample
14+
centos_install.sh
15+
ios_install.sh
16+
ubuntu_install.sh
17+
windows_install.ps1
18+
windows_post_reboot.ps1

Dockerfile

Lines changed: 36 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,51 @@
1-
### IMPORTANT DOCKER COMMANDS ###
1+
FROM ubuntu as production
22

3-
### docker images - List images available
4-
### docker build <GITHUB-REPO-LINK> -t TAGNAME - Builds the Dockerfile from the github repo
5-
### docker ps - List running images
6-
### docker stop <IMAGE ID || IMAGE NAME> - Stops running image with either --name <IMAGE NAME> || IMAGE ID>
7-
### docker run -it -d TAGNAME /bin/bash - Runs bash
8-
### docker exec -it <IMAGE ID> /bin/bash - Connects to bash for terminal execution (Needs to be running first)
3+
# since we don't really need a stable base we can also upgrade
4+
RUN apt update && apt upgrade -y
95

10-
### EXAMPLE DOCKER COMMANDS FOR RUNNING SERVER & AGENT
11-
12-
### docker run -d -p 4000:80 <IMAGE ID || <IMAGE TAG>
13-
### docker run -d -p 4001:80 --network="host" -e "SERVER_URL=http://localhost:4000/work/" -e "LOCATION=Test" -e "-v" <IMAGE ID || <IMAGE TAG>
14-
15-
### INSTALLING METHOD ###
16-
17-
### Recommend to install with "docker build <GITHUB-REPO-LINK> -t TAGNAME",
18-
### grabs the latest copy of WPT and build time on average takes 10 minutes.
19-
20-
FROM ubuntu
21-
22-
### PREVENTs INTERACTIVE PROMPTS WHILE INSTALLING ###
23-
ARG DEBIAN_FRONTEND=noninteractive
24-
25-
### COPYING ENTIRE DIR TO LOCAL DOCKER /wptagent
6+
# Get files
7+
# see .dockerignore for filterd out folders
268
COPY / /wptagent
27-
RUN apt-get update
289

29-
# Git Clone Install
30-
# RUN apt-get install -y git
31-
# RUN git clone -b dockerfile https://github.com/sammeboy635/wptagent.git
10+
# dependencies
3211

33-
### UPDATE ###
34-
RUN apt-get update
12+
## apt dependencies (took them from https://github.com/WPO-Foundation/wptagent/blob/master/.github/workflows/wptagent_test.yml#L31)
13+
# split into 2 parts to show dependency gathered from docs and found during upgrade of the docker image
14+
# set UTC as default timezone before end to avoid user interaction for tzdata package
15+
RUN ln -fs /usr/share/zoneinfo/UTC /etc/localtime && \
16+
DEBIAN_FRONTEND=noninteractive apt install -y pylint apt-transport-https xserver-xorg-video-dummy xvfb gnupg2 python3-ujson imagemagick \
17+
dbus-x11 traceroute software-properties-common psmisc libnss3-tools iproute2 net-tools openvpn libtiff5-dev \
18+
libjpeg-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python3-tk python3-dev \
19+
libavutil-dev libmp3lame-dev libx264-dev yasm autoconf automake build-essential libass-dev libfreetype6-dev \
20+
libtheora-dev libtool libvorbis-dev pkg-config texi2html libtext-unidecode-perl python3-numpy python3-scipy \
21+
perl adb ethtool nodejs cmake libsdl2-dev libva-dev libvdpau-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev \
22+
texinfo wget ttf-mscorefonts-installer fonts-noto fonts-roboto fonts-open-sans
23+
RUN apt install -y python3 python3-pip curl npm sudo
3524

36-
### INSTALL APT-GET LIBS ###
37-
RUN xargs -a /wptagent/.github/workflows/docker-apt-get.txt apt-get install --no-install-recommends --yes; exit 0
3825

39-
### UPGRADING PIP AND INSTALLING REQUIRED PACKAGES ###
40-
RUN python3 -m pip install --upgrade --user pip && \
41-
python3 -m pip install --user -r /wptagent/.github/workflows/requirements.txt
26+
## python dependencies
27+
# FIXME split requirements into dev requirements and release requirements
28+
RUN pip install -r /wptagent/.github/workflows/requirements.txt && rm -rf /wptagent/.github/
4229

43-
### INSTALLING LIGHTHOUSE FROM NPM ###
30+
## npm dependencies
4431
RUN npm install -g lighthouse
4532

46-
### INSTALLING CHROME BROWSER ###
47-
### Fails to Find all libs needed to run
48-
# RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \
49-
# dpkg -i google-chrome-stable_current_amd64.deb; exit 0 && \
50-
# apt -f install -y && \
51-
# apt-get install google-chrome-stable
33+
# install chrome, simplified version
34+
RUN curl -o google-chrome-stable_current_amd64.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \
35+
apt install -y /google-chrome-stable_current_amd64.deb && rm /google-chrome-stable_current_amd64.deb
5236

53-
### BETTER INSTALLING CHROME BROWSER METHOD ###
54-
### Better Installing method but would like to change this to something less complex.
55-
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
56-
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
57-
RUN apt-get update && apt-get -y install google-chrome-stable ; exit 0
58-
RUN apt-get update --fix-missing -y
59-
RUN apt-get install -f -y
37+
WORKDIR /wptagent
6038

61-
### CLEAN UP ###
62-
# We could add some clean up here but in testing it was negotiable
39+
ENTRYPOINT ["/bin/sh", "/wptagent/docker/linux-headless/entrypoint.sh"]
6340

41+
# Create debug build that waits for a debugger to attach
42+
FROM production as debug
6443

65-
WORKDIR /wptagent
44+
RUN pip install debugpy
45+
46+
RUN mv wptagent.py wptagent_starter.py
47+
48+
COPY wptagent_debug.py wptagent.py
6649

67-
### /bin/bash LOCATION OF COMMAND EXECUTION ###
68-
CMD ["/bin/bash", "/wptagent/docker/linux-headless/entrypoint.sh"]
50+
# set production build as default
51+
FROM production

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,33 @@ The test result is written as JSON to `stdout`. If a server, location, and key a
141141
- `--testruns`: Number of runs to test. Defaults to 1.
142142
- `--testrv`: Include repeat view (defaults to only testing first view)
143143

144+
### Running the container
145+
146+
The `Dokerfile`` has multi-stage definition:
147+
* **production**: Default stage, produce a image without debug features;
148+
* **debug**: When running the produced image the wptagent script will wait for a debug to.attach
149+
150+
To build the production container
151+
```sh
152+
docker build --tag wptagent .
153+
```
154+
To build the debug container
155+
```sh
156+
docker build --target debug --tag wptagent -debug .
157+
```
158+
159+
The entrypoint is `docker\linux-headless\entrypoint.sh` that has some of the above parameters as default: `--xvfb`, `--dockerized`.
160+
Mandatory parameters are required via environment variables:
161+
* **SERVER_URL**: corresponding to `--server` parameter;
162+
* **LOCATION**: corresponding to `--location` parameter.
163+
164+
Additional parameters can be passed. A typical run in debug mode looks like this
165+
166+
```sh
167+
docker run -e SERVER_URL=http://127.0.0.1:80/work/ -e LOCATION=Test wptagent-debug -vvvv --key 123456789
168+
```
169+
170+
where `-vvvv` and `--key` are optional parameters passed to the wptagent script.
144171
## Supported features
145172

146173
The following [Script Commands](https://docs.webpagetest.org/scripting/) are supported on Windows, Linux, Mac, and Android:
Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#!/bin/bash
2-
set -e
3-
42
if [ -z "$SERVER_URL" ]; then
53
echo >&2 'SERVER_URL not set'
64
exit 1
@@ -11,22 +9,6 @@ if [ -z "$LOCATION" ]; then
119
exit 1
1210
fi
1311

14-
if [ -z "$EXTRA_ARGS" ]; then
15-
EXTRA_ARGS=""
16-
fi
17-
18-
if [ -n "$NAME" ]; then
19-
EXTRA_ARGS="$EXTRA_ARGS --name $NAME"
20-
fi
21-
22-
if [ -n "$KEY" ]; then
23-
EXTRA_ARGS="$EXTRA_ARGS --key $KEY"
24-
fi
25-
26-
if [ -n "$SHAPER" ]; then
27-
EXTRA_ARGS="$EXTRA_ARGS --shaper $SHAPER"
28-
fi
29-
3012
# exec replaces the shell process by the python process and is required to
3113
# propagate signals (i.e. SIGTERM)
32-
exec python3 /wptagent/wptagent.py --server "${SERVER_URL}" --location "${LOCATION}" ${EXTRA_ARGS} --xvfb --dockerized -vvvv
14+
exec python3 /wptagent/wptagent.py --server "${SERVER_URL}" --location "${LOCATION}" --xvfb --dockerized "$@"

wptagent_debug.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import debugpy
2+
import os
3+
# first try to import with the original name
4+
try:
5+
from wptagent import main
6+
except ImportError:
7+
# then import as the contianer require
8+
from wptagent_starter import main
9+
10+
if __name__ == '__main__':
11+
print("Waiting for debug")
12+
debugpy.listen(("0.0.0.0", 50000))
13+
debugpy.wait_for_client()
14+
main()
15+
# Force a hard exit so unclean threads can't hang the agent
16+
os._exit(0)

0 commit comments

Comments
 (0)