diff --git a/Dockerfile b/Dockerfile index 810fd9a..87f0229 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,13 +3,70 @@ FROM ubuntu:18.04 # Based on # https://switch2osm.org/manually-building-a-tile-server-18-04-lts/ -# Install dependencies -RUN apt-get update -RUN apt-get install -y libboost-all-dev git-core tar unzip wget bzip2 build-essential autoconf libtool libxml2-dev libgeos-dev libgeos++-dev libpq-dev libbz2-dev libproj-dev munin-node munin libprotobuf-c0-dev protobuf-c-compiler libfreetype6-dev libtiff5-dev libicu-dev libgdal-dev libcairo-dev libcairomm-1.0-dev apache2 apache2-dev libagg-dev liblua5.2-dev ttf-unifont lua5.1 liblua5.1-dev libgeotiff-epsg - -# Set up environment and renderer user +# Set up environment ENV TZ=UTC RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +# Install dependencies +RUN echo "deb [ allow-insecure=yes ] http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main" >> /etc/apt/sources.list.d/pgdg.list \ + && apt-get update \ + && apt-get install -y apt-transport-https ca-certificates \ + && apt-get install -y --no-install-recommends --allow-unauthenticated \ + apache2 \ + apache2-dev \ + autoconf \ + build-essential \ + bzip2 \ + cmake \ + fonts-noto-cjk \ + fonts-noto-hinted \ + fonts-noto-unhinted \ + clang \ + gdal-bin \ + git-core \ + libagg-dev \ + libboost-all-dev \ + libbz2-dev \ + libcairo-dev \ + libcairomm-1.0-dev \ + libexpat1-dev \ + libfreetype6-dev \ + libgdal-dev \ + libgeos++-dev \ + libgeos-dev \ + libgeotiff-epsg \ + libicu-dev \ + liblua5.3-dev \ + libmapnik-dev \ + libpq-dev \ + libproj-dev \ + libprotobuf-c0-dev \ + libtiff5-dev \ + libtool \ + libxml2-dev \ + lua5.3 \ + make \ + mapnik-utils \ + nodejs \ + npm \ + postgis \ + postgresql-10 \ + postgresql-10-postgis-2.5 \ + postgresql-10-postgis-2.5-scripts \ + postgresql-contrib-10 \ + protobuf-c-compiler \ + python-mapnik \ + sudo \ + tar \ + ttf-unifont \ + unzip \ + wget \ + zlib1g-dev \ +&& apt-get clean autoclean \ +&& apt-get autoremove --yes \ +&& rm -rf /var/lib/{apt,dpkg,cache,log}/ + +# Set up renderer user RUN adduser --disabled-password --gecos "" renderer USER renderer @@ -18,34 +75,28 @@ RUN mkdir /home/renderer/src WORKDIR /home/renderer/src RUN git clone https://github.com/openstreetmap/osm2pgsql.git WORKDIR /home/renderer/src/osm2pgsql -USER root -RUN apt-get install -y make cmake g++ libboost-dev libboost-system-dev libboost-filesystem-dev libexpat1-dev zlib1g-dev libbz2-dev libpq-dev libgeos-dev libgeos++-dev libproj-dev lua5.2 liblua5.2-dev -USER renderer RUN mkdir build WORKDIR /home/renderer/src/osm2pgsql/build -RUN cmake .. -RUN make +RUN cmake .. \ + && make -j $(nproc) USER root RUN make install USER renderer # Install and test Mapnik -USER root -RUN apt-get -y install autoconf apache2-dev libtool libxml2-dev libbz2-dev libgeos-dev libgeos++-dev libproj-dev gdal-bin libmapnik-dev mapnik-utils python-mapnik -USER renderer RUN python -c 'import mapnik' # Install mod_tile and renderd WORKDIR /home/renderer/src RUN git clone -b switch2osm https://github.com/SomeoneElseOSM/mod_tile.git WORKDIR /home/renderer/src/mod_tile -RUN ./autogen.sh -RUN ./configure -RUN make +RUN ./autogen.sh \ + && ./configure \ + && make -j $(nproc) USER root -RUN make install -RUN make install-mod_tile -RUN ldconfig +RUN make -j $(nproc) install \ + && make -j $(nproc) install-mod_tile \ + && ldconfig USER renderer # Configure stylesheet @@ -53,46 +104,42 @@ WORKDIR /home/renderer/src RUN git clone https://github.com/gravitystorm/openstreetmap-carto.git WORKDIR /home/renderer/src/openstreetmap-carto USER root -RUN apt-get install -y npm nodejs RUN npm install -g carto USER renderer -RUN carto -v RUN carto project.mml > mapnik.xml # Load shapefiles WORKDIR /home/renderer/src/openstreetmap-carto RUN scripts/get-shapefiles.py -# Install fonts -USER root -RUN apt-get install -y fonts-noto-cjk fonts-noto-hinted fonts-noto-unhinted ttf-unifont -USER renderer - # Configure renderd USER root -RUN sed -i 's/renderaccount/renderer/g' /usr/local/etc/renderd.conf -RUN sed -i 's/hot/tile/g' /usr/local/etc/renderd.conf +RUN sed -i 's/renderaccount/renderer/g' /usr/local/etc/renderd.conf \ + && sed -i 's/hot/tile/g' /usr/local/etc/renderd.conf USER renderer # Configure Apache USER root -RUN mkdir /var/lib/mod_tile -RUN chown renderer /var/lib/mod_tile -RUN mkdir /var/run/renderd -RUN chown renderer /var/run/renderd -RUN echo "LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so" >> /etc/apache2/conf-available/mod_tile.conf -RUN a2enconf mod_tile +RUN mkdir /var/lib/mod_tile \ + && chown renderer /var/lib/mod_tile \ + && mkdir /var/run/renderd \ + && chown renderer /var/run/renderd +RUN echo "LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so" >> /etc/apache2/conf-available/mod_tile.conf \ + && a2enconf mod_tile COPY apache.conf /etc/apache2/sites-available/000-default.conf -USER renderer +COPY leaflet-demo.html /var/www/html/index.html +RUN ln -sf /proc/1/fd/1 /var/log/apache2/access.log \ + && ln -sf /proc/1/fd/2 /var/log/apache2/error.log -# Install PostgreSQL -USER root -RUN apt-get install -y postgresql postgresql-contrib postgis postgresql-10-postgis-2.4 -USER renderer +# Configure PosgtreSQL +COPY postgresql.custom.conf /etc/postgresql/10/main/ +RUN chown -R postgres:postgres /var/lib/postgresql \ + && chown postgres:postgres /etc/postgresql/10/main/postgresql.custom.conf \ + && echo "\ninclude 'postgresql.custom.conf'" >> /etc/postgresql/10/main/postgresql.conf # Start running -USER root -RUN apt-get install -y sudo COPY run.sh / ENTRYPOINT ["/run.sh"] -CMD [] \ No newline at end of file +CMD [] + +EXPOSE 80 5432 diff --git a/README.md b/README.md index 97618f2..1f7e583 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,21 @@ The import and tile serving processes use 4 threads by default, but this number docker run -p 80:80 -e THREADS=24 -v openstreetmap-data:/var/lib/postgresql/10/main -d overv/openstreetmap-tile-server run +## Troubleshooting + +### ERROR: could not resize shared memory segment + +If you encounter such entries in the log, it will mean that the default shared memory limit (64 MB) is too low for the container and it should be raised: + + renderd[126]: ERROR: failed to render TILE ajt 6 32-39 16-23, + renderd[126]: reason: Postgis Plugin: ERROR: could not resize shared memory segment + +To raise it use `--shm-size` parameter. For example: + + docker run -p 80:80 -v openstreetmap-data:/var/lib/postgresql/10/main --shm-size="192m" -d overv/openstreetmap-tile-server run + +For too high values you may notice excessive CPU load and memory usage. It might be that you will have to experimentally find the best values for yourself. + ## License ``` diff --git a/leaflet-demo.html b/leaflet-demo.html index c3b626b..82d09a8 100644 --- a/leaflet-demo.html +++ b/leaflet-demo.html @@ -25,7 +25,7 @@