speedtest/Dockerfile.alpine
Akira Yamamoto 3b3cddeb41 fix(docker): raise PHP post_max_size for default 20MB upload chunks
speedtest_worker.js uploads in 20 MB chunks by default
(xhr_ul_blob_megabytes: 20) but the official Docker images inherit
PHP's stock post_max_size = 8M / upload_max_filesize = 2M, so every
upload chunk:

* triggers a "POST Content-Length ... exceeds the limit" warning
  (leaked into the response body of /backend/empty.php on the Debian
  variant where display_errors is on; suppressed but still emitted on
  Alpine where it's off);
* causes empty.php's subsequent header() calls to fail with "Cannot
  modify header information - headers already sent", leaving the
  response without proper status, cache, or CORS directives.

Ship a small docker/librespeed-php.ini with post_max_size = 32M,
upload_max_filesize = 32M, memory_limit = 256M and COPY it into the
right conf.d for each base image (/usr/local/etc/php/conf.d on
Debian, /etc/php84/conf.d on Alpine). 99- prefix follows the
NN-name.ini packaging convention so this loads after distro defaults
but never silently shadows operator overrides.

Verified post-fix on both variants: a 20 MB POST to /backend/empty.php
returns HTTP 200 / 0 bytes with no warning leakage.
2026-06-09 18:06:14 +10:00

80 lines
2.3 KiB
Text
Executable file

FROM alpine:3.23
RUN apk add --quiet --no-cache \
bash \
apache2 \
ca-certificates \
php \
php-apache2 \
php-ctype \
php-phar \
php-gd \
php-openssl \
php-pdo \
php-pdo_mysql \
php-pdo_pgsql \
php-pdo_sqlite \
php-pgsql \
php-session \
php-sqlite3
RUN ln -sf /dev/stdout /var/log/apache2/access.log && \
ln -sf /dev/stderr /var/log/apache2/error.log
COPY docker/librespeed-php.ini /tmp/librespeed-php.ini
RUN scan_dir="$(/usr/bin/php -r 'echo rtrim(PHP_CONFIG_FILE_SCAN_DIR);')" \
&& [ -n "$scan_dir" ] \
&& install -D -m 0644 /tmp/librespeed-php.ini "$scan_dir/99-librespeed.ini" \
&& rm /tmp/librespeed-php.ini
# Prepare files and folders
RUN mkdir -p /speedtest/
# Copy sources
COPY backend/ /speedtest/backend
COPY frontend/ /speedtest/frontend
COPY results/*.php /speedtest/results/
COPY results/*.ttf /speedtest/results/
COPY *.js /speedtest/
COPY index.html /speedtest/
COPY index-classic.html /speedtest/
COPY index-modern.html /speedtest/
COPY config.json /speedtest/
COPY stability.html /speedtest/
COPY favicon.ico /speedtest/
COPY docker/entrypoint.sh /
# Prepare default environment variables
ENV TITLE=LibreSpeed
ENV TAGLINE="No Flash, No Java, No Websockets, No Bullsh*t"
ENV MODE=standalone
ENV PASSWORD=password
ENV TELEMETRY=false
ENV ENABLE_ID_OBFUSCATION=false
ENV REDACT_IP_ADDRESSES=false
ENV WEBPORT=8080
ENV USE_NEW_DESIGN=false
# https://httpd.apache.org/docs/2.4/stopping.html#gracefulstop
STOPSIGNAL SIGWINCH
# Add labels for better metadata
LABEL org.opencontainers.image.title="LibreSpeed"
LABEL org.opencontainers.image.description="A Free and Open Source speed test that you can host on your server(s)"
LABEL org.opencontainers.image.vendor="LibreSpeed"
LABEL org.opencontainers.image.url="https://github.com/librespeed/speedtest"
LABEL org.opencontainers.image.source="https://github.com/librespeed/speedtest"
LABEL org.opencontainers.image.documentation="https://github.com/librespeed/speedtest/blob/master/doc_docker.md"
LABEL org.opencontainers.image.licenses="LGPL-3.0-or-later"
# Add health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:${WEBPORT}/ || exit 1
WORKDIR /var/www/html
# Final touches
EXPOSE ${WEBPORT}
CMD ["bash", "/entrypoint.sh"]