Skip to content

Commit 81c3433

Browse files
authored
Reduce dependencies for updates, switch to Ubuntu 22.04 (#234)
1 parent dc47871 commit 81c3433

File tree

5 files changed

+56
-129
lines changed

5 files changed

+56
-129
lines changed

Dockerfile

Lines changed: 25 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,14 @@
1-
FROM ubuntu:20.04 AS compiler-common
1+
FROM ubuntu:22.04 AS compiler-common
22
ENV DEBIAN_FRONTEND=noninteractive
33

44
RUN apt-get update \
55
&& apt-get install -y --no-install-recommends \
66
git-core \
7-
checkinstall \
8-
g++ \
9-
gnupg2 \
10-
make \
11-
tar \
12-
wget \
137
ca-certificates \
148
&& apt-get update
159

1610
###########################################################################################################
1711

18-
FROM compiler-common AS compiler-postgis
19-
RUN echo "deb http://apt.postgresql.org/pub/repos/apt focal-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
20-
&& wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
21-
&& apt-get update \
22-
&& apt-get install -y --no-install-recommends \
23-
postgresql-server-dev-14 \
24-
libxml2-dev \
25-
libgeos-dev \
26-
libproj-dev \
27-
&& wget https://download.osgeo.org/postgis/source/postgis-3.2.1.tar.gz -O postgis.tar.gz \
28-
&& mkdir -p postgis_src \
29-
&& tar -xvzf postgis.tar.gz --strip 1 -C postgis_src \
30-
&& rm postgis.tar.gz \
31-
&& cd postgis_src \
32-
&& ./configure --without-protobuf --without-raster \
33-
&& make -j $(nproc) \
34-
&& checkinstall --pkgversion="3.2.1" --install=no --default make install
35-
36-
###########################################################################################################
37-
38-
FROM compiler-common AS compiler-osm2pgsql
39-
RUN apt-get install -y --no-install-recommends \
40-
cmake \
41-
libboost-dev \
42-
libboost-system-dev \
43-
libboost-filesystem-dev \
44-
libexpat1-dev \
45-
zlib1g-dev \
46-
libbz2-dev \
47-
libpq-dev \
48-
libproj-dev \
49-
lua5.3 \
50-
liblua5.3-dev \
51-
pandoc
52-
RUN cd ~ \
53-
&& git clone -b master --single-branch https://github.com/openstreetmap/osm2pgsql.git --depth 1 \
54-
&& cd osm2pgsql \
55-
&& mkdir build \
56-
&& cd build \
57-
&& cmake .. \
58-
&& make -j $(nproc) \
59-
&& checkinstall --pkgversion="1" --install=no --default make install
60-
61-
###########################################################################################################
62-
63-
FROM compiler-common AS compiler-modtile-renderd
64-
RUN apt-get install -y --no-install-recommends \
65-
apache2-dev \
66-
automake \
67-
autoconf \
68-
autotools-dev \
69-
libtool \
70-
libmapnik-dev
71-
RUN cd ~ \
72-
&& git clone -b switch2osm --single-branch https://github.com/SomeoneElseOSM/mod_tile.git --depth 1 \
73-
&& cd mod_tile \
74-
&& ./autogen.sh \
75-
&& ./configure \
76-
&& make -j $(nproc) \
77-
&& checkinstall --pkgversion="1" --install=no --pkgname "renderd" --default make install \
78-
&& checkinstall --pkgversion="1" --install=no --pkgname "mod_tile" --default make install-mod_tile
79-
80-
###########################################################################################################
81-
8212
FROM compiler-common AS compiler-stylesheet
8313
RUN cd ~ \
8414
&& git clone --single-branch --branch v5.4.0 https://github.com/gravitystorm/openstreetmap-carto.git --depth 1 \
@@ -97,7 +27,7 @@ RUN mkdir -p /home/renderer/src \
9727

9828
###########################################################################################################
9929

100-
FROM ubuntu:20.04 AS final
30+
FROM ubuntu:22.04 AS final
10131

10232
# Based on
10333
# https://switch2osm.org/serving-tiles/manually-building-a-tile-server-18-04-lts/
@@ -111,30 +41,33 @@ RUN apt-get update \
11141
&& apt-get install -y --no-install-recommends \
11242
apache2 \
11343
cron \
44+
dateutils \
11445
fonts-noto-cjk \
11546
fonts-noto-hinted \
11647
fonts-noto-unhinted \
48+
fonts-unifont \
11749
gnupg2 \
11850
gdal-bin \
11951
liblua5.3-dev \
12052
lua5.3 \
12153
mapnik-utils \
12254
npm \
55+
osm2pgsql \
12356
osmium-tool \
12457
osmosis \
58+
postgresql-14 \
59+
postgresql-14-postgis-3 \
60+
postgresql-14-postgis-3-scripts \
61+
postgis \
12562
python-is-python3 \
12663
python3-mapnik \
12764
python3-lxml \
12865
python3-psycopg2 \
12966
python3-shapely \
13067
python3-pip \
68+
renderd \
13169
sudo \
132-
ttf-unifont \
13370
wget \
134-
&& echo "deb http://apt.postgresql.org/pub/repos/apt focal-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
135-
&& wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
136-
&& apt-get update \
137-
&& apt-get install -y --no-install-recommends postgresql-14 \
13871
&& apt-get clean autoclean \
13972
&& apt-get autoremove --yes \
14073
&& rm -rf /var/lib/{apt,dpkg,cache,log}/
@@ -146,16 +79,12 @@ RUN pip3 install \
14679
requests \
14780
osmium \
14881
pyyaml
149-
82+
15083
# Install carto for stylesheet
15184
RUN npm install -g [email protected]
15285

15386
# Configure Apache
154-
RUN mkdir /var/lib/mod_tile \
155-
&& chown renderer /var/lib/mod_tile \
156-
&& mkdir /var/run/renderd \
157-
&& chown renderer /var/run/renderd \
158-
&& echo "LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so" >> /etc/apache2/conf-available/mod_tile.conf \
87+
RUN echo "LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so" >> /etc/apache2/conf-available/mod_tile.conf \
15988
&& echo "LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so" >> /etc/apache2/conf-available/mod_headers.conf \
16089
&& a2enconf mod_tile && a2enconf mod_headers
16190
COPY apache.conf /etc/apache2/sites-available/000-default.conf
@@ -179,43 +108,28 @@ RUN chown -R postgres:postgres /var/lib/postgresql \
179108
&& echo "host all all ::/0 md5" >> /etc/postgresql/14/main/pg_hba.conf
180109

181110
# Create volume directories
182-
RUN mkdir -p /data/database/ \
111+
RUN mkdir -p /run/renderd/ \
112+
&& mkdir -p /data/database/ \
183113
&& mkdir -p /data/style/ \
184114
&& mkdir -p /home/renderer/src/ \
185115
&& chown -R renderer: /data/ \
186116
&& chown -R renderer: /home/renderer/src/ \
117+
&& chown -R renderer: /run/renderd \
187118
&& mv /var/lib/postgresql/14/main/ /data/database/postgres/ \
188-
&& mv /var/lib/mod_tile/ /data/tiles/ \
119+
&& mv /var/cache/renderd/tiles/ /data/tiles/ \
120+
&& chown -R renderer: /data/tiles \
189121
&& ln -s /data/database/postgres /var/lib/postgresql/14/main \
190122
&& ln -s /data/style /home/renderer/src/openstreetmap-carto \
191-
&& ln -s /data/tiles /var/lib/mod_tile \
123+
&& ln -s /data/tiles /var/cache/renderd/tiles \
192124
;
193125

194-
# Install PostGIS
195-
COPY --from=compiler-postgis postgis_src/postgis-src_3.2.1-1_amd64.deb .
196-
RUN dpkg -i postgis-src_3.2.1-1_amd64.deb \
197-
&& rm postgis-src_3.2.1-1_amd64.deb
198-
199-
# Install osm2pgsql
200-
COPY --from=compiler-osm2pgsql /root/osm2pgsql/build/build_1-1_amd64.deb .
201-
RUN dpkg -i build_1-1_amd64.deb \
202-
&& rm build_1-1_amd64.deb
203-
204-
# Install renderd
205-
COPY --from=compiler-modtile-renderd /root/mod_tile/renderd_1-1_amd64.deb .
206-
RUN dpkg -i renderd_1-1_amd64.deb \
207-
&& rm renderd_1-1_amd64.deb \
208-
&& sed -i 's/renderaccount/renderer/g' /usr/local/etc/renderd.conf \
209-
&& sed -i 's/\/truetype//g' /usr/local/etc/renderd.conf \
210-
&& sed -i 's/hot/tile/g' /usr/local/etc/renderd.conf
211-
212-
# Install mod_tile
213-
COPY --from=compiler-modtile-renderd /root/mod_tile/mod-tile_1-1_amd64.deb .
214-
RUN dpkg -i mod-tile_1-1_amd64.deb \
215-
&& ldconfig \
216-
&& rm mod-tile_1-1_amd64.deb
217-
218-
COPY --from=compiler-modtile-renderd /root/mod_tile/osmosis-db_replag /usr/bin/osmosis-db_replag
126+
RUN echo '[default] \n\
127+
URI=/tile/ \n\
128+
TILEDIR=/var/cache/renderd/tiles \n\
129+
XML=/home/renderer/src/openstreetmap-carto/mapnik.xml \n\
130+
HOST=localhost \n\
131+
TILESIZE=256 \n\
132+
MAXZOOM=20' >> /etc/renderd.conf
219133

220134
# Install helper script
221135
COPY --from=compiler-helper-script /home/renderer/src/regional /home/renderer/src/regional

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ Given that you've set up your import as described in the *Automatic updates* sec
126126
```
127127
docker run \
128128
-p 8080:80 \
129+
-e REPLICATION_URL=https://planet.openstreetmap.org/replication/minute/ \
130+
-e MAX_INTERVAL_SECONDS=60 \
129131
-e UPDATES=enabled \
130132
-v osm-data:/data/database/ \
131133
-v osm-tiles:/data/tiles/ \
@@ -244,7 +246,7 @@ You can find an example of the import performance to expect with this image on t
244246

245247
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:
246248
```
247-
renderd[121]: ERROR: failed to render TILE ajt 2 0-3 0-3
249+
renderd[121]: ERROR: failed to render TILE default 2 0-3 0-3
248250
renderd[121]: reason: Postgis Plugin: ERROR: could not resize shared memory segment "/PostgreSQL.790133961" to 12615680 bytes: ### No space left on device
249251
```
250252
To raise it use `--shm-size` parameter. For example:

apache.conf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<VirtualHost *:80>
22
ServerAdmin webmaster@localhost
33

4-
LoadTileConfigFile /usr/local/etc/renderd.conf
5-
ModTileRenderdSocketName /var/run/renderd/renderd.sock
4+
AddTileConfig /tile/ default
5+
LoadTileConfigFile /etc/renderd.conf
6+
ModTileRenderdSocketName /run/renderd/renderd.sock
67
ModTileRequestTimeout 0
78
ModTileMissingRequestTimeout 30
89

openstreetmap-tiles-update-expire.sh

100644100755
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -e
44

55
#------------------------------------------------------------------------------
6-
# AJT - change directory to mod_tile directory so that we can run replag
6+
# Change directory to mod_tile directory so that we can run replag
77
# and other things directly from this script when run from cron.
88
# Change the actual location to wherever installed locally.
99
#------------------------------------------------------------------------------
@@ -61,6 +61,10 @@ EXPIRY_TOUCHFROM=13
6161
EXPIRY_DELETEFROM=19
6262
EXPIRY_MAXZOOM=20
6363

64+
65+
REPLICATION_URL=${REPLICATION_URL:="https://planet.openstreetmap.org/replication/hour/"}
66+
MAX_INTERVAL_SECONDS=${MAX_INTERVAL_SECONDS:="3600"}
67+
6468
#*************************************************************************
6569
#*************************************************************************
6670

@@ -109,14 +113,16 @@ freelock()
109113
if [ $# -eq 1 ] ; then
110114
m_info "Initialising Osmosis replication system to $1"
111115
mkdir -p $WORKOSM_DIR
116+
$OSMOSIS_BIN -v 5 --read-replication-interval-init workingDirectory=$WORKOSM_DIR 1>&2 2> "$OSMOSISLOG"
112117

113-
$OSMOSIS_BIN --read-replication-interval-init workingDirectory=$WORKOSM_DIR 1>&2 2> "$OSMOSISLOG"
114-
115-
wget "https://replicate-sequences.osm.mazdermind.de/?"$1"T00:00:00Z" -O $WORKOSM_DIR/state.txt
118+
init_seq=$(/usr/lib/python3-pyosmium/pyosmium-get-changes --server $REPLICATION_URL -D $1)
119+
url_dynamicPart=$(printf %09d $init_seq | sed 's_\([0-9][0-9][0-9]\)\([0-9][0-9][0-9]\)\([0-9][0-9][0-9]\)_\1/\2/\3_')
120+
wget $REPLICATION_URL/$url_dynamicPart.state.txt -O $WORKOSM_DIR/state.txt
116121

117-
mv $WORKOSM_DIR/configuration.txt $WORKOSM_DIR/configuration_orig.txt
118-
sed "s!baseUrl=http://planet.openstreetmap.org/replication/minute!baseUrl=https://planet.openstreetmap.org/replication/minute!" $WORKOSM_DIR/configuration_orig.txt > $WORKOSM_DIR/configuration.txt
119-
exit 0
122+
cat > $WORKOSM_DIR/configuration.txt <<- EOM
123+
baseUrl=$REPLICATION_URL
124+
maxInterval=$MAX_INTERVAL_SECONDS
125+
EOM
120126
fi
121127

122128
# make sure the lockfile is removed when we exit and then claim it
@@ -141,8 +147,9 @@ if `python -c "import os, sys; st=os.statvfs('$BASE_DIR'); sys.exit(1 if st.f_ba
141147
fi
142148

143149
seq=`cat $WORKOSM_DIR/state.txt | grep sequenceNumber | cut -d= -f2`
150+
replag=`dateutils.ddiff $(cat $WORKOSM_DIR/state.txt | grep timestamp | cut -d "=" -f 2 | sed 's,\\\,,g') now`
144151

145-
m_ok "start import from seq-nr $seq, replag is `osmosis-db_replag -h`"
152+
m_ok "start import from seq-nr $seq, replag is $replag"
146153

147154
/bin/cp $WORKOSM_DIR/state.txt $WORKOSM_DIR/last.state.txt
148155
m_ok "downloading diff"
@@ -182,15 +189,13 @@ fi
182189
m_ok "expiring tiles"
183190

184191
#------------------------------------------------------------------------------
185-
# When expiring tiles we need to define the style sheet if it's not "default".
186-
# In this case it's "ajt".
187192
# Previously all tiles on the "dirty" list between $EXPIRY_MINZOOM and
188193
# $EXPIRY_MAXZOOM were dirtied. We currently re-render
189194
# tiles >= $EXPIRY_MINZOOM and < $EXPIRY_DELETEFROM, expiry from 14 and
190195
# delete >= $EXPIRY_DELETEFROM and <= $EXPIRY_MAXZOOM.
191196
# The default path to renderd.sock is fixed.
192197
#------------------------------------------------------------------------------
193-
if ! render_expired --map=ajt --min-zoom=$EXPIRY_MINZOOM --touch-from=$EXPIRY_TOUCHFROM --delete-from=$EXPIRY_DELETEFROM --max-zoom=$EXPIRY_MAXZOOM -s /var/run/renderd/renderd.sock < "$EXPIRY_FILE.$$" 2>&1 | tail -8 >> "$EXPIRYLOG"; then
198+
if ! render_expired --map=default --min-zoom=$EXPIRY_MINZOOM --touch-from=$EXPIRY_TOUCHFROM --delete-from=$EXPIRY_DELETEFROM --max-zoom=$EXPIRY_MAXZOOM -s /var/run/renderd/renderd.sock < "$EXPIRY_FILE.$$" 2>&1 | tail -8 >> "$EXPIRYLOG"; then
194199
m_info "Expiry failed"
195200
fi
196201

run.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ if [ "$1" == "import" ]; then
7070
if [ -n "${DOWNLOAD_PBF:-}" ]; then
7171
echo "INFO: Download PBF file: $DOWNLOAD_PBF"
7272
wget ${WGET_ARGS:-} "$DOWNLOAD_PBF" -O /data/region.osm.pbf
73-
if [ -n "$DOWNLOAD_POLY" ]; then
73+
if [ -n "${DOWNLOAD_POLY:-}" ]; then
7474
echo "INFO: Download PBF-POLY file: $DOWNLOAD_POLY"
7575
wget ${WGET_ARGS:-} "$DOWNLOAD_POLY" -O /data/region.poly
7676
fi
7777
fi
7878

7979
if [ "${UPDATES:-}" == "enabled" ] || [ "${UPDATES:-}" == "1" ]; then
8080
# determine and set osmosis_replication_timestamp (for consecutive updates)
81-
REPLICATION_TIMESTAMP=`osmium fileinfo /data/region.osm.pbf | grep 'osmosis_replication_timestamp=' | cut -b35-44`
81+
REPLICATION_TIMESTAMP=`osmium fileinfo /data/region.osm.pbf | grep 'osmosis_replication_timestamp=' | cut -d "=" -f 2`
8282

8383
# initial setup of osmosis workspace (for consecutive updates)
8484
sudo -u renderer openstreetmap-tiles-update-expire.sh $REPLICATION_TIMESTAMP
@@ -168,11 +168,16 @@ if [ "$1" == "run" ]; then
168168
setPostgresPassword
169169

170170
# Configure renderd threads
171-
sed -i -E "s/num_threads=[0-9]+/num_threads=${THREADS:-4}/g" /usr/local/etc/renderd.conf
171+
sed -i -E "s/num_threads=[0-9]+/num_threads=${THREADS:-4}/g" /etc/renderd.conf
172172

173173
# start cron job to trigger consecutive updates
174174
if [ "${UPDATES:-}" == "enabled" ] || [ "${UPDATES:-}" == "1" ]; then
175175
/etc/init.d/cron start
176+
sudo -u renderer touch /var/log/tiles/run.log; tail -f /var/log/tiles/run.log >> /proc/1/fd/1 &
177+
sudo -u renderer touch /var/log/tiles/osmosis.log; tail -f /var/log/tiles/osmosis.log >> /proc/1/fd/1 &
178+
sudo -u renderer touch /var/log/tiles/expiry.log; tail -f /var/log/tiles/expiry.log >> /proc/1/fd/1 &
179+
sudo -u renderer touch /var/log/tiles/osm2pgsql.log; tail -f /var/log/tiles/osm2pgsql.log >> /proc/1/fd/1 &
180+
176181
fi
177182

178183
# Run while handling docker stop's SIGTERM
@@ -181,7 +186,7 @@ if [ "$1" == "run" ]; then
181186
}
182187
trap stop_handler SIGTERM
183188

184-
sudo -u renderer renderd -f -c /usr/local/etc/renderd.conf &
189+
sudo -u renderer renderd -f -c /etc/renderd.conf &
185190
child=$!
186191
wait "$child"
187192

0 commit comments

Comments
 (0)