openstreetmap-tile-server/Dockerfile

184 lines
5.2 KiB
Docker
Raw Normal View History

2018-05-08 20:43:34 +00:00
FROM ubuntu:18.04
# Based on
# https://switch2osm.org/manually-building-a-tile-server-18-04-lts/
2019-03-14 14:56:07 +00:00
# Set up environment
ENV TZ=UTC
ENV AUTOVACUUM=on
ENV UPDATES=disabled
2019-03-14 14:56:07 +00:00
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
2018-05-08 20:43:34 +00:00
# Install dependencies
RUN apt-get update \
&& apt-get install wget gnupg2 lsb-core -y \
2019-10-14 21:40:49 +00:00
&& wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo "deb [ trusted=yes ] http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list \
2019-03-15 15:50:46 +00:00
&& apt-get update \
2020-02-09 20:13:22 +00:00
&& apt-get install -y apt-transport-https ca-certificates
RUN apt-get install -y curl \
&& wget --quiet -O - https://deb.nodesource.com/setup_10.x | bash - \
&& apt-get install -y nodejs
RUN apt-get install -y --no-install-recommends --allow-unauthenticated \
2019-03-14 14:45:25 +00:00
apache2 \
apache2-dev \
autoconf \
build-essential \
bzip2 \
cmake \
2019-12-21 21:19:12 +00:00
cron \
2019-03-14 14:45:25 +00:00
fonts-noto-cjk \
fonts-noto-hinted \
fonts-noto-unhinted \
2019-10-14 21:40:49 +00:00
gcc \
2019-03-14 14:45:25 +00:00
gdal-bin \
git-core \
libagg-dev \
2019-12-23 20:46:24 +00:00
libboost-filesystem-dev \
libboost-system-dev \
2019-03-14 14:45:25 +00:00
libbz2-dev \
libcairo-dev \
libcairomm-1.0-dev \
libexpat1-dev \
libfreetype6-dev \
libgdal-dev \
libgeos++-dev \
libgeos-dev \
libgeotiff-epsg \
libicu-dev \
2019-03-15 15:50:46 +00:00
liblua5.3-dev \
2019-03-14 14:45:25 +00:00
libmapnik-dev \
libpq-dev \
libproj-dev \
libprotobuf-c0-dev \
libtiff5-dev \
libtool \
libxml2-dev \
2019-03-15 15:50:46 +00:00
lua5.3 \
2019-03-14 14:45:25 +00:00
make \
mapnik-utils \
2020-02-09 20:13:22 +00:00
node-gyp \
2019-12-21 21:19:12 +00:00
osmium-tool \
osmosis \
2019-03-14 14:45:25 +00:00
postgis \
2019-10-14 21:40:49 +00:00
postgresql-12 \
postgresql-contrib-12 \
2019-12-21 21:19:12 +00:00
postgresql-server-dev-12 \
2019-03-14 14:45:25 +00:00
protobuf-c-compiler \
python3-mapnik \
2019-12-21 21:19:12 +00:00
python3-lxml \
python3-psycopg2 \
python3-shapely \
2019-03-14 14:45:25 +00:00
sudo \
tar \
ttf-unifont \
unzip \
wget \
2019-03-15 15:50:46 +00:00
zlib1g-dev \
&& apt-get clean autoclean \
&& apt-get autoremove --yes \
&& rm -rf /var/lib/{apt,dpkg,cache,log}/
2018-05-08 20:43:34 +00:00
2019-10-14 21:40:49 +00:00
# Set up PostGIS
RUN wget http://download.osgeo.org/postgis/source/postgis-3.0.0.tar.gz -O postgis.tar.gz \
2019-12-21 21:20:35 +00:00
&& mkdir -p postgis_src \
&& tar -xvzf postgis.tar.gz --strip 1 -C postgis_src \
&& rm postgis.tar.gz \
&& cd postgis_src \
&& ./configure && make && make install \
&& cd .. && rm -rf postgis_src
2019-10-14 21:40:49 +00:00
2019-03-14 14:56:07 +00:00
# Set up renderer user
2018-05-08 20:43:34 +00:00
RUN adduser --disabled-password --gecos "" renderer
# Install latest osm2pgsql
2019-12-21 21:25:04 +00:00
RUN mkdir -p /home/renderer/src \
&& cd /home/renderer/src \
&& git clone https://github.com/openstreetmap/osm2pgsql.git \
&& cd /home/renderer/src/osm2pgsql \
&& rm -rf .git \
2019-12-21 21:25:04 +00:00
&& mkdir build \
&& cd build \
&& cmake .. \
&& make -j $(nproc) \
&& make install \
&& mkdir /nodes \
&& chown renderer:renderer /nodes \
&& rm -rf /home/renderer/src/osm2pgsql
2018-05-08 20:43:34 +00:00
# Install mod_tile and renderd
2019-12-21 21:26:30 +00:00
RUN mkdir -p /home/renderer/src \
&& cd /home/renderer/src \
2019-12-21 21:26:30 +00:00
&& git clone -b switch2osm https://github.com/SomeoneElseOSM/mod_tile.git \
&& cd mod_tile \
&& ./autogen.sh \
&& ./configure \
&& make -j $(nproc) \
&& make -j $(nproc) install \
&& make -j $(nproc) install-mod_tile \
&& ldconfig \
2019-12-25 20:49:31 +00:00
&& cd ..
2018-05-08 20:43:34 +00:00
# Configure stylesheet
RUN mkdir -p /home/renderer/src \
&& cd /home/renderer/src \
&& git clone https://github.com/gravitystorm/openstreetmap-carto.git \
&& git -C openstreetmap-carto checkout v4.23.0 \
2019-12-21 21:53:12 +00:00
&& cd openstreetmap-carto \
2019-12-22 20:48:33 +00:00
&& rm -rf .git \
2019-12-21 21:53:12 +00:00
&& npm install -g carto@0.18.2 \
&& carto project.mml > mapnik.xml \
2020-01-23 15:25:24 +00:00
&& scripts/get-shapefiles.py \
&& rm /home/renderer/src/openstreetmap-carto/data/*.zip
2018-05-08 20:43:34 +00:00
# Configure renderd
2019-03-15 15:50:46 +00:00
RUN sed -i 's/renderaccount/renderer/g' /usr/local/etc/renderd.conf \
2019-12-21 21:53:12 +00:00
&& sed -i 's/hot/tile/g' /usr/local/etc/renderd.conf
2018-05-08 20:43:34 +00:00
# Configure Apache
2019-03-15 15:50:46 +00:00
RUN mkdir /var/lib/mod_tile \
2019-12-21 21:33:56 +00:00
&& chown renderer /var/lib/mod_tile \
&& mkdir /var/run/renderd \
&& chown renderer /var/run/renderd \
&& echo "LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so" >> /etc/apache2/conf-available/mod_tile.conf \
&& echo "LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so" >> /etc/apache2/conf-available/mod_headers.conf \
&& a2enconf mod_tile && a2enconf mod_headers
2018-05-08 20:43:34 +00:00
COPY apache.conf /etc/apache2/sites-available/000-default.conf
2019-01-11 19:37:31 +00:00
COPY leaflet-demo.html /var/www/html/index.html
RUN ln -sf /dev/stdout /var/log/apache2/access.log \
2019-12-22 20:21:56 +00:00
&& ln -sf /dev/stderr /var/log/apache2/error.log
2019-01-11 19:37:31 +00:00
# Configure PosgtreSQL
COPY postgresql.custom.conf.tmpl /etc/postgresql/12/main/
RUN chown -R postgres:postgres /var/lib/postgresql \
2019-12-21 21:34:30 +00:00
&& chown postgres:postgres /etc/postgresql/12/main/postgresql.custom.conf.tmpl \
&& echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/12/main/pg_hba.conf \
&& echo "host all all ::/0 md5" >> /etc/postgresql/12/main/pg_hba.conf
2019-12-22 20:21:56 +00:00
# Copy update scripts
COPY openstreetmap-tiles-update-expire /usr/bin/
RUN chmod +x /usr/bin/openstreetmap-tiles-update-expire \
2019-12-21 21:37:32 +00:00
&& mkdir /var/log/tiles \
&& chmod a+rw /var/log/tiles \
&& ln -s /home/renderer/src/mod_tile/osmosis-db_replag /usr/bin/osmosis-db_replag \
&& echo "* * * * * renderer openstreetmap-tiles-update-expire\n" >> /etc/crontab
2019-12-22 20:21:56 +00:00
# Install trim_osc.py helper script
RUN mkdir -p /home/renderer/src \
&& cd /home/renderer/src \
2019-12-21 21:37:45 +00:00
&& git clone https://github.com/zverik/regional \
&& cd regional \
&& git checkout 612fe3e040d8bb70d2ab3b133f3b2cfc6c940520 \
2019-12-22 20:21:56 +00:00
&& rm -rf .git \
&& chmod u+x /home/renderer/src/regional/trim_osc.py
2018-05-08 20:43:34 +00:00
# Start running
COPY run.sh /
COPY indexes.sql /
2018-05-08 20:43:34 +00:00
ENTRYPOINT ["/run.sh"]
2019-01-11 19:37:31 +00:00
CMD []
2019-03-14 10:52:16 +00:00
EXPOSE 80 5432