Skip to content

Commit c0c2a41

Browse files
authored
Merge pull request #678 from librespeed/fix-docker-images
alpine/debian docker image tests and fixes
2 parents ed9b19f + 513fe3f commit c0c2a41

File tree

6 files changed

+160
-47
lines changed

6 files changed

+160
-47
lines changed

Dockerfile

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
FROM php:8-apache
22

3+
# use docker-php-extension-installer for automatically get the right packages installed
4+
ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
5+
6+
37
# Install extensions
4-
RUN apt-get update && apt-get install -y --no-install-recommends \
5-
libfreetype6-dev \
6-
libjpeg62-turbo-dev \
7-
libpng-dev \
8-
libpq-dev \
9-
&& docker-php-ext-install -j$(nproc) iconv \
10-
&& docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \
11-
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
12-
&& docker-php-ext-install -j$(nproc) gd pdo pdo_mysql pdo_pgsql pgsql \
13-
&& rm -f /usr/src/php.tar.xz /usr/src/php.tar.xz.asc \
14-
&& apt-get remove -y libfreetype6-dev \
15-
libjpeg62-turbo-dev \
16-
libpng-dev \
17-
libpq-dev \
8+
RUN install-php-extensions iconv gd pdo pdo_mysql pdo_pgsql pgsql
9+
10+
RUN rm -f /usr/src/php.tar.xz /usr/src/php.tar.xz.asc \
1811
&& apt autoremove -y \
1912
&& rm -rf /var/lib/apt/lists/*
2013

@@ -42,11 +35,11 @@ ENV PASSWORD=password
4235
ENV TELEMETRY=false
4336
ENV ENABLE_ID_OBFUSCATION=false
4437
ENV REDACT_IP_ADDRESSES=false
45-
ENV WEBPORT=80
38+
ENV WEBPORT=8080
4639

4740
# https://httpd.apache.org/docs/2.4/stopping.html#gracefulstop
4841
STOPSIGNAL SIGWINCH
4942

5043
# Final touches
51-
EXPOSE 80
44+
EXPOSE ${WEBPORT}
5245
CMD ["bash", "/entrypoint.sh"]

Dockerfile.alpine

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
FROM php:8-alpine
2-
3-
# Install extensions
42
RUN apk add --quiet --no-cache \
53
bash \
64
apache2 \
7-
apache2-ssl \
8-
php83-apache2 \
9-
php83-ctype \
10-
php83-openssl \
11-
freetype-dev \
12-
libjpeg-turbo-dev \
13-
libpng-dev \
14-
libpq-dev \
15-
&& docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \
16-
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
17-
&& docker-php-ext-install -j$(nproc) gd pdo pdo_mysql pdo_pgsql pgsql \
18-
&& rm -f /usr/src/php.tar.xz /usr/src/php.tar.xz.asc \
19-
&& apk del --quiet --no-cache \
20-
freetype-dev \
21-
libjpeg-turbo-dev \
22-
libpng-dev \
23-
libpq-dev
5+
php-apache2 \
6+
php-ctype \
7+
php-gd \
8+
php-openssl \
9+
php-pdo \
10+
php-pdo_mysql \
11+
php-pdo_pgsql \
12+
php-pdo_sqlite \
13+
php-pgsql \
14+
php-session \
15+
php-sqlite3
16+
17+
# use docker-php-extension-installer for automatically get the right packages installed
18+
ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
19+
20+
21+
22+
# Install extensions
23+
RUN install-php-extensions iconv gd pdo pdo_mysql pdo_pgsql pgsql
2424

2525
RUN ln -sf /dev/stdout /var/log/apache2/access.log && \
2626
ln -sf /dev/stderr /var/log/apache2/error.log
@@ -49,11 +49,13 @@ ENV PASSWORD=password
4949
ENV TELEMETRY=false
5050
ENV ENABLE_ID_OBFUSCATION=false
5151
ENV REDACT_IP_ADDRESSES=false
52-
ENV WEBPORT=80
52+
ENV WEBPORT=8080
5353

5454
# https://httpd.apache.org/docs/2.4/stopping.html#gracefulstop
5555
STOPSIGNAL SIGWINCH
5656

57+
WORKDIR /var/www/html
58+
5759
# Final touches
58-
EXPOSE 80
60+
EXPOSE ${WEBPORT}
5961
CMD ["bash", "/entrypoint.sh"]

docker/entrypoint.sh

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
set -e
44
set -x
55

6+
is_alpine() {
7+
[ -f /etc/alpine-release ]
8+
}
9+
610
# Cleanup
711
rm -rf /var/www/html/*
812

@@ -13,7 +17,7 @@ cp /speedtest/*.js /var/www/html/
1317
cp /speedtest/favicon.ico /var/www/html/
1418

1519
# Set custom webroot on alpine
16-
if [ -f /etc/alpine-release ]; then
20+
if is_alpine; then
1721
sed -i "s#\"/var/www/localhost/htdocs\"#\"/var/www/html\"#g" /etc/apache2/httpd.conf
1822
fi
1923

@@ -38,24 +42,24 @@ if [ "$MODE" != "backend" ]; then
3842
fi
3943

4044
# Apply Telemetry settings when running in standalone or frontend mode and telemetry is enabled
41-
if [[ "$TELEMETRY" == "true" && ( "$MODE" == "frontend" || "$MODE" == "standalone" || "$MODE" == "dual" ) ]]; then
45+
if [[ "$TELEMETRY" == "true" && ("$MODE" == "frontend" || "$MODE" == "standalone" || "$MODE" == "dual") ]]; then
4246
cp -r /speedtest/results /var/www/html/results
4347

4448
if [ "$MODE" == "frontend" ]; then
4549
mkdir /var/www/html/backend
4650
cp /speedtest/backend/getIP_util.php /var/www/html/backend
4751
fi
4852

49-
if [ "$DB_TYPE" == "mysql" ]; then
53+
if [ "$DB_TYPE" == "mysql" ]; then
5054
sed -i 's/$db_type = '\''.*'\''/$db_type = '\'$DB_TYPE\''/g' /var/www/html/results/telemetry_settings.php
5155
sed -i 's/$MySql_username = '\''.*'\''/$MySql_username = '\'$DB_USERNAME\''/g' /var/www/html/results/telemetry_settings.php
5256
sed -i 's/$MySql_password = '\''.*'\''/$MySql_password = '\'$DB_PASSWORD\''/g' /var/www/html/results/telemetry_settings.php
5357
sed -i 's/$MySql_hostname = '\''.*'\''/$MySql_hostname = '\'$DB_HOSTNAME\''/g' /var/www/html/results/telemetry_settings.php
5458
sed -i 's/$MySql_databasename = '\''.*'\''/$MySql_databasename = '\'$DB_NAME\''/g' /var/www/html/results/telemetry_settings.php
55-
if [ "$DB_PORT" != "" ]; then
59+
if [ "$DB_PORT" != "" ]; then
5660
sed -i 's/$MySql_port = '\''.*'\''/$MySql_port = '\'$DB_PORT\''/g' /var/www/html/results/telemetry_settings.php
5761
fi
58-
elif [ "$DB_TYPE" == "postgresql" ]; then
62+
elif [ "$DB_TYPE" == "postgresql" ]; then
5963
sed -i 's/$db_type = '\''.*'\''/$db_type = '\'$DB_TYPE\''/g' /var/www/html/results/telemetry_settings.php
6064
sed -i 's/$PostgreSql_username = '\''.*'\''/$PostgreSql_username = '\'$DB_USERNAME\''/g' /var/www/html/results/telemetry_settings.php
6165
sed -i 's/$PostgreSql_password = '\''.*'\''/$PostgreSql_password = '\'$DB_PASSWORD\''/g' /var/www/html/results/telemetry_settings.php
@@ -77,14 +81,22 @@ if [[ "$TELEMETRY" == "true" && ( "$MODE" == "frontend" || "$MODE" == "standalon
7781
fi
7882

7983
mkdir -p /database/
80-
chown www-data /database/
84+
if is_alpine; then
85+
chown apache /database/
86+
else
87+
chown www-data /database/
88+
fi
8189
fi
8290

83-
chown -R www-data /var/www/html/*
91+
if is_alpine; then
92+
chown -R apache /var/www/html/*
93+
else
94+
chown -R www-data /var/www/html/*
95+
fi
8496

8597
# Allow selection of Apache port for network_mode: host
8698
if [ "$WEBPORT" != "80" ]; then
87-
if [ -f /etc/alpine-release ]; then
99+
if is_alpine; then
88100
sed -i "s/^Listen 80\$/Listen $WEBPORT/g" /etc/apache2/httpd.conf
89101
else
90102
sed -i "s/^Listen 80\$/Listen $WEBPORT/g" /etc/apache2/ports.conf
@@ -95,7 +107,7 @@ fi
95107
echo "Done, Starting APACHE"
96108

97109
# This runs apache
98-
if [ -f /etc/alpine-release ]; then
110+
if is_alpine; then
99111
exec httpd -DFOREGROUND
100112
else
101113
exec apache2-foreground

docker/test/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
COMPOSE_PROJECT_NAME=speedtest-test

docker/test/docker-compose.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
## this is a docker compose file used to test all scenarios
2+
## do not use it in production
3+
4+
services:
5+
###################### POSTGRESQL ################################
6+
pg:
7+
image: postgres:alpine
8+
environment:
9+
POSTGRES_PASSWORD: Not4SecureProduction
10+
POSTGRES_USER: librespeed
11+
volumes:
12+
# mount init script from source to create database tables
13+
- ../../results/telemetry_postgresql.sql:/docker-entrypoint-initdb.d/01-init.sql
14+
15+
speedtest-debian-pg:
16+
build:
17+
context: ../..
18+
dockerfile: Dockerfile
19+
environment: &env_vars_pg
20+
- PASSWORD=gimmeTheStats1337
21+
- DB_HOSTNAME=pg
22+
- DB_NAME=librespeed
23+
- DB_PASSWORD=Not4SecureProduction
24+
- DB_TYPE=postgresql
25+
- DB_USERNAME=librespeed
26+
27+
- ENABLE_ID_OBFUSCATION=true
28+
- MODE=standalone
29+
- REDACT_IP_ADDRESSES=true
30+
- TELEMETRY=true
31+
ports:
32+
- 9123:8080
33+
34+
speedtest-alpine-pg:
35+
build:
36+
context: ../..
37+
dockerfile: Dockerfile.alpine
38+
environment: *env_vars_pg
39+
ports:
40+
- 9124:8080
41+
42+
####################### MYSQL ##############################
43+
44+
mysql:
45+
image: mysql:lts
46+
environment:
47+
MYSQL_ROOT_PASSWORD: Not4SecureProduction
48+
MYSQL_USER: librespeed
49+
MYSQL_PASSWORD: Not4SecureProduction
50+
MYSQL_DATABASE: librespeed
51+
volumes:
52+
# mount init script from source to create database tables
53+
- ../../results/telemetry_mysql.sql:/docker-entrypoint-initdb.d/01-init.sql
54+
55+
speedtest-debian-mysql:
56+
# check at http://localhost:9125/results/sanitycheck.php
57+
build:
58+
context: ../..
59+
dockerfile: Dockerfile
60+
environment: &env_vars_mysql
61+
- PASSWORD=gimmeTheStats1337
62+
- DB_HOSTNAME=mysql
63+
- DB_NAME=librespeed
64+
- DB_PASSWORD=Not4SecureProduction
65+
- DB_TYPE=mysql
66+
- DB_USERNAME=librespeed
67+
68+
- ENABLE_ID_OBFUSCATION=true
69+
- MODE=standalone
70+
- REDACT_IP_ADDRESSES=true
71+
- TELEMETRY=true
72+
ports:
73+
- 9125:8080
74+
speedtest-alpine-mysql:
75+
build:
76+
context: ../..
77+
dockerfile: Dockerfile.alpine
78+
environment: *env_vars_mysql
79+
ports:
80+
- 9126:8080
81+
82+
###### SQLITE ######
83+
speedtest-debian-sqlite:
84+
# check at http://localhost:9125/results/sanitycheck.php
85+
build:
86+
context: ../..
87+
dockerfile: Dockerfile
88+
environment: &env_vars_sqlite
89+
- PASSWORD=gimmeTheStats1337
90+
91+
- ENABLE_ID_OBFUSCATION=true
92+
- MODE=standalone
93+
- REDACT_IP_ADDRESSES=true
94+
- TELEMETRY=true
95+
ports:
96+
- 9127:8080
97+
98+
speedtest-alpine-sqlite:
99+
build:
100+
context: ../..
101+
dockerfile: Dockerfile.alpine
102+
environment: *env_vars_sqlite
103+
ports:
104+
- 9128:8080

docker/ui.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
function I(i){return document.getElementById(i);}
1010

1111
//LIST OF TEST SERVERS. See documentation for details if needed
12-
<?php
12+
<?php
1313
$mode=getenv("MODE");
1414
if($mode=="standalone" || $mode=="dual"){ ?>
1515
var SPEEDTEST_SERVERS=[];
@@ -400,6 +400,7 @@ function initUI(){
400400
html,body,#loading{
401401
background:#202020;
402402
color:#F4F4F4;
403+
color-scheme:dark;
403404
}
404405
h1{
405406
color:#E0E0E0;

0 commit comments

Comments
 (0)