The dev directory now holds source code + compiled binaries only:
~/trips/osm/ OSM PBF extracts (was osm/, 1.4 GB)
~/trips/tilecache/ mock tile cache (was mock/.tilecache)
~/trips/store/mock/ per-trip uploads + chat logs (was mock/store, PII)
~/trips/logs/ server.log
~/trips/stale-osm-build/ stale source/tarball dup of ~/osm-build
(repo osm/build had no binaries; the live OSRM
toolchain + graphs already lived in ~/osm-build)
Code now points at the new locations, all overridable via env:
- mock/server.js: TRIPS_HOME (default ~/trips) for tile cache + store
- setup-osrm.sh / setup-osrm-colombia.sh: OSM_DIR (default ~/trips/osm)
- spatial/compose+import.sh: OSM_DIR (default ~/trips/osm)
- .gitignore: rewritten — no artifact paths remain in-tree
55 lines
2.1 KiB
Bash
Executable File
55 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Import an OSM PBF extract into the local PostGIS stack via osm2pgsql.
|
|
#
|
|
# ./import.sh [file.osm.pbf] [extract-name]
|
|
#
|
|
# file.osm.pbf default: $OSM_DIR/nh.osm.pbf (OSM_DIR defaults to
|
|
# ~/trips/osm — the PBFs live outside the dev tree)
|
|
# extract-name default: basename without extension
|
|
#
|
|
# The PBF must be readable by uid 1001 (the osm2pgsql image user) — the
|
|
# script bind-mounts its directory read-only. After the load, the poi
|
|
# table is refreshed (refresh_poi()) and the spatial_extract row updated.
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")"
|
|
|
|
OSM_DIR="${OSM_DIR:-$HOME/trips/osm}"
|
|
PBF=${1:-$OSM_DIR/nh.osm.pbf}
|
|
NAME=${2:-$(basename "${PBF%.osm.pbf}")}
|
|
ABS=$(realpath "$PBF")
|
|
[[ -f $ABS ]] || { echo "no such PBF: $ABS" >&2; exit 1; }
|
|
|
|
# 1. DB up (first boot runs schema.sql)
|
|
docker compose up -d postgis
|
|
echo "waiting for postgis to be healthy…"
|
|
for i in $(seq 1 60); do
|
|
if docker compose exec -T postgis pg_isready -U trips -d trips >/dev/null 2>&1; then break; fi
|
|
sleep 2
|
|
[[ $i -eq 60 ]] && { echo "postgis never became healthy" >&2; exit 1; }
|
|
done
|
|
|
|
# 2. osm2pgsql load (one-shot container, PBF bind-mounted ro)
|
|
docker run --rm \
|
|
--user 1001:1001 \
|
|
--network "trips_default" \
|
|
-v "$(dirname "$ABS"):/data:ro" \
|
|
-e PBF_FILE="/data/$(basename "$ABS")" \
|
|
-e ARGS="--host=postgis --port=5432 --database=trips --user=trips --password=trips \
|
|
--create --clean --slim --flat-nodes=/tmp/flat.nodes --disable-operations" \
|
|
osm2pgsql/osm2pgsql:16
|
|
|
|
# 3. refresh the queryable poi table + extract bookkeeping
|
|
docker compose exec -T postgis psql -U trips -d trips -v ON_ERROR_STOP=1 <<SQL
|
|
INSERT INTO spatial_extract (name) VALUES ('${NAME}')
|
|
ON CONFLICT (name) DO NOTHING;
|
|
SELECT refresh_poi('${NAME}');
|
|
SQL
|
|
|
|
# 4. report
|
|
docker compose exec -T postgis psql -U trips -d trips -c \
|
|
"SELECT name, poi_count, to_char(imported_at,'YYYY-MM-DD HH24:MI') AS imported
|
|
FROM spatial_extract ORDER BY name;"
|
|
|
|
echo "done — extract '$NAME' is queryable. Start the service:"
|
|
echo " docker compose up -d spatiald # :5005, proxied by the mock server at /spatial/*"
|