Merge pull request #363 from trails-cool/brouter-auto-segments

Auto-download BRouter segments on first container start
This commit is contained in:
Ullrich Schäfer 2026-05-08 00:47:17 +02:00 committed by GitHub
commit ddbf95f6bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 7 deletions

View file

@ -10,11 +10,17 @@ RUN apt-get update && apt-get install -y --no-install-recommends wget unzip curl
&& mv "brouter-${BROUTER_VERSION}"/* . \
&& rmdir "brouter-${BROUTER_VERSION}" \
&& rm "brouter-${BROUTER_VERSION}.zip" \
&& apt-get purge -y wget unzip && apt-get autoremove -y && rm -rf /var/lib/apt/lists/*
&& apt-get purge -y unzip && apt-get autoremove -y && rm -rf /var/lib/apt/lists/*
# Create non-root user and directories for segments and profiles
RUN addgroup --system app && adduser --system --ingroup app app \
&& mkdir -p /data/segments /data/profiles
&& mkdir -p /data/segments /data/profiles \
&& chown -R app:app /data
# Install entrypoint + segment downloader
COPY download-segments.sh /brouter/download-segments.sh
COPY entrypoint.sh /brouter/entrypoint.sh
RUN chmod +x /brouter/download-segments.sh /brouter/entrypoint.sh
# Copy default profiles from release and rename JAR for simpler CMD
RUN cp -r profiles2/* /data/profiles/ 2>/dev/null || true \
@ -45,9 +51,10 @@ ENV JAVA_OPTS="-Xmx1024M -Xms256M -Xmn64M"
# sets it to 16; flagship/CI keep the default.
ENV BROUTER_THREADS=4
# Entrypoint downloads segments on first start if /data/segments is empty,
# then execs the CMD. Shell form on CMD so $JAVA_OPTS / $BROUTER_THREADS
# expand at container start.
ENTRYPOINT ["/brouter/entrypoint.sh"]
# BRouter server: <segmentdir> <profiledir> <customprofiledir> <port> <maxthreads>
# Shell form so $JAVA_OPTS and $BROUTER_THREADS expand at container start.
CMD java $JAVA_OPTS -DmaxRunningTime=300 -cp brouter.jar \
btools.server.RouteServer \
/data/segments /data/profiles /data/profiles \
17777 $BROUTER_THREADS
CMD ["sh", "-c", "java $JAVA_OPTS -DmaxRunningTime=300 -cp brouter.jar btools.server.RouteServer /data/segments /data/profiles /data/profiles 17777 $BROUTER_THREADS"]

16
docker/brouter/entrypoint.sh Executable file
View file

@ -0,0 +1,16 @@
#!/bin/bash
set -euo pipefail
SEGMENTS_DIR="/data/segments"
# Auto-populate segments on first start. The named volume is empty after
# `docker compose up`, which leaves BRouter returning 400 for every routing
# request. Downloading here means a fresh checkout works end-to-end without
# extra setup steps. On subsequent starts the rd5 files are already present
# and we skip straight to the server.
if ! ls "$SEGMENTS_DIR"/*.rd5 >/dev/null 2>&1; then
echo "No segments found in $SEGMENTS_DIR — downloading…"
/brouter/download-segments.sh "$SEGMENTS_DIR"
fi
exec "$@"