forked from merlinnot/nominatim-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
204 lines (183 loc) · 6.24 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# -*-dockerfile-*-
FROM phusion/baseimage:0.11
# Use bash
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
# Update image
RUN apt-get -qq update && apt-get -qq upgrade -y -o \
Dpkg::Options::="--force-confold"
# Update locales
USER root
RUN apt-get install -y --no-install-recommends locales
ENV DEBIAN_FRONTEND noninteractive
ENV LANG C.UTF-8
RUN locale-gen en_US.UTF-8
RUN update-locale LANG=en_US.UTF-8
# Add postgresql sources
USER root
RUN apt-get install -y --no-install-recommends wget
RUN echo "deb http://apt.postgresql.org/pub/repos/apt bionic-pgdg main" >> \
/etc/apt/sources.list && \
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | \
apt-key add -
RUN apt-get -qq update
# Set build variables
ARG PGSQL_VERSION=9.6
ARG POSTGIS_VERSION=2.5
# Install build dependencies
USER root
RUN apt-get install -y --no-install-recommends \
apache2 \
build-essential \
ca-certificates \
cmake \
curl \
g++ \
git \
libapache2-mod-php \
libboost-dev \
libboost-filesystem-dev \
libboost-python-dev \
libboost-system-dev \
libbz2-dev \
libexpat1-dev \
libgeos-dev \
libgeos++-dev \
libpq-dev \
libproj-dev \
libxml2-dev\
openssl \
osmosis \
php \
php-db \
php-intl \
php-pear \
php-pgsql \
postgresql-${PGSQL_VERSION}-postgis-${POSTGIS_VERSION} \
postgresql-${PGSQL_VERSION}-postgis-scripts \
postgresql-contrib-${PGSQL_VERSION} \
postgresql-server-dev-${PGSQL_VERSION} \
python \
python-pip \
python-setuptools \
sudo \
zlib1g-dev
RUN pip install --upgrade pip
RUN pip install osmium
# Create nominatim user account
USER root
RUN useradd -d /srv/nominatim -s /bin/bash -m nominatim
ENV USERNAME nominatim
ENV USERHOME /srv/nominatim
RUN chmod a+x ${USERHOME}
# Install Nominatim
USER nominatim
ARG REPLICATION_URL=https://planet.osm.org/replication/hour/
ARG BASE_URL=/nominatim/
WORKDIR /srv/nominatim
RUN git clone --recursive git://github.com/openstreetmap/Nominatim.git
RUN echo $'<?php\n\
# Paths
@define('CONST_Postgresql_Version', '${PGSQL_VERSION}'); \n\
@define('CONST_Postgis_Version', '${POSTGIS_VERSION}'); \n\
@define('CONST_Osm2pgsql_Flatnode_File', '/srv/nominatim/flatnode'); \n\
@define('CONST_Pyosmium_Binary', '/usr/local/bin/pyosmium-get-changes'); \n\
# Website settings
@define('CONST_Website_BaseURL', '${BASE_URL}'); \n\
@define('CONST_Replication_Url', '${REPLICATION_URL}'); \n\
@define('CONST_Replication_MaxInterval', '86400'); \n\
@define('CONST_Replication_Update_Interval', '86400'); \n\
@define('CONST_Replication_Recheck_Interval', '900'); \n'\
> ./Nominatim/settings/local.php
RUN wget -O Nominatim/data/country_osm_grid.sql.gz \
http://www.nominatim.org/data/country_grid.sql.gz
RUN mkdir ${USERHOME}/Nominatim/build && \
cd ${USERHOME}/Nominatim/build && \
cmake ${USERHOME}/Nominatim && \
make
RUN sed -i "/CONST_Website_BaseURL/c\@define('CONST_Website_BaseURL', '${BASE_URL}');" Nominatim/settings/defaults.php
RUN sed -i "/CONST_Website_BaseURL/c\@define('CONST_Website_BaseURL', '${BASE_URL}');" Nominatim/build/settings/settings.php
# Download data for initial import
USER nominatim
ARG PBF_URL=https://planet.osm.org/pbf/planet-latest.osm.pbf
RUN curl -L ${PBF_URL} --create-dirs -o /srv/nominatim/src/data.osm.pbf
# Filter administrative boundaries
USER nominatim
ARG BUILD_THREADS=8
ARG IMPORT_ADMINISTRATIVE=false
COPY scripts/filter_administrative.sh \
/srv/nominatim/scripts/filter_administrative.sh
RUN /srv/nominatim/scripts/filter_administrative.sh
# Add postgresql users
USER root
RUN service postgresql start && \
sudo -u postgres createuser -s nominatim && \
sudo -u postgres createuser www-data && \
service postgresql stop
# Tune postgresql configuration for import
USER root
ARG BUILD_MEMORY=16GB
ENV PGCONFIG_URL https://api.pgconfig.org/v1/tuning/get-config
RUN IMPORT_CONFIG_URL="${PGCONFIG_URL}? \
format=alter_system& \
pg_version=${PGSQL_VERSION}& \
total_ram=${BUILD_MEMORY}& \
max_connections=$((8 * ${BUILD_THREADS} + 32))& \
environment_name=DW& \
include_pgbadger=false" && \
IMPORT_CONFIG_URL=${IMPORT_CONFIG_URL// /} && \
service postgresql start && \
( curl -sSL "${IMPORT_CONFIG_URL}"; \
echo $'ALTER SYSTEM SET fsync TO \'off\';\n'; \
echo $'ALTER SYSTEM SET full_page_writes TO \'off\';\n'; \
echo $'ALTER SYSTEM SET logging_collector TO \'off\';\n'; \
) | sudo -u postgres psql -e && \
service postgresql stop
# Initial import
USER root
ARG OSM2PGSQL_CACHE=24000
RUN service postgresql start && \
sudo -u nominatim ${USERHOME}/Nominatim/build/utils/setup.php \
--osm-file /srv/nominatim/src/data.osm.pbf \
--all \
--threads ${BUILD_THREADS} \
--osm2pgsql-cache ${OSM2PGSQL_CACHE} && \
service postgresql stop
# Use safe postgresql configuration
USER root
ARG RUNTIME_THREADS=2
ARG RUNTIME_MEMORY=8GB
RUN IMPORT_CONFIG_URL="${PGCONFIG_URL}? \
format=alter_system& \
pg_version=${PGSQL_VERSION}& \
total_ram=${RUNTIME_MEMORY}& \
max_connections=$((8 * ${RUNTIME_THREADS} + 32))& \
environment_name=WEB& \
include_pgbadger=true" && \
IMPORT_CONFIG_URL=${IMPORT_CONFIG_URL// /} && \
service postgresql start && \
( curl -sSL "${IMPORT_CONFIG_URL}"; \
echo $'ALTER SYSTEM SET fsync TO \'on\';\n'; \
echo $'ALTER SYSTEM SET full_page_writes TO \'on\';\n'; \
echo $'ALTER SYSTEM SET logging_collector TO \'on\';\n'; \
) | sudo -u postgres psql -e && \
service postgresql stop
# Configure Apache
USER root
COPY nominatim.conf /etc/apache2/sites-enabled/000-default.conf
#RUN a2enconf nominatim
# Clean up
USER root
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Expose ports
EXPOSE 80
EXPOSE 443
# Init scripts
USER root
ENV KILL_PROCESS_TIMEOUT=300
ENV KILL_ALL_PROCESSES_TIMEOUT=300
RUN mkdir -p /etc/my_init.d
COPY scripts/start_postgresql.sh /etc/my_init.d/00-postgresql.sh
RUN chmod +x /etc/my_init.d/00-postgresql.sh
COPY scripts/start_apache2.sh /etc/my_init.d/00-apache2.sh
RUN chmod +x /etc/my_init.d/00-apache2.sh
CMD ["/sbin/my_init"]