Add OSRM and OTP Docker services with setup scripts

Adds osrm-foot, osrm-bicycle, and otp services to Docker Compose under
a 'routing' profile (opt-in). Setup scripts download Greater London OSM
data and pre-process for OSRM foot/bicycle profiles, plus TfL GTFS for
OTP transit. Routing engine env vars added to .env.sample.
This commit is contained in:
Viktor Barzin 2026-02-08 13:16:10 +00:00
parent 149311508e
commit bb489c2032
No known key found for this signature in database
GPG key ID: 0EB088298288D958
4 changed files with 220 additions and 0 deletions

94
scripts/otp-setup.sh Executable file
View file

@ -0,0 +1,94 @@
#!/usr/bin/env bash
# OpenTripPlanner data setup script for Greater London
# Downloads OSM extract and TfL GTFS feeds for transit routing.
#
# Usage:
# ./scripts/otp-setup.sh [DATA_DIR]
#
# DATA_DIR defaults to ./otp-data/
# The directory is suitable for mounting as /var/opentripplanner in OTP container.
set -euo pipefail
DATA_DIR="${1:-./otp-data}"
GEOFABRIK_URL="https://download.geofabrik.de/europe/great-britain/england/greater-london-latest.osm.pbf"
OSM_FILE="greater-london-latest.osm.pbf"
# TfL GTFS feeds (Bus Open Data Service + TfL open data)
# These URLs may need updating; check https://data.bus-data.dft.gov.uk/ and TfL API
TFL_GTFS_URLS=(
"https://data.bus-data.dft.gov.uk/timetable/download/gtfs-file/london/"
)
echo "==> OTP Setup for Greater London"
echo " Data directory: ${DATA_DIR}"
mkdir -p "${DATA_DIR}"
# Download OSM extract
if [ ! -f "${DATA_DIR}/${OSM_FILE}" ]; then
echo "==> Downloading Greater London OSM extract..."
curl -L -o "${DATA_DIR}/${OSM_FILE}" "${GEOFABRIK_URL}"
else
echo "==> OSM extract already downloaded"
fi
# Download GTFS feeds
for i in "${!TFL_GTFS_URLS[@]}"; do
GTFS_FILE="gtfs-london-${i}.zip"
if [ ! -f "${DATA_DIR}/${GTFS_FILE}" ]; then
echo "==> Downloading GTFS feed ${i}..."
curl -L -o "${DATA_DIR}/${GTFS_FILE}" "${TFL_GTFS_URLS[$i]}" || {
echo " WARNING: Failed to download GTFS feed from ${TFL_GTFS_URLS[$i]}"
echo " You may need to manually download GTFS data."
echo " Check: https://data.bus-data.dft.gov.uk/"
echo " Place .zip files in ${DATA_DIR}/"
}
else
echo "==> GTFS feed ${i} already downloaded"
fi
done
# Create OTP build config if not present
if [ ! -f "${DATA_DIR}/build-config.json" ]; then
echo "==> Creating OTP build config..."
cat > "${DATA_DIR}/build-config.json" << 'EOF'
{
"osm": [
{
"source": "greater-london-latest.osm.pbf"
}
],
"transitFeeds": [
{
"type": "gtfs",
"source": "gtfs-london-0.zip"
}
]
}
EOF
fi
# Create OTP router config if not present
if [ ! -f "${DATA_DIR}/router-config.json" ]; then
echo "==> Creating OTP router config..."
cat > "${DATA_DIR}/router-config.json" << 'EOF'
{
"routingDefaults": {
"walkSpeed": 1.3,
"bikeSpeed": 5.0,
"numItineraries": 3
}
}
EOF
fi
echo ""
echo "==> OTP setup complete!"
echo " Mount ${DATA_DIR} as /var/opentripplanner in OTP container."
echo ""
echo " OTP will build the transit graph on first startup (~2 min for London)."
echo ""
echo " Example:"
echo " docker run -p 8080:8080 -v ${DATA_DIR}:/var/opentripplanner \\"
echo " opentripplanner/opentripplanner:2.6.0 --load --serve"