From 12224db3b918122edf6fd47215d5b172d96ef542 Mon Sep 17 00:00:00 2001 From: Dennis Boldt Date: Sun, 2 Jan 2022 13:39:07 +0100 Subject: [PATCH] Use osm2pgsql.sh to import osm data into the database with the portal image - Added POSTGRES env-vars to the portal (only handled by osm2pgsql.sh until now) - Added ./data/pbf:/pbf as host volume mount to the portal - Added osm2pgsql.sh, which ueses the env-vars and pbf-mount to import the osm data into the database --- Dockerfile | 3 ++- deployment/README.md | 24 ++++++++++++++++-------- deployment/examples/docker-compose.yaml | 6 ++++++ osm2pgsql.sh | 3 +++ 4 files changed, 27 insertions(+), 9 deletions(-) create mode 100755 osm2pgsql.sh diff --git a/Dockerfile b/Dockerfile index c0dac0c..b6c4ecb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -91,7 +91,8 @@ ADD api/obs /opt/obs/api/obs/ ADD api/tools /opt/obs/api/tools/ RUN pip install -e /opt/obs/api/ -ADD roads_import.lua /opt/obs/api/roads_import.lua +ADD roads_import.lua /opt/obs/api/tools +ADD osm2pgsql.sh /opt/obs/api/tools COPY --from=frontend-builder /opt/obs/frontend/build /opt/obs/frontend/build COPY --from=osm2pgsql-builder /usr/local/bin/osm2pgsql /usr/local/bin/osm2pgsql diff --git a/deployment/README.md b/deployment/README.md index 656a523..f60e094 100644 --- a/deployment/README.md +++ b/deployment/README.md @@ -78,22 +78,30 @@ sure to configure: ### Prepare database -Follow the procedure outlined in [README.md](../README.md) under "Prepare -database". Whenever the docker-compose service `api` is referenced, replace it -with `portal`, which contains the same python code as the development `api` -service, but also the frontend. For example: +Run the following two scripts to prepare the database: ```bash -# development -docker-compose run --rm api tools/prepare_sql_tiles.py -# production +docker-compose run --rm portal tools/reset_database.py docker-compose run --rm portal tools/prepare_sql_tiles.py ``` +For more details, see [README.md](../README.md) under "Prepare database". + ### Import OpenStreetMap data -Follow the procedure outlined in [README.md](../README.md) under "Import OpenStreetMap data". +First of all, download the area(s) you would like to import from [GeoFabrik](https://download.geofabrik.de) into `data/pbf`, for example: +```bash +wget https://download.geofabrik.de/europe/germany/schleswig-holstein-latest.osm.pbf -P data/pbf +``` + +Afterwards,run the following script: + +``` +docker-compose run --rm portal tools/osm2pgsql.sh +``` + +For more details. see [README.md](../README.md) under "Import OpenStreetMap data". ### Configure portal diff --git a/deployment/examples/docker-compose.yaml b/deployment/examples/docker-compose.yaml index 40e09d7..a23621f 100644 --- a/deployment/examples/docker-compose.yaml +++ b/deployment/examples/docker-compose.yaml @@ -23,10 +23,16 @@ services: image: openbikesensor-portal build: context: ./source + environment: + POSTGRES_HOST: postgres + POSTGRES_USER: obs + POSTGRES_PASSWORD: obs + POSTGRES_DB: obs volumes: - ./data/api-data:/data - ./config/config.py:/opt/obs/api/config.py - ./data/tiles/:/tiles + - ./data/pbf/:/pbf restart: on-failure depends_on: - postgres diff --git a/osm2pgsql.sh b/osm2pgsql.sh new file mode 100755 index 0000000..0ca1fa7 --- /dev/null +++ b/osm2pgsql.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo $POSTGRES_PASSWORD | osm2pgsql --create --hstore --style tools/roads_import.lua -O flex -H $POSTGRES_HOST -d $POSTGRES_DB -U $POSTGRES_USER -W /pbf/*.osm.pbf