trips/spatial/docker-compose.yml
Greg Pomerantz d05ebfa72f PostGIS: live — imports, spatiald, and fixes from real runs
Ran the full stack (docker now available via sg docker):
- postgis/postgis:16-3.4 up, both extracts imported:
  northeast 291,000 POIs (from ~/osm-build/data/northeast.osm.pbf),
  colombia 228,446 POIs
- spatiald live on :5005, proxied by the mock server (/spatial/*,
  /spatial-status); UI badge + poi_near tool activate automatically

Fixes discovered by running against real data:
- osm2pgsql image: osm2pgsql/osm2pgsql does not exist on Docker Hub —
  use iboates/osm2pgsql, bypass its DB-probing entrypoint (--entrypoint
  osm2pgsql), password via PGPASSWORD (this build's --password flag
  forces an interactive prompt)
- osm2pgsql 2.x schema: planet_osm_point/_polygon (not _node/_way),
  geometry in EPSG:3857 'way' column, -k hstore for opening_hours/
  fee/website/addr:*, refresh_poi() dedupes relation polygons and
  uses hstore -> (not ->>)
- compose file downgraded to v1-compatible 3.8 (host has docker-compose
  1.29, no v2 plugin); OSM_DIR exported by import.sh
- spatiald: proper SQL parameterization (@@i@@ tokens, body ..
  shifted past the filter args — the first renumber attempt was
  unsound), ST_Distance(geography) instead of the geometry-only
  ST_Distance_Sphere, 4-arg ST_DWithin for the corridor band, WKT in
  lng lat order, kind= accepts exact (amenity=restaurant), bare tag
  value (restaurant) or family (tourism)
- mock server /spatial proxy: forward u.search (was dropping it)
- app.js poi_near: 'points' param, semicolons must be %3B-encoded
  (Go url.Parse drops the tail of a value containing a raw ';')
- README: osm2pgsql 2.x data notes + kind semantics
2026-09-10 12:23:49 -04:00

60 lines
2.0 KiB
YAML

# PostGIS spatial stack for the trip planner.
#
# docker-compose up -d postgis # start the DB (schema.sql runs on first boot)
# ./import.sh ~/trips/osm/nh.osm.pbf nh # import an OSM extract (one-shot osm2pgsql)
# docker-compose up -d spatiald # start the query service on :5005
#
# Composed for docker-compose v1 (3.8) AND v2 (the same file works with
# `docker compose` once the v2 plugin is available): no healthchecks or
# `depends_on` conditions — import.sh polls pg_isready itself, and spatiald
# tolerates a not-yet-ready DB at boot.
#
# OSM_DIR (default ~/trips/osm) is where the PBF extracts live — outside the
# dev tree. Export it to override.
version: "3.8"
services:
postgis:
image: postgis/postgis:16-3.4
container_name: trips-postgis
environment:
POSTGRES_DB: trips
POSTGRES_USER: trips
POSTGRES_PASSWORD: trips
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
# initdb scripts run in lexicographic order, once, on an empty volume
- ./schema.sql:/docker-entrypoint-initdb.d/10-schema.sql:ro
restart: unless-stopped
# One-shot importer (also usable as: docker-compose run --rm importer
# -- /data/<file>.osm.pbf ...). import.sh does the same with a bare
# `docker run`, since the PBF path varies per import.
importer:
image: iboates/osm2pgsql:latest
entrypoint: osm2pgsql
environment:
PGPASSWORD: trips # the image build's --password flag forces a prompt
command: >-
/data/colombia.osm.pbf --host=postgis --port=5432 --database=trips
--user=trips -k --slim
--flat-nodes=/tmp/flat.nodes
network_mode: "service:postgis"
volumes:
- ${OSM_DIR}:/data:ro # OSM_DIR is exported by import.sh (default ~/trips/osm)
spatiald:
build: .
container_name: trips-spatiald
environment:
SPATIAL_DSN: "host=postgis port=5432 user=trips password=trips dbname=trips sslmode=disable"
ports:
- "5005:5005"
depends_on:
- postgis
restart: unless-stopped
volumes:
pgdata: