Initial version

This commit is contained in:
Knut Ahlers 2020-07-17 00:58:22 +02:00
commit cc7e730295
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
5 changed files with 127 additions and 0 deletions

42
Dockerfile Normal file
View file

@ -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"]

8
Makefile Normal file
View file

@ -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

22
README.md Normal file
View file

@ -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 | `` |

8
README.tpl.md Normal file
View file

@ -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 |
| ------------ | ------------- |

47
docker-entrypoint.sh Normal file
View file

@ -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 <<EOF >${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