Skip to content

Commit

Permalink
Merge pull request #19 from peter-evans/update-nominatim
Browse files Browse the repository at this point in the history
Update Nominatim to version 3.3.0
  • Loading branch information
peter-evans authored May 1, 2019
2 parents 0dd5ad2 + 28f1482 commit abab7d1
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM peterevans/trusty-gcloud:1.2.23 as builder

ENV NOMINATIM_VERSION 3.2.0
ENV NOMINATIM_VERSION 3.3.0

# Let the container know that there is no TTY
ARG DEBIAN_FRONTEND=noninteractive
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Nominatim for Kubernetes
[![](https://images.microbadger.com/badges/image/peterevans/nominatim-k8s.svg)](https://microbadger.com/images/peterevans/nominatim-k8s)
[![Build Status](https://travis-ci.org/peter-evans/nominatim-k8s.svg?branch=master)](https://travis-ci.org/peter-evans/nominatim-k8s)
[![CircleCI](https://circleci.com/gh/peter-evans/nominatim-k8s/tree/master.svg?style=svg)](https://circleci.com/gh/peter-evans/nominatim-k8s/tree/master)

[Nominatim](https://github.com/openstreetmap/Nominatim) for Kubernetes on Google Container Engine (GKE).
Expand All @@ -9,7 +8,8 @@ This Docker image and sample Kubernetes configuration files are one solution to

## Supported tags and respective `Dockerfile` links

- [`2.3.3`, `2.3`, `latest` (*2.3/Dockerfile*)](https://github.com/peter-evans/nominatim-k8s/tree/master)
- [`2.4.0`, `2.4`, `latest` (*2.4/Dockerfile*)](https://github.com/peter-evans/nominatim-k8s/tree/master)
- [`2.3.3`, `2.3` (*2.3/Dockerfile*)](https://github.com/peter-evans/nominatim-k8s/tree/master/archive/2.3)
- [`2.2.0`, `2.2` (*2.2/Dockerfile*)](https://github.com/peter-evans/nominatim-k8s/tree/master/archive/2.2)
- [`2.1.0`, `2.1` (*2.1/Dockerfile*)](https://github.com/peter-evans/nominatim-k8s/tree/master/archive/2.1)
- [`2.0.1`, `2.0` (*2.0/Dockerfile*)](https://github.com/peter-evans/nominatim-k8s/tree/master/archive/2.0)
Expand Down
97 changes: 97 additions & 0 deletions archive/2.3/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
FROM peterevans/trusty-gcloud:1.2.23 as builder

ENV NOMINATIM_VERSION 3.2.0

# Let the container know that there is no TTY
ARG DEBIAN_FRONTEND=noninteractive

# Install packages
RUN apt-get -y update \
&& apt-get install -y -qq --no-install-recommends \
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.3 \
php5 \
php5-cli \
curl

# Build Nominatim
RUN cd /srv \
&& curl --silent -L http://www.nominatim.org/release/Nominatim-$NOMINATIM_VERSION.tar.bz2 -o v$NOMINATIM_VERSION.tar.bz2 \
&& tar xf v$NOMINATIM_VERSION.tar.bz2 \
&& rm v$NOMINATIM_VERSION.tar.bz2 \
&& mv Nominatim-$NOMINATIM_VERSION nominatim \
&& cd nominatim \
&& mkdir build \
&& cd build \
&& cmake .. \
&& make


FROM peterevans/trusty-gcloud:1.2.23

LABEL \
maintainer="Peter Evans <[email protected]>" \
org.opencontainers.image.title="nominatim-k8s" \
org.opencontainers.image.description="Nominatim for Kubernetes on Google Container Engine (GKE)." \
org.opencontainers.image.authors="Peter Evans <[email protected]>" \
org.opencontainers.image.url="https://github.com/peter-evans/nominatim-k8s" \
org.opencontainers.image.vendor="https://peterevans.dev" \
org.opencontainers.image.licenses="MIT"

# Let the container know that there is no TTY
ARG DEBIAN_FRONTEND=noninteractive

# Set locale and install packages
ENV LANG C.UTF-8
RUN locale-gen en_US.UTF-8 \
&& update-locale LANG=en_US.UTF-8 \
&& apt-get -y update \
&& apt-get install -y -qq --no-install-recommends \
postgresql-contrib \
postgresql-9.3-postgis-2.1 \
postgresql-server-dev-9.3 \
apache2 \
php5 \
php5-pgsql \
php5-intl \
libapache2-mod-php5 \
php-pear \
php-db \
curl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /tmp/* /var/tmp/*

# Copy the application from the builder image
COPY --from=builder /srv/nominatim /srv/nominatim

# Configure Nominatim
COPY local.php /srv/nominatim/build/settings/local.php

# Configure Apache
COPY nominatim.conf /etc/apache2/sites-enabled/000-default.conf

# Allow remote connections to PostgreSQL
RUN echo "host all all 0.0.0.0/0 trust" >> /etc/postgresql/9.3/main/pg_hba.conf \
&& echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf

# Set the entrypoint
COPY docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]

EXPOSE 5432
EXPOSE 8080
87 changes: 87 additions & 0 deletions archive/2.3/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash

if [ "$NOMINATIM_MODE" != "CREATE" ] && [ "$NOMINATIM_MODE" != "RESTORE" ]; then
# Default to CREATE
NOMINATIM_MODE="CREATE"
fi

# Defaults
NOMINATIM_DATA_PATH=${NOMINATIM_DATA_PATH:="/srv/nominatim/data"}
NOMINATIM_DATA_LABEL=${NOMINATIM_DATA_LABEL:="data"}
NOMINATIM_PBF_URL=${NOMINATIM_PBF_URL:="http://download.geofabrik.de/asia/maldives-latest.osm.pbf"}
NOMINATIM_POSTGRESQL_DATA_PATH=${NOMINATIM_POSTGRESQL_DATA_PATH:="/var/lib/postgresql/9.3/main"}
# Google Storage variables
NOMINATIM_SA_KEY_PATH=${NOMINATIM_SA_KEY_PATH:=""}
NOMINATIM_PROJECT_ID=${NOMINATIM_PROJECT_ID:=""}
NOMINATIM_GS_BUCKET=${NOMINATIM_GS_BUCKET:=""}


if [ "$NOMINATIM_MODE" == "CREATE" ]; then

# Retrieve the PBF file
curl -L $NOMINATIM_PBF_URL --create-dirs -o $NOMINATIM_DATA_PATH/$NOMINATIM_DATA_LABEL.osm.pbf
# Allow user accounts read access to the data
chmod 755 $NOMINATIM_DATA_PATH

# Start PostgreSQL
service postgresql start

# Import data
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
sudo -u nominatim /srv/nominatim/build/utils/setup.php --osm-file $NOMINATIM_DATA_PATH/$NOMINATIM_DATA_LABEL.osm.pbf --all --threads 2

if [ ! -z "$NOMINATIM_SA_KEY_PATH" ] && [ ! -z "$NOMINATIM_PROJECT_ID" ] && [ ! -z "$NOMINATIM_GS_BUCKET" ]; then

# Stop PostgreSQL
service postgresql stop

# Archive PostgreSQL data
tar cz $NOMINATIM_POSTGRESQL_DATA_PATH | split -b 1024MiB - $NOMINATIM_DATA_PATH/$NOMINATIM_DATA_LABEL.tgz_

# Activate the service account to access storage
gcloud auth activate-service-account --key-file $NOMINATIM_SA_KEY_PATH
# Set the Google Cloud project ID
gcloud config set project $NOMINATIM_PROJECT_ID

# Copy the archive to storage
gsutil -m cp $NOMINATIM_DATA_PATH/*.tgz* $NOMINATIM_GS_BUCKET/$NOMINATIM_DATA_LABEL

# Start PostgreSQL
service postgresql start

fi

else

if [ ! -z "$NOMINATIM_SA_KEY_PATH" ] && [ ! -z "$NOMINATIM_PROJECT_ID" ] && [ ! -z "$NOMINATIM_GS_BUCKET" ]; then

# Activate the service account to access storage
gcloud auth activate-service-account --key-file $NOMINATIM_SA_KEY_PATH
# Set the Google Cloud project ID
gcloud config set project $NOMINATIM_PROJECT_ID

# Copy the archive from storage
mkdir -p $NOMINATIM_DATA_PATH
gsutil -m cp $NOMINATIM_GS_BUCKET/$NOMINATIM_DATA_LABEL/*.tgz* $NOMINATIM_DATA_PATH

# Remove any files present in the target directory
rm -rf $NOMINATIM_POSTGRESQL_DATA_PATH/*

# Extract the archive
cat $NOMINATIM_DATA_PATH/$NOMINATIM_DATA_LABEL.tgz_* | tar xz -C $NOMINATIM_POSTGRESQL_DATA_PATH --strip-components=5

# Start PostgreSQL
service postgresql start

fi

fi

# Tail Apache logs
tail -f /var/log/apache2/* &

# Run Apache in the foreground
/usr/sbin/apache2ctl -D FOREGROUND
7 changes: 7 additions & 0 deletions archive/2.3/local.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
// Paths
@define('CONST_Postgresql_Version', '9.3');
@define('CONST_Postgis_Version', '2.1');
// Website settings
@define('CONST_Website_BaseURL', '/');
?>
13 changes: 13 additions & 0 deletions archive/2.3/nominatim.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Listen 8080
<VirtualHost *:8080>
DocumentRoot /srv/nominatim/build/website
CustomLog /var/log/apache2/access.log combined
ErrorLog /var/log/apache2/error.log
LogLevel debug
<Directory /srv/nominatim/build/website>
Options FollowSymLinks MultiViews
DirectoryIndex search.php
Require all granted
</Directory>
AddType text/html .php
</VirtualHost>

0 comments on commit abab7d1

Please sign in to comment.