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
This commit is contained in:
Dennis Boldt 2022-01-02 13:39:07 +01:00 committed by Paul Bienkowski
parent 85911a2c97
commit 12224db3b9
4 changed files with 27 additions and 9 deletions

View file

@ -91,7 +91,8 @@ ADD api/obs /opt/obs/api/obs/
ADD api/tools /opt/obs/api/tools/ ADD api/tools /opt/obs/api/tools/
RUN pip install -e /opt/obs/api/ 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=frontend-builder /opt/obs/frontend/build /opt/obs/frontend/build
COPY --from=osm2pgsql-builder /usr/local/bin/osm2pgsql /usr/local/bin/osm2pgsql COPY --from=osm2pgsql-builder /usr/local/bin/osm2pgsql /usr/local/bin/osm2pgsql

View file

@ -78,22 +78,30 @@ sure to configure:
### Prepare database ### Prepare database
Follow the procedure outlined in [README.md](../README.md) under "Prepare Run the following two scripts to prepare the database:
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:
```bash ```bash
# development docker-compose run --rm portal tools/reset_database.py
docker-compose run --rm api tools/prepare_sql_tiles.py
# production
docker-compose run --rm portal tools/prepare_sql_tiles.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 ### 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 ### Configure portal

View file

@ -23,10 +23,16 @@ services:
image: openbikesensor-portal image: openbikesensor-portal
build: build:
context: ./source context: ./source
environment:
POSTGRES_HOST: postgres
POSTGRES_USER: obs
POSTGRES_PASSWORD: obs
POSTGRES_DB: obs
volumes: volumes:
- ./data/api-data:/data - ./data/api-data:/data
- ./config/config.py:/opt/obs/api/config.py - ./config/config.py:/opt/obs/api/config.py
- ./data/tiles/:/tiles - ./data/tiles/:/tiles
- ./data/pbf/:/pbf
restart: on-failure restart: on-failure
depends_on: depends_on:
- postgres - postgres

3
osm2pgsql.sh Executable file
View file

@ -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