Auto-download BRouter segments on first container start

Fresh `pnpm dev:services` checkouts came up with an empty
brouter_segments volume, so every routing request returned
"datafile not found" and the e2e suite's BRouter tests failed.

Add an entrypoint that runs download-segments.sh when /data/segments
has no rd5 files, then exec's the existing server command. Subsequent
starts find the populated volume and skip straight to the server.
Keep wget in the final image (previously stripped) so the entrypoint
can fetch segments at runtime.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ullrich Schäfer 2026-05-08 00:43:43 +02:00
parent f1963aab7a
commit 46743a91db
No known key found for this signature in database
GPG key ID: A32FF691A0F752D9
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}"/* . \ && mv "brouter-${BROUTER_VERSION}"/* . \
&& rmdir "brouter-${BROUTER_VERSION}" \ && rmdir "brouter-${BROUTER_VERSION}" \
&& rm "brouter-${BROUTER_VERSION}.zip" \ && 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 # Create non-root user and directories for segments and profiles
RUN addgroup --system app && adduser --system --ingroup app app \ 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 # Copy default profiles from release and rename JAR for simpler CMD
RUN cp -r profiles2/* /data/profiles/ 2>/dev/null || true \ 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. # sets it to 16; flagship/CI keep the default.
ENV BROUTER_THREADS=4 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> # BRouter server: <segmentdir> <profiledir> <customprofiledir> <port> <maxthreads>
# Shell form so $JAVA_OPTS and $BROUTER_THREADS expand at container start. CMD ["sh", "-c", "java $JAVA_OPTS -DmaxRunningTime=300 -cp brouter.jar btools.server.RouteServer /data/segments /data/profiles /data/profiles 17777 $BROUTER_THREADS"]
CMD 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 "$@"