commit cc7e7302951ce1f036329a036d54d991d24c62b0 Author: Knut Ahlers Date: Fri Jul 17 00:58:22 2020 +0200 Initial version diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4d195c9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +FROM golang:alpine as builder + +ENV GCO_ENABLED=0 + +ARG VERSION=v1.0.1 + +RUN set -ex \ + && apk add \ + curl \ + git \ + && git clone "https://github.com/librespeed/speedtest-go.git" /src \ + && cd /src \ + && git reset --hard "${VERSION}" \ + && go build \ + -o speedtest \ + -mod=readonly \ + && curl -sSfLo dumb-init "https://github.com/Yelp/dumb-init/releases/download/v1.2.2/dumb-init_1.2.2_amd64" \ + && install -D -m755 -t /build/usr/local/bin \ + dumb-init \ + speedtest \ + && install -D -t /build/usr/local/share/speedtest/ \ + assets/* \ + && mkdir -p /build/etc/speedtest \ + && touch /build/etc/speedtest/.keep + + +FROM alpine + +RUN set -ex \ + && apk --no-cache add \ + bash \ + coreutils + +COPY --from=builder /build/ / +COPY docker-entrypoint.sh /usr/local/bin/ + +EXPOSE 8989 +VOLUME ["/data"] +WORKDIR /etc/speedtest + +ENTRYPOINT ["/usr/local/bin/dumb-init"] +CMD ["/bin/bash", "/usr/local/bin/docker-entrypoint.sh"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1510c0d --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +README.md: + cp README.tpl.md README.md + grep -Eo '\$$\{[A-Z][^\}]*\}' docker-entrypoint.sh | sed -E 's/\$$\{([^:]*)(|:-(.*))\}/| \1 | `\3` |/' | sort | uniq >>README.md + +.PHONY: README.md + +auto-hook-pre-commit: README.md + git add README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..9433b94 --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +# Luzifer-docker / librespeed + +This is a container setup for the Go variant of the LibreSpeed speed test, fully configurable through environment variables and runnable out-of-the-box. + +## Available configuration variables + +| ENV Variable | Default Value | +| ------------ | ------------- | +| ASSETS_PATH | `/usr/local/share/speedtest` | +| BIND_ADDR | `` | +| DB_FILE | `/data/speedtest.db` | +| DB_HOST | `` | +| DB_NAME | `` | +| DB_PASS | `` | +| DB_TYPE | `bolt` | +| DB_USER | `` | +| IPINFO_API_KEY | `` | +| LISTEN_PORT | `8989` | +| REDACT_IP_ADDRESSES | `true` | +| SERVER_LAT | `0` | +| SERVER_LON | `0` | +| STATISTICS_PASSWORD | `` | diff --git a/README.tpl.md b/README.tpl.md new file mode 100644 index 0000000..5eac984 --- /dev/null +++ b/README.tpl.md @@ -0,0 +1,8 @@ +# Luzifer-docker / librespeed + +This is a container setup for the Go variant of the LibreSpeed speed test, fully configurable through environment variables and runnable out-of-the-box. + +## Available configuration variables + +| ENV Variable | Default Value | +| ------------ | ------------- | diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..ef9a0ce --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,47 @@ +#!/bin/bash +set -euo pipefail + +config_file="/etc/speedtest/settings.toml" +rand_pass=$(head -c 50 /dev/urandom | sha1sum | cut -d ' ' -f 1) + +if [ -f "${config_file}" ]; then + echo "Found configuration in ${config_file}, ENV is not used" +else + [[ -n ${STATISTICS_PASSWORD:-} ]] || { + STATISTICS_PASSWORD=${rand_pass} + echo "/!\\ For security reasons random statistics password has been set: ${rand_pass}" + } + + cat -s <${config_file} +# bind address, use empty string to bind to all interfaces +bind_address="${BIND_ADDR:-}" +# backend listen port +listen_port=${LISTEN_PORT:-8989} +# Server location +server_lat=${SERVER_LAT:-0} +server_lng=${SERVER_LON:-0} +# ipinfo.io API key, if applicable +ipinfo_api_key="${IPINFO_API_KEY:-}" + +# assets directory path, defaults to \$(assets) in the same directory +assets_path="${ASSETS_PATH:-/usr/local/share/speedtest}" + +# password for logging into statistics page +statistics_password="${STATISTICS_PASSWORD}" +# redact IP addresses +redact_ip_addresses=${REDACT_IP_ADDRESSES:-true} + +# database type for statistics data, currently supports: bolt, mysql, postgresql +database_type="${DB_TYPE:-bolt}" +database_hostname="${DB_HOST:-}" +database_name="${DB_NAME:-}" +database_username="${DB_USER:-}" +database_password="${DB_PASS:-}" + +# if you use \$(bolt) as database, set database_file to database file location +database_file="${DB_FILE:-/data/speedtest.db}" +EOF + +fi + +exec /usr/local/bin/speedtest