Skip to content

Commit 084646d

Browse files
committed
Moved docker stuff into the master branch instead of a separate one
1 parent 2ea9b4f commit 084646d

9 files changed

+1077
-3
lines changed

Dockerfile

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
FROM php:7.4-apache
2+
3+
# Install extensions
4+
RUN apt-get update && apt-get install -y \
5+
libfreetype6-dev \
6+
libjpeg62-turbo-dev \
7+
libpng-dev \
8+
&& docker-php-ext-install -j$(nproc) iconv \
9+
&& docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \
10+
&& docker-php-ext-install -j$(nproc) gd
11+
12+
# Prepare files and folders
13+
14+
RUN mkdir -p /speedtest/
15+
16+
# Copy sources
17+
18+
COPY backend/ /speedtest/backend
19+
20+
COPY results/*.php /speedtest/results/
21+
COPY results/*.ttf /speedtest/results/
22+
23+
COPY *.js /speedtest/
24+
COPY favicon.ico /speedtest/
25+
26+
COPY docker/servers.json /servers.json
27+
28+
COPY docker/*.php /speedtest/
29+
COPY docker/entrypoint.sh /
30+
31+
# Prepare environment variabiles defaults
32+
33+
ENV TITLE=LibreSpeed
34+
ENV MODE=standalone
35+
ENV PASSWORD=password
36+
ENV TELEMETRY=false
37+
ENV ENABLE_ID_OBFUSCATION=false
38+
ENV REDACT_IP_ADDRESSES=false
39+
ENV WEBPORT=80
40+
41+
# Final touches
42+
43+
EXPOSE 80
44+
CMD ["bash", "/entrypoint.sh"]

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Works with mobile versions too.
3939
A template to build an Android client for your LibreSpeed installation is available [here](https://github.com/librespeed/speedtest-android).
4040

4141
## Docker
42-
Please see the `docker` branch
42+
A docker image is available on the [Docker Hub](https://registry.hub.docker.com/r/adolfintel/speedtest), see `doc_docker.md` for more info about it
4343

4444
## Go backend
4545
A Go implementation is available in the [`speedtest-go`](https://github.com/librespeed/speedtest-go) repo, maintained by [Maddie Zhan](https://github.com/maddie).

doc.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# LibreSpeed
22

33
> by Federico Dossena
4-
> Version 5.2.3
4+
> Version 5.2.4
55
> [https://github.com/librespeed/speedtest/](https://github.com/librespeed/speedtest/)
66
77
## Introduction

doc_docker.md

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
A docker version of LibreSpeed is available on docker hub: [https://hub.docker.com/r/adolfintel/speedtest/](https://hub.docker.com/r/adolfintel/speedtest/)
2+
3+
## Downloading from Docker hub
4+
To download LibreSpeed from the docker hub, use this command:
5+
6+
```
7+
docker pull adolfintel/speedtest
8+
```
9+
10+
You will now have a new docker image called `adolfintel/speedtest`.
11+
12+
## Standalone mode
13+
If you want to install LibreSpeed on a single server, you need to configure it in standalone mode. To do this, set the `MODE` environment variable to `standalone`.
14+
15+
The test can be accessed on port 80.
16+
17+
Here's a list of additional environment variables available in this mode:
18+
* __`TITLE`__: Title of your speedtest. Default value: `LibreSpeed`
19+
* __`TELEMETRY`__: Whether to enable telemetry or not. Default value: `false`
20+
* __`ENABLE_ID_OBFUSCATION`__: When set to true with telemetry enabled, test IDs are obfuscated, to avoid exposing the database internal sequential IDs. Default value: `false`
21+
* __`REDACT_IP_ADDRESSES`__: When set to true with telemetry enabled, IP addresses and hostnames are redacted from the collected telemetry, for better privacy. Default value: `false`
22+
* __`PASSWORD`__: Password to access the stats page. If not set, stats page will not allow accesses.
23+
* __`EMAIL`__: Email address for GDPR requests. Must be specified when telemetry is enabled.
24+
* __`IPINFO_APIKEY`__: API key for ipinfo.io. Optional, but required if you expect to serve a large number of tests
25+
* __`DISABLE_IPINFO`__: If set to true, ISP info and distance will not be fetched from ipinfo.io. Default: value: `false`
26+
* __`DISTANCE`__: When `DISABLE_IPINFO` is set to false, this specifies how the distance from the server is measured. Can be either `km` for kilometers, `mi` for miles, or an empty string to disable distance measurement. Default value: `km`
27+
* __`WEBPORT`__: Allows choosing a custom port for the included web server. Default value: `80`. Note that you will have to expose it through docker with the -p argument
28+
29+
If telemetry is enabled, a stats page will be available at `http://your.server/results/stats.php`, but a password must be specified.
30+
31+
###### Example
32+
This command starts LibreSpeed in standalone mode, with the default settings, on port 80:
33+
34+
```
35+
docker run -e MODE=standalone -p 80:80 -it adolfintel/speedtest
36+
```
37+
38+
This command starts LibreSpeed in standalone mode, with telemetry, ID obfuscation and a stats password, on port 86:
39+
40+
```
41+
docker run -e MODE=standalone -e TELEMETRY=true -e ENABLE_ID_OBFUSCATION=true -e PASSWORD="yourPasswordHere" -e WEBPORT=86 -p 86:86 -it adolfintel/speedtest
42+
```
43+
44+
## Multiple Points of Test
45+
For multiple servers, you need to set up 1+ LibreSpeed backends, and 1 LibreSpeed frontend.
46+
47+
### Backend mode
48+
In backend mode, LibreSpeed provides only a test point with no UI. To do this, set the `MODE` environment variable to `backend`.
49+
50+
The following backend files can be accessed on port 80: `garbage.php`, `empty.php`, `getIP.php`
51+
52+
Here's a list of additional environment variables available in this mode:
53+
* __`IPINFO_APIKEY`__: API key for ipinfo.io. Optional, but required if you expect to serve a large number of tests
54+
55+
###### Example:
56+
This command starts LibreSpeed in backend mode, with the default settings, on port 80:
57+
```
58+
docker run -e MODE=backend -p 80:80 -it adolfintel/speedtest
59+
```
60+
61+
### Frontend mode
62+
In frontend mode, LibreSpeed serves clients the Web UI and a list of servers. To do this:
63+
* Set the `MODE` environment variable to `frontend`
64+
* Create a servers.json file with your test points. The syntax is the following:
65+
```
66+
[
67+
{
68+
"name": "Friendly name for Server 1",
69+
"server" :"//server1.mydomain.com/",
70+
"dlURL" :"garbage.php",
71+
"ulURL" :"empty.php",
72+
"pingURL" :"empty.php",
73+
"getIpURL" :"getIP.php"
74+
},
75+
{
76+
"name": "Friendly name for Server 2",
77+
"server" :"https://server2.mydomain.com/",
78+
"dlURL" :"garbage.php",
79+
"ulURL" :"empty.php",
80+
"pingURL" :"empty.php",
81+
"getIpURL" :"getIP.php"
82+
},
83+
...more servers...
84+
]
85+
```
86+
Note: if a server only supports HTTP or HTTPS, specify the protocol in the server field. If it supports both, just use `//`.
87+
* Mount this file to `/servers.json` in the container (example at the end of this file)
88+
89+
The test can be accessed on port 80.
90+
91+
Here's a list of additional environment variables available in this mode:
92+
* __`TITLE`__: Title of your speedtest. Default value: `LibreSpeed`
93+
* __`TELEMETRY`__: Whether to enable telemetry or not. Default value: `false`
94+
* __`ENABLE_ID_OBFUSCATION`__: When set to true with telemetry enabled, test IDs are obfuscated, to avoid exposing the database internal sequential IDs. Default value: `false`
95+
* __`REDACT_IP_ADDRESSES`__: When set to true with telemetry enabled, IP addresses and hostnames are redacted from the collected telemetry, for better privacy. Default value: `false`
96+
* __`PASSWORD`__: Password to access the stats page. If not set, stats page will not allow accesses.
97+
* __`EMAIL`__: Email address for GDPR requests. Must be specified when telemetry is enabled.
98+
* __`DISABLE_IPINFO`__: If set to true, ISP info and distance will not be fetched from ipinfo.io. Default: value: `false`
99+
* __`DISTANCE`__: When `DISABLE_IPINFO` is set to false, this specifies how the distance from the server is measured. Can be either `km` for kilometers, `mi` for miles, or an empty string to disable distance measurement. Default value: `km`
100+
* __`WEBPORT`__: Allows choosing a custom port for the included web server. Default value: `80`
101+
102+
###### Example
103+
This command starts LibreSpeed in frontend mode, with a given `servers.json` file, and with telemetry, ID obfuscation, and a stats password:
104+
```
105+
docker run -e MODE=frontend -e TELEMETRY=true -e ENABLE_ID_OBFUSCATION=true -e PASSWORD="yourPasswordHere" -v $(pwd)/servers.json:/servers.json -p 80:80 -it adolfintel/speedtest
106+
```

docker/entrypoint.sh

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -x
5+
6+
# Cleanup
7+
rm -rf /var/www/html/*
8+
9+
# Copy frontend files
10+
cp /speedtest/*.js /var/www/html/
11+
12+
# Copy favicon
13+
cp /speedtest/favicon.ico /var/www/html/
14+
15+
# Set up backend side for standlone modes
16+
if [ "$MODE" == "standalone" ]; then
17+
cp -r /speedtest/backend/ /var/www/html/backend
18+
if [ ! -z "$IPINFO_APIKEY" ]; then
19+
sed -i s/\$IPINFO_APIKEY\ =\ \'\'/\$IPINFO_APIKEY\ =\ \'$IPINFO_APIKEY\'/g /var/www/html/backend/getIP_ipInfo_apikey.php
20+
fi
21+
fi
22+
23+
if [ "$MODE" == "backend" ]; then
24+
cp -r /speedtest/backend/* /var/www/html
25+
if [ ! -z "$IPINFO_APIKEY" ]; then
26+
sed -i s/\$IPINFO_APIKEY\ =\ \'\'/\$IPINFO_APIKEY\ =\ \'$IPINFO_APIKEY\'/g /var/www/html/getIP_ipInfo_apikey.php
27+
fi
28+
fi
29+
30+
# Set up index.php for frontend-only or standalone modes
31+
if [ "$MODE" == "frontend" ]; then
32+
cp /speedtest/frontend.php /var/www/html/index.php
33+
elif [ "$MODE" == "standalone" ]; then
34+
cp /speedtest/standalone.php /var/www/html/index.php
35+
fi
36+
37+
# Apply Telemetry settings when running in standalone or frontend mode and telemetry is enabled
38+
if [[ "$TELEMETRY" == "true" && ( "$MODE" == "frontend" || "$MODE" == "standalone" ) ]]; then
39+
cp -r /speedtest/results /var/www/html/results
40+
41+
sed -i s/\$db_type\ =\ \'.*\'/\$db_type\ =\ \'sqlite\'\/g /var/www/html/results/telemetry_settings.php
42+
sed -i s/\$Sqlite_db_file\ =\ \'.*\'/\$Sqlite_db_file=\'\\\/database\\\/db.sql\'/g /var/www/html/results/telemetry_settings.php
43+
sed -i s/\$stats_password\ =\ \'.*\'/\$stats_password\ =\ \'$PASSWORD\'/g /var/www/html/results/telemetry_settings.php
44+
45+
if [ "$ENABLE_ID_OBFUSCATION" == "true" ]; then
46+
sed -i s/\$enable_id_obfuscation\ =\ .*\;/\$enable_id_obfuscation\ =\ true\;/g /var/www/html/results/telemetry_settings.php
47+
fi
48+
49+
if [ "$REDACT_IP_ADDRESSES" == "true" ]; then
50+
sed -i s/\$redact_ip_addresses\ =\ .*\;/\$redact_ip_addresses\ =\ true\;/g /var/www/html/results/telemetry_settings.php
51+
fi
52+
53+
mkdir -p /database/
54+
chown www-data /database/
55+
fi
56+
57+
chown -R www-data /var/www/html/*
58+
59+
# Allow selection of Apache port for network_mode: host
60+
if [ "$WEBPORT" != "80" ]; then
61+
sed -i "s/^Listen 80\$/Listen $WEBPORT/g" /etc/apache2/ports.conf
62+
sed -i "s/*:80>/*:$WEBPORT>/g" /etc/apache2/sites-available/000-default.conf
63+
fi
64+
65+
echo "Done, Starting APACHE"
66+
67+
# This runs apache
68+
apache2-foreground

0 commit comments

Comments
 (0)