trails/docker/brouter/Dockerfile
Ullrich Schäfer 46743a91db
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>
2026-05-08 00:43:43 +02:00

60 lines
2.8 KiB
Docker

FROM eclipse-temurin:11-jre-jammy
WORKDIR /brouter
# Download latest BRouter release
ARG BROUTER_VERSION=1.7.9
RUN apt-get update && apt-get install -y --no-install-recommends wget unzip curl \
&& wget -q "https://github.com/abrensch/brouter/releases/download/v${BROUTER_VERSION}/brouter-${BROUTER_VERSION}.zip" \
&& unzip "brouter-${BROUTER_VERSION}.zip" \
&& mv "brouter-${BROUTER_VERSION}"/* . \
&& rmdir "brouter-${BROUTER_VERSION}" \
&& rm "brouter-${BROUTER_VERSION}.zip" \
&& 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 \
&& 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 \
&& mv brouter-*-all.jar brouter.jar
# Patch profiles to include extra tags in WayTags output for visualization
# Each tag needs its own assign statement to appear in tiledesc WayTags
RUN for f in /data/profiles/*.brf; do \
if grep -q "dummyUsage" "$f"; then \
grep -q "maxspeed" "$f" || sed -i '/assign dummyUsage/a assign dummyUsage2 = maxspeed=' "$f"; \
grep -q "tracktype" "$f" || sed -i '/assign dummyUsage/a assign dummyUsage3 = tracktype=' "$f"; \
elif grep -q "context:node" "$f"; then \
sed -i '/---context:node/i assign dummyUsage2 = maxspeed=\nassign dummyUsage3 = tracktype=' "$f"; \
fi; \
done
USER app
EXPOSE 17777
# JAVA_OPTS can be overridden at runtime (e.g., `-Xmx8g` for planet-scale).
# The default keeps the flagship's single-instance footprint small.
ENV JAVA_OPTS="-Xmx1024M -Xms256M -Xmn64M"
# Routing thread pool. When saturated, BRouter's thread-priority watchdog
# kills the oldest in-flight request ("contention! ms killed …") to free a
# thread for the new one — the caller then sees a cancelled response. Bump
# this on hosts with spare cores/RAM to absorb burst traffic. Planet host
# 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>
CMD ["sh", "-c", "java $JAVA_OPTS -DmaxRunningTime=300 -cp brouter.jar btools.server.RouteServer /data/segments /data/profiles /data/profiles 17777 $BROUTER_THREADS"]