From 0c31f1de6d03e8d39150ef354be8750d3f72a341 Mon Sep 17 00:00:00 2001 From: Stefan S Date: Sat, 26 Oct 2024 15:40:13 +0200 Subject: [PATCH 1/5] alpine/debian images tested with postgres --- Dockerfile | 25 +++++++++---------------- Dockerfile.alpine | 42 +++++++++++++++++++++--------------------- 2 files changed, 30 insertions(+), 37 deletions(-) diff --git a/Dockerfile b/Dockerfile index 684a16027..e4ea1c8e7 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,13 @@ FROM php:8-apache +# use docker-php-extension-installer for automatically get the right packages installed +ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ + + # Install extensions -RUN apt-get update && apt-get install -y --no-install-recommends \ - libfreetype6-dev \ - libjpeg62-turbo-dev \ - libpng-dev \ - libpq-dev \ - && docker-php-ext-install -j$(nproc) iconv \ - && docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \ - && docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \ - && docker-php-ext-install -j$(nproc) gd pdo pdo_mysql pdo_pgsql pgsql \ - && rm -f /usr/src/php.tar.xz /usr/src/php.tar.xz.asc \ - && apt-get remove -y libfreetype6-dev \ - libjpeg62-turbo-dev \ - libpng-dev \ - libpq-dev \ +RUN install-php-extensions iconv gd pdo pdo_mysql pdo_pgsql pgsql + +RUN rm -f /usr/src/php.tar.xz /usr/src/php.tar.xz.asc \ && apt autoremove -y \ && rm -rf /var/lib/apt/lists/* @@ -42,11 +35,11 @@ ENV PASSWORD=password ENV TELEMETRY=false ENV ENABLE_ID_OBFUSCATION=false ENV REDACT_IP_ADDRESSES=false -ENV WEBPORT=80 +ENV WEBPORT=8080 # https://httpd.apache.org/docs/2.4/stopping.html#gracefulstop STOPSIGNAL SIGWINCH # Final touches -EXPOSE 80 +EXPOSE ${WEBPORT} CMD ["bash", "/entrypoint.sh"] diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 633ceec19..bc0f7464d 100755 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -1,26 +1,26 @@ FROM php:8-alpine - -# Install extensions RUN apk add --quiet --no-cache \ bash \ apache2 \ - apache2-ssl \ - php83-apache2 \ - php83-ctype \ - php83-openssl \ - freetype-dev \ - libjpeg-turbo-dev \ - libpng-dev \ - libpq-dev \ - && docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \ - && docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \ - && docker-php-ext-install -j$(nproc) gd pdo pdo_mysql pdo_pgsql pgsql \ - && rm -f /usr/src/php.tar.xz /usr/src/php.tar.xz.asc \ - && apk del --quiet --no-cache \ - freetype-dev \ - libjpeg-turbo-dev \ - libpng-dev \ - libpq-dev + php-apache2 \ + php-ctype \ + php-gd \ + php-openssl \ + php-pdo \ + php-pdo_mysql \ + php-pdo_pgsql \ + php-pdo_sqlite \ + php-pgsql \ + php-session \ + php-sqlite3 + +# use docker-php-extension-installer for automatically get the right packages installed +ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ + + + +# Install extensions +RUN install-php-extensions iconv gd pdo pdo_mysql pdo_pgsql pgsql RUN ln -sf /dev/stdout /var/log/apache2/access.log && \ ln -sf /dev/stderr /var/log/apache2/error.log @@ -49,11 +49,11 @@ ENV PASSWORD=password ENV TELEMETRY=false ENV ENABLE_ID_OBFUSCATION=false ENV REDACT_IP_ADDRESSES=false -ENV WEBPORT=80 +ENV WEBPORT=8080 # https://httpd.apache.org/docs/2.4/stopping.html#gracefulstop STOPSIGNAL SIGWINCH # Final touches -EXPOSE 80 +EXPOSE ${WEBPORT} CMD ["bash", "/entrypoint.sh"] From 2c3be7b52df81adfb100bfa01f8bfb6021c7f0f8 Mon Sep 17 00:00:00 2001 From: Stefan S Date: Sat, 26 Oct 2024 15:52:33 +0200 Subject: [PATCH 2/5] docker test for postgres --- docker/test/.env | 1 + docker/test/docker-compose.yml | 40 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 docker/test/.env create mode 100644 docker/test/docker-compose.yml diff --git a/docker/test/.env b/docker/test/.env new file mode 100644 index 000000000..68023f010 --- /dev/null +++ b/docker/test/.env @@ -0,0 +1 @@ +COMPOSE_PROJECT_NAME=speedtest-test diff --git a/docker/test/docker-compose.yml b/docker/test/docker-compose.yml new file mode 100644 index 000000000..5aae8fb81 --- /dev/null +++ b/docker/test/docker-compose.yml @@ -0,0 +1,40 @@ +## this is a docker compose file used to test all scenarios +## do not use it in production + +services: + pg: + image: postgres:alpine + environment: + POSTGRES_PASSWORD: Not4SecureProduction + POSTGRES_USER: librespeed + volumes: + # mount init script from source to create database tables + - ../../results/telemetry_postgresql.sql:/docker-entrypoint-initdb.d/01-init.sql + + speedtest-debian-pg: + build: + context: ../.. + dockerfile: Dockerfile + environment: &env_vars + - PASSWORD=gimmeTheStats1337 + - DB_HOSTNAME=pg + - DB_NAME=librespeed + - DB_PASSWORD=Not4SecureProduction + - DB_PORT=5432 + - DB_TYPE=postgresql + - DB_USERNAME=librespeed + - EMAIL=test@example.com + - ENABLE_ID_OBFUSCATION=true + - MODE=standalone + - REDACT_IP_ADDRESSES=true + - TELEMETRY=true + ports: + - 9123:8080 + + speedtest-alpine-pg: + build: + context: ../.. + dockerfile: Dockerfile.alpine + environment: *env_vars + ports: + - 9124:8080 From 8a7c145a19ceb35c5045b3e68d25135246ab8a6a Mon Sep 17 00:00:00 2001 From: Stefan S Date: Sat, 26 Oct 2024 17:16:00 +0200 Subject: [PATCH 3/5] test docker mysql --- docker/test/docker-compose.yml | 46 +++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/docker/test/docker-compose.yml b/docker/test/docker-compose.yml index 5aae8fb81..b6421c9a6 100644 --- a/docker/test/docker-compose.yml +++ b/docker/test/docker-compose.yml @@ -2,6 +2,7 @@ ## do not use it in production services: + ###################### POSTGRESQL ################################ pg: image: postgres:alpine environment: @@ -15,12 +16,11 @@ services: build: context: ../.. dockerfile: Dockerfile - environment: &env_vars + environment: &env_vars_pg - PASSWORD=gimmeTheStats1337 - DB_HOSTNAME=pg - DB_NAME=librespeed - DB_PASSWORD=Not4SecureProduction - - DB_PORT=5432 - DB_TYPE=postgresql - DB_USERNAME=librespeed - EMAIL=test@example.com @@ -35,6 +35,46 @@ services: build: context: ../.. dockerfile: Dockerfile.alpine - environment: *env_vars + environment: *env_vars_pg ports: - 9124:8080 + + ####################### MYSQL ############################## + + mysql: + image: mysql:lts + environment: + MYSQL_ROOT_PASSWORD: Not4SecureProduction + MYSQL_USER: librespeed + MYSQL_PASSWORD: Not4SecureProduction + MYSQL_DATABASE: librespeed + volumes: + # mount init script from source to create database tables + - ../../results/telemetry_mysql.sql:/docker-entrypoint-initdb.d/01-init.sql + + speedtest-debian-mysql: + # check at http://localhost:9125/results/sanitycheck.php + build: + context: ../.. + dockerfile: Dockerfile + environment: &env_vars_mysql + - PASSWORD=gimmeTheStats1337 + - DB_HOSTNAME=mysql + - DB_NAME=librespeed + - DB_PASSWORD=Not4SecureProduction + - DB_TYPE=mysql + - DB_USERNAME=librespeed + - EMAIL=test@example.com + - ENABLE_ID_OBFUSCATION=true + - MODE=standalone + - REDACT_IP_ADDRESSES=true + - TELEMETRY=true + ports: + - 9125:8080 + speedtest-alpine-mysql: + build: + context: ../.. + dockerfile: Dockerfile.alpine + environment: *env_vars_mysql + ports: + - 9126:8080 From 6406d06a33275cb9c1b23956cb003e5c389a1349 Mon Sep 17 00:00:00 2001 From: Stefan S Date: Sat, 26 Oct 2024 17:17:47 +0200 Subject: [PATCH 4/5] fix sqlite in alpine --- Dockerfile.alpine | 2 ++ docker/entrypoint.sh | 30 +++++++++++++++++++++--------- docker/test/docker-compose.yml | 24 ++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/Dockerfile.alpine b/Dockerfile.alpine index bc0f7464d..d06daa5dd 100755 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -54,6 +54,8 @@ ENV WEBPORT=8080 # https://httpd.apache.org/docs/2.4/stopping.html#gracefulstop STOPSIGNAL SIGWINCH +WORKDIR /var/www/html + # Final touches EXPOSE ${WEBPORT} CMD ["bash", "/entrypoint.sh"] diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index f1eac4f22..96c19460f 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -3,6 +3,10 @@ set -e set -x +is_alpine() { + [ -f /etc/alpine-release ] +} + # Cleanup rm -rf /var/www/html/* @@ -13,7 +17,7 @@ cp /speedtest/*.js /var/www/html/ cp /speedtest/favicon.ico /var/www/html/ # Set custom webroot on alpine -if [ -f /etc/alpine-release ]; then +if is_alpine; then sed -i "s#\"/var/www/localhost/htdocs\"#\"/var/www/html\"#g" /etc/apache2/httpd.conf fi @@ -38,7 +42,7 @@ if [ "$MODE" != "backend" ]; then fi # Apply Telemetry settings when running in standalone or frontend mode and telemetry is enabled -if [[ "$TELEMETRY" == "true" && ( "$MODE" == "frontend" || "$MODE" == "standalone" || "$MODE" == "dual" ) ]]; then +if [[ "$TELEMETRY" == "true" && ("$MODE" == "frontend" || "$MODE" == "standalone" || "$MODE" == "dual") ]]; then cp -r /speedtest/results /var/www/html/results if [ "$MODE" == "frontend" ]; then @@ -46,16 +50,16 @@ if [[ "$TELEMETRY" == "true" && ( "$MODE" == "frontend" || "$MODE" == "standalon cp /speedtest/backend/getIP_util.php /var/www/html/backend fi - if [ "$DB_TYPE" == "mysql" ]; then + if [ "$DB_TYPE" == "mysql" ]; then sed -i 's/$db_type = '\''.*'\''/$db_type = '\'$DB_TYPE\''/g' /var/www/html/results/telemetry_settings.php sed -i 's/$MySql_username = '\''.*'\''/$MySql_username = '\'$DB_USERNAME\''/g' /var/www/html/results/telemetry_settings.php sed -i 's/$MySql_password = '\''.*'\''/$MySql_password = '\'$DB_PASSWORD\''/g' /var/www/html/results/telemetry_settings.php sed -i 's/$MySql_hostname = '\''.*'\''/$MySql_hostname = '\'$DB_HOSTNAME\''/g' /var/www/html/results/telemetry_settings.php sed -i 's/$MySql_databasename = '\''.*'\''/$MySql_databasename = '\'$DB_NAME\''/g' /var/www/html/results/telemetry_settings.php - if [ "$DB_PORT" != "" ]; then + if [ "$DB_PORT" != "" ]; then sed -i 's/$MySql_port = '\''.*'\''/$MySql_port = '\'$DB_PORT\''/g' /var/www/html/results/telemetry_settings.php fi - elif [ "$DB_TYPE" == "postgresql" ]; then + elif [ "$DB_TYPE" == "postgresql" ]; then sed -i 's/$db_type = '\''.*'\''/$db_type = '\'$DB_TYPE\''/g' /var/www/html/results/telemetry_settings.php sed -i 's/$PostgreSql_username = '\''.*'\''/$PostgreSql_username = '\'$DB_USERNAME\''/g' /var/www/html/results/telemetry_settings.php 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 fi mkdir -p /database/ - chown www-data /database/ + if is_alpine; then + chown apache /database/ + else + chown www-data /database/ + fi fi -chown -R www-data /var/www/html/* +if is_alpine; then + chown -R apache /var/www/html/* +else + chown -R www-data /var/www/html/* +fi # Allow selection of Apache port for network_mode: host if [ "$WEBPORT" != "80" ]; then - if [ -f /etc/alpine-release ]; then + if is_alpine; then sed -i "s/^Listen 80\$/Listen $WEBPORT/g" /etc/apache2/httpd.conf else sed -i "s/^Listen 80\$/Listen $WEBPORT/g" /etc/apache2/ports.conf @@ -95,7 +107,7 @@ fi echo "Done, Starting APACHE" # This runs apache -if [ -f /etc/alpine-release ]; then +if is_alpine; then exec httpd -DFOREGROUND else exec apache2-foreground diff --git a/docker/test/docker-compose.yml b/docker/test/docker-compose.yml index b6421c9a6..918fe74a7 100644 --- a/docker/test/docker-compose.yml +++ b/docker/test/docker-compose.yml @@ -78,3 +78,27 @@ services: environment: *env_vars_mysql ports: - 9126:8080 + + ###### SQLITE ###### + speedtest-debian-sqlite: + # check at http://localhost:9125/results/sanitycheck.php + build: + context: ../.. + dockerfile: Dockerfile + environment: &env_vars_sqlite + - PASSWORD=gimmeTheStats1337 + - EMAIL=test@example.com + - ENABLE_ID_OBFUSCATION=true + - MODE=standalone + - REDACT_IP_ADDRESSES=true + - TELEMETRY=true + ports: + - 9127:8080 + + speedtest-alpine-sqlite: + build: + context: ../.. + dockerfile: Dockerfile.alpine + environment: *env_vars_sqlite + ports: + - 9128:8080 From a964e3c975661a31e3d8529f4e224b92f9aa06a4 Mon Sep 17 00:00:00 2001 From: Stefan S Date: Sat, 26 Oct 2024 18:12:30 +0200 Subject: [PATCH 5/5] change from pr#671 --- docker/ui.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker/ui.php b/docker/ui.php index 90feb5a8e..2d0723540 100755 --- a/docker/ui.php +++ b/docker/ui.php @@ -9,7 +9,7 @@ function I(i){return document.getElementById(i);} //LIST OF TEST SERVERS. See documentation for details if needed - var SPEEDTEST_SERVERS=[]; @@ -400,6 +400,7 @@ function initUI(){ html,body,#loading{ background:#202020; color:#F4F4F4; + color-scheme:dark; } h1{ color:#E0E0E0;