commit 546c010369823daa20abda94fd5efec7d283a6a2 Author: Andrei Dragulescu Date: Tue Nov 6 11:45:13 2018 +0200 initial commit diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f6b0afc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,50 @@ +FROM ubuntu:xenial + +LABEL andreimagic + +ENV DEBIAN_FRONTEND noninteractive +ENV LANG C.UTF-8 + +RUN apt-get -y update -qq && \ + apt-get -y install locales && \ + locale-gen en_US.UTF-8 && \ + update-locale LANG=en_US.UTF-8 && \ + apt-get install -y build-essential cmake g++ libboost-dev libboost-system-dev \ + libboost-filesystem-dev libexpat1-dev zlib1g-dev libxml2-dev\ + libbz2-dev libpq-dev libgeos-dev libgeos++-dev libproj-dev \ + postgresql-server-dev-9.5 postgresql-9.5-postgis-2.2 postgresql-contrib-9.5 \ + apache2 php php-pgsql libapache2-mod-php php-pear php-db \ + php-intl git curl sudo \ + python-pip libboost-python-dev \ + osmosis && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* && \ + rm -rf /tmp/* /var/tmp/* + +WORKDIR /app + +# Configure postgres +RUN echo "host all all 0.0.0.0/0 trust" >> /etc/postgresql/9.5/main/pg_hba.conf && \ + echo "listen_addresses='*'" >> /etc/postgresql/9.5/main/postgresql.conf + +# Nominatim install +ENV NOMINATIM_VERSION v3.1.0 +RUN git clone --recursive https://github.com/openstreetmap/Nominatim ./src +RUN cd ./src && git checkout tags/$NOMINATIM_VERSION && git submodule update --recursive --init && \ + mkdir build && cd build && cmake .. && make + +# Osmium install to run continuous updates +RUN pip install osmium + +# Apache configure +COPY local.php /app/src/build/settings/local.php +COPY nominatim.conf /etc/apache2/sites-enabled/000-default.conf + +# Load initial data +RUN curl http://www.nominatim.org/data/country_grid.sql.gz > /app/src/data/country_osm_grid.sql.gz + +EXPOSE 5432 +EXPOSE 8080 + +COPY start.sh /app/start.sh +COPY init.sh /app/init.sh \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..4485d6d --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +# Nominatim Docker (Nominatim version 3.1) + +1. Build + ``` + docker build -t nominatim . + ``` +2. Copy .osm.pbf to a local directory (i.e. /home/docker-volumes/nominatimdata) + +3. Initialize Nominatim Database + ``` + docker run -t -v /home/docker-volumes/nominatimdata:/data nominatim sh /app/init.sh /data/merged.osm.pbf postgresdata 4 + ``` + Where 4 is the number of threads to use during import, set this according to the host. + You can delete the `/home/docker-volumes/nominatimdata/merged.osm.pbf` once the import is finished. + +4. After the import is finished the `/home/docker-volumes/nominatimdata/postgresdata` folder will contain the full postgress binaries of a postgis/nominatim database. +Start the nominatim as a single node is the following: + ``` + docker run --restart=always -p 7070:8080 -d -v /home/docker-volumes/nominatimdata/postgresdata:/var/lib/postgresql/9.5/main nominatim sh /app/start.sh + ``` + +At this stage all database files are stored on the host and the containers are considered disposable. \ No newline at end of file diff --git a/init.sh b/init.sh new file mode 100644 index 0000000..abeca0d --- /dev/null +++ b/init.sh @@ -0,0 +1,23 @@ +OSMFILE=$1 +PGDIR=$2 +THREADS=$3 + +mkdir -p /data/$PGDIR && \ + +chown postgres:postgres /data/$PGDIR && \ + +export PGDATA=/data/$PGDIR && \ +sudo -u postgres /usr/lib/postgresql/9.5/bin/initdb -D /data/$PGDIR && \ +sudo -u postgres /usr/lib/postgresql/9.5/bin/pg_ctl -D /data/$PGDIR start && \ +sudo -u postgres psql postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='nominatim'" | grep -q 1 || sudo -u postgres createuser -s nominatim && \ +sudo -u postgres psql postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='www-data'" | grep -q 1 || sudo -u postgres createuser -SDR www-data && \ +sudo -u postgres psql postgres -c "DROP DATABASE IF EXISTS nominatim" && \ +useradd -m -p password1234 nominatim && \ +chown -R nominatim:nominatim ./src && \ +sudo -u nominatim ./src/build/utils/setup.php --osm-file $OSMFILE --all --threads $THREADS && \ +sudo -u nominatim ./src/build/utils/specialphrases.php --wiki-import > specialphrases.sql && \ +sudo -u postgres psql -d nominatim -f specialphrases.sql && \ +sudo -u postgres psql postgres -tAc "CREATE INDEX nodes_index ON public.planet_osm_ways USING gin (nodes);" + +sudo -u postgres /usr/lib/postgresql/9.5/bin/pg_ctl -D /data/$PGDIR stop && \ +sudo chown -R postgres:postgres /data/$PGDIR \ No newline at end of file diff --git a/local.php b/local.php new file mode 100644 index 0000000..909dba9 --- /dev/null +++ b/local.php @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/nominatim.conf b/nominatim.conf new file mode 100644 index 0000000..52df6d7 --- /dev/null +++ b/nominatim.conf @@ -0,0 +1,14 @@ +Listen 8080 + + DocumentRoot /app/src/build/website + ServerPath "/nominatim/" + CustomLog /var/log/apache2/access.log combined + ErrorLog /var/log/apache2/error.log + LogLevel debug + + Options FollowSymLinks MultiViews + DirectoryIndex search.php + Require all granted + + AddType text/html .php + \ No newline at end of file diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..19e5baa --- /dev/null +++ b/start.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +service postgresql restart +service apache2 restart + +tail -f /var/log/postgresql/postgresql-9.5-main.log