Skip to content

Commit cffbd7b

Browse files
authored
changed volume paths ; FLAT_NODES=enabled (#261)
Changes: - /var/lib/postgresql/14/main/ => /data/database/ - /var/lib/mod_tile/ => /data/tiles/ - /home/renderer/src/openstreetmap-carto/ => /data/style/ - /data.osm.pbf => /data/region.osm.pbf - /data.poly => /data/region.poly - /nodes/flat_nodes.bin => deprecated (use FLAT_NODES=enabled instead) Because some files are needed later and should never be separated from the database, the import does save those files now into /data/databases/: - /data/database/region.poly - /data/database/flat_nodes.bin - /data/database/planet-import-complete - and automatic update artifacts
1 parent d0673dc commit cffbd7b

File tree

8 files changed

+174
-131
lines changed

8 files changed

+174
-131
lines changed

.github/workflows/build-and-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
env:
2727
VOLUME : osm-db
2828
CONTAINER : osm-www
29-
MOUNT : /var/lib/postgresql/14/main
29+
MOUNT : /data/database/
3030
steps:
3131
-
3232
name: Checkout

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ before_script:
1010
- docker pull overv/openstreetmap-tile-server || true
1111
script:
1212
- docker build --pull --cache-from overv/openstreetmap-tile-server --tag overv/openstreetmap-tile-server .
13-
- docker volume create openstreetmap-data
14-
- docker run --rm -v openstreetmap-data:/var/lib/postgresql/14/main overv/openstreetmap-tile-server import
15-
- docker run --rm -v openstreetmap-data:/var/lib/postgresql/14/main -p 8080:80 -d overv/openstreetmap-tile-server run
13+
- docker volume create osm-data
14+
- docker run --rm -v osm-data:/data/database/ overv/openstreetmap-tile-server import
15+
- docker run --rm -v osm-data:/data/database/ -p 8080:80 -d overv/openstreetmap-tile-server run
1616
- sleep 30
1717
- make DOCKER_IMAGE=overv/openstreetmap-tile-server stop
1818
after_script:

Dockerfile

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ RUN mkdir -p /home/renderer/src \
9797

9898
###########################################################################################################
9999

100-
FROM ubuntu:20.04 AS final-base
100+
FROM ubuntu:20.04 AS final
101101

102102
# Based on
103103
# https://switch2osm.org/serving-tiles/manually-building-a-tile-server-18-04-lts/
@@ -164,15 +164,12 @@ RUN ln -sf /dev/stdout /var/log/apache2/access.log \
164164
&& ln -sf /dev/stderr /var/log/apache2/error.log
165165

166166
# Copy update scripts
167-
COPY openstreetmap-tiles-update-expire /usr/bin/
168-
RUN chmod +x /usr/bin/openstreetmap-tiles-update-expire \
167+
COPY openstreetmap-tiles-update-expire.sh /usr/bin/
168+
RUN chmod +x /usr/bin/openstreetmap-tiles-update-expire.sh \
169169
&& mkdir /var/log/tiles \
170170
&& chmod a+rw /var/log/tiles \
171171
&& ln -s /home/renderer/src/mod_tile/osmosis-db_replag /usr/bin/osmosis-db_replag \
172-
&& echo "* * * * * renderer openstreetmap-tiles-update-expire\n" >> /etc/crontab
173-
174-
RUN mkdir /nodes \
175-
&& chown renderer:renderer /nodes
172+
&& echo "* * * * * renderer openstreetmap-tiles-update-expire.sh\n" >> /etc/crontab
176173

177174
# Configure PosgtreSQL
178175
COPY postgresql.custom.conf.tmpl /etc/postgresql/14/main/
@@ -181,9 +178,18 @@ RUN chown -R postgres:postgres /var/lib/postgresql \
181178
&& echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/14/main/pg_hba.conf \
182179
&& echo "host all all ::/0 md5" >> /etc/postgresql/14/main/pg_hba.conf
183180

184-
###########################################################################################################
185-
186-
FROM final-base AS final
181+
# Create volume directories
182+
RUN mkdir -p /data/database/ \
183+
&& mkdir -p /data/style/ \
184+
&& mkdir -p /home/renderer/src/ \
185+
&& chown -R renderer: /data/ \
186+
&& chown -R renderer: /home/renderer/src/ \
187+
&& mv /var/lib/postgresql/14/main/ /data/database/postgres/ \
188+
&& mv /var/lib/mod_tile/ /data/tiles/ \
189+
&& ln -s /data/database/postgres /var/lib/postgresql/14/main \
190+
&& ln -s /data/style /home/renderer/src/openstreetmap-carto \
191+
&& ln -s /data/tiles /var/lib/mod_tile \
192+
;
187193

188194
# Install PostGIS
189195
COPY --from=compiler-postgis postgis_src/postgis-src_3.2.1-1_amd64.deb .
@@ -206,7 +212,6 @@ RUN dpkg -i renderd_1-1_amd64.deb \
206212
# Install mod_tile
207213
COPY --from=compiler-modtile-renderd /root/mod_tile/mod-tile_1-1_amd64.deb .
208214
RUN dpkg -i mod-tile_1-1_amd64.deb \
209-
&& mkdir -p /home/renderer/src/openstreetmap-carto \
210215
&& ldconfig \
211216
&& rm mod-tile_1-1_amd64.deb
212217

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ push: build
99
docker push ${DOCKER_IMAGE}:latest
1010

1111
test: build
12-
docker volume create openstreetmap-data
13-
docker run --rm -v openstreetmap-data:/var/lib/postgresql/14/main ${DOCKER_IMAGE} import
14-
docker run --rm -v openstreetmap-data:/var/lib/postgresql/14/main -p 8080:80 -d ${DOCKER_IMAGE} run
12+
docker volume create osm-data
13+
docker run --rm -v osm-data:/data/database/ ${DOCKER_IMAGE} import
14+
docker run --rm -v osm-data:/data/database/ -p 8080:80 -d ${DOCKER_IMAGE} run
1515

1616
stop:
1717
docker rm -f `docker ps | grep '${DOCKER_IMAGE}' | awk '{ print $$1 }'` || true
18-
docker volume rm -f openstreetmap-data
18+
docker volume rm -f osm-data

README.md

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,43 @@ This container allows you to easily set up an OpenStreetMap PNG tile server give
99

1010
First create a Docker volume to hold the PostgreSQL database that will contain the OpenStreetMap data:
1111

12-
docker volume create openstreetmap-data
12+
docker volume create osm-data
1313

14-
Next, download an .osm.pbf extract from geofabrik.de for the region that you're interested in. You can then start importing it into PostgreSQL by running a container and mounting the file as `/data.osm.pbf`. For example:
14+
Next, download an `.osm.pbf` extract from geofabrik.de for the region that you're interested in. You can then start importing it into PostgreSQL by running a container and mounting the file as `/data/region.osm.pbf`. For example:
1515

1616
```
1717
docker run \
18-
-v /absolute/path/to/luxembourg.osm.pbf:/data.osm.pbf \
19-
-v openstreetmap-data:/var/lib/postgresql/14/main \
18+
-v /absolute/path/to/luxembourg.osm.pbf:/data/region.osm.pbf \
19+
-v osm-data:/data/database/ \
2020
overv/openstreetmap-tile-server \
2121
import
2222
```
2323

2424
If the container exits without errors, then your data has been successfully imported and you are now ready to run the tile server.
2525

26-
Note that the import process requires an internet connection. The run process does not require an internet connection. If you want to run the openstreetmap-tile server on a computer that is isolated, you must first import on an internet connected computer, export the openstreetmap-data volume as a tarfile, and then restore the data volume on the target computer system.
26+
Note that the import process requires an internet connection. The run process does not require an internet connection. If you want to run the openstreetmap-tile server on a computer that is isolated, you must first import on an internet connected computer, export the `osm-data` volume as a tarfile, and then restore the data volume on the target computer system.
2727

28-
Also when running on an isolated system, the default index.html from the container will not work, as it requires access to the web for the leaflet packages.
28+
Also when running on an isolated system, the default `index.html` from the container will not work, as it requires access to the web for the leaflet packages.
2929

3030
### Automatic updates (optional)
3131

32-
If your import is an extract of the planet and has polygonal bounds associated with it, like those from geofabrik.de, then it is possible to set your server up for automatic updates. Make sure to reference both the OSM file and the polygon file during the import process to facilitate this, and also include the `UPDATES=enabled` variable:
32+
If your import is an extract of the planet and has polygonal bounds associated with it, like those from [geofabrik.de](https://download.geofabrik.de/), then it is possible to set your server up for automatic updates. Make sure to reference both the OSM file and the polygon file during the `import` process to facilitate this, and also include the `UPDATES=enabled` variable:
3333

3434
```
3535
docker run \
3636
-e UPDATES=enabled \
37-
-v /absolute/path/to/luxembourg.osm.pbf:/data.osm.pbf \
38-
-v /absolute/path/to/luxembourg.poly:/data.poly \
39-
-v openstreetmap-data:/var/lib/postgresql/14/main \
40-
-v openstreetmap-rendered-tiles:/var/lib/mod_tile \
37+
-v /absolute/path/to/luxembourg.osm.pbf:/data/region.osm.pbf \
38+
-v /absolute/path/to/luxembourg.poly:/data/region.poly \
39+
-v osm-data:/data/database/ \
4140
overv/openstreetmap-tile-server \
4241
import
4342
```
4443

4544
Refer to the section *Automatic updating and tile expiry* to actually enable the updates while running the tile server.
4645

46+
Please note: If you're not importing the whole planet, then the `.poly` file is necessary to limit automatic updates to the relevant region.
47+
Therefore, when you only have a `.osm.pbf` file but not a `.poly` file, you should not enable automatic updates.
48+
4749
### Letting the container download the file
4850

4951
It is also possible to let the container download files for you rather than mounting them in advance by using the `DOWNLOAD_PBF` and `DOWNLOAD_POLY` parameters:
@@ -52,7 +54,7 @@ It is also possible to let the container download files for you rather than moun
5254
docker run \
5355
-e DOWNLOAD_PBF=https://download.geofabrik.de/europe/luxembourg-latest.osm.pbf \
5456
-e DOWNLOAD_POLY=https://download.geofabrik.de/europe/luxembourg.poly \
55-
-v openstreetmap-data:/var/lib/postgresql/14/main \
57+
-v osm-data:/data/database/ \
5658
overv/openstreetmap-tile-server \
5759
import
5860
```
@@ -69,15 +71,15 @@ docker run \
6971
-e NAME_STYLE=test.style
7072
-e NAME_MML=project.mml
7173
-e NAME_SQL=test.sql
72-
-v /home/user/openstreetmap-carto-modified:/home/renderer/src/openstreetmap-carto \
73-
-v openstreetmap-data:/var/lib/postgresql/12/main \
74+
-v /home/user/openstreetmap-carto-modified:/data/style/ \
75+
-v osm-data:/data/database/ \
7476
overv/openstreetmap-tile-server \
7577
import
7678
```
7779

7880
If you do not define the "NAME_*" variables, the script will default to those found in the openstreetmap-carto style.
7981

80-
Be sure to mount the volume during `run` with the same `-v /home/user/openstreetmap-carto-modified:/home/renderer/src/openstreetmap-carto`
82+
Be sure to mount the volume during `run` with the same `-v /home/user/openstreetmap-carto-modified:/data/style/`
8183

8284
If you do not see the expected style upon `run` double check your paths as the style may not have been found at the directory specified. By default, `openstreetmap-carto` will be used if a style cannot be found
8385

@@ -90,7 +92,7 @@ Run the server like this:
9092
```
9193
docker run \
9294
-p 8080:80 \
93-
-v openstreetmap-data:/var/lib/postgresql/14/main \
95+
-v osm-data:/data/database/ \
9496
-d overv/openstreetmap-tile-server \
9597
run
9698
```
@@ -103,19 +105,19 @@ The `docker-compose.yml` file included with this repository shows how the aforem
103105

104106
### Preserving rendered tiles
105107

106-
Tiles that have already been rendered will be stored in `/var/lib/mod_tile`. To make sure that this data survives container restarts, you should create another volume for it:
108+
Tiles that have already been rendered will be stored in `/data/tiles/`. To make sure that this data survives container restarts, you should create another volume for it:
107109

108110
```
109-
docker volume create openstreetmap-rendered-tiles
111+
docker volume create osm-tiles
110112
docker run \
111113
-p 8080:80 \
112-
-v openstreetmap-data:/var/lib/postgresql/14/main \
113-
-v openstreetmap-rendered-tiles:/var/lib/mod_tile \
114+
-v osm-data:/data/database/ \
115+
-v osm-tiles:/data/tiles/ \
114116
-d overv/openstreetmap-tile-server \
115117
run
116118
```
117119

118-
**If you do this, then make sure to also run the import with the `openstreetmap-rendered-tiles` volume to make sure that caching works properly across updates!**
120+
**If you do this, then make sure to also run the import with the `osm-tiles` volume to make sure that caching works properly across updates!**
119121

120122
### Enabling automatic updating (optional)
121123

@@ -125,8 +127,8 @@ Given that you've set up your import as described in the *Automatic updates* sec
125127
docker run \
126128
-p 8080:80 \
127129
-e UPDATES=enabled \
128-
-v openstreetmap-data:/var/lib/postgresql/14/main \
129-
-v openstreetmap-rendered-tiles:/var/lib/mod_tile \
130+
-v osm-data:/data/database/ \
131+
-v osm-tiles:/data/tiles/ \
130132
-d overv/openstreetmap-tile-server \
131133
run
132134
```
@@ -140,7 +142,7 @@ To enable the `Access-Control-Allow-Origin` header to be able to retrieve tiles
140142
```
141143
docker run \
142144
-p 8080:80 \
143-
-v openstreetmap-data:/var/lib/postgresql/14/main \
145+
-v osm-data:/data/database/ \
144146
-e ALLOW_CORS=enabled \
145147
-d overv/openstreetmap-tile-server \
146148
run
@@ -154,7 +156,7 @@ To connect to the PostgreSQL database inside the container, make sure to expose
154156
docker run \
155157
-p 8080:80 \
156158
-p 5432:5432 \
157-
-v openstreetmap-data:/var/lib/postgresql/14/main \
159+
-v osm-data:/data/database/ \
158160
-d overv/openstreetmap-tile-server \
159161
run
160162
```
@@ -172,7 +174,7 @@ docker run \
172174
-p 8080:80 \
173175
-p 5432:5432 \
174176
-e PGPASSWORD=secret \
175-
-v openstreetmap-data:/var/lib/postgresql/14/main \
177+
-v osm-data:/data/database/ \
176178
-d overv/openstreetmap-tile-server \
177179
run
178180
```
@@ -188,7 +190,7 @@ The import and tile serving processes use 4 threads by default, but this number
188190
docker run \
189191
-p 8080:80 \
190192
-e THREADS=24 \
191-
-v openstreetmap-data:/var/lib/postgresql/14/main \
193+
-v osm-data:/data/database/ \
192194
-d overv/openstreetmap-tile-server \
193195
run
194196
```
@@ -200,7 +202,7 @@ The import and tile serving processes use 800 MB RAM cache by default, but this
200202
docker run \
201203
-p 8080:80 \
202204
-e "OSM2PGSQL_EXTRA_ARGS=-C 4096" \
203-
-v openstreetmap-data:/var/lib/postgresql/14/main \
205+
-v osm-data:/data/database/ \
204206
-d overv/openstreetmap-tile-server \
205207
run
206208
```
@@ -212,27 +214,24 @@ The database use the autovacuum feature by default. This behavior can be changed
212214
docker run \
213215
-p 8080:80 \
214216
-e AUTOVACUUM=off \
215-
-v openstreetmap-data:/var/lib/postgresql/14/main \
217+
-v osm-data:/data/database/ \
216218
-d overv/openstreetmap-tile-server \
217219
run
218220
```
219221

220-
### Flat nodes
222+
### FLAT_NODES
221223

222224
If you are planning to import the entire planet or you are running into memory errors then you may want to enable the `--flat-nodes` option for osm2pgsql. You can then use it during the import process as follows:
223225

224226
```
225227
docker run \
226-
-v /absolute/path/to/luxembourg.osm.pbf:/data.osm.pbf \
227-
-v openstreetmap-nodes:/nodes \
228-
-v openstreetmap-data:/var/lib/postgresql/14/main \
229-
-e "OSM2PGSQL_EXTRA_ARGS=--flat-nodes /nodes/flat_nodes.bin" \
228+
-v /absolute/path/to/luxembourg.osm.pbf:/data/region.osm.pbf \
229+
-v osm-data:/data/database/ \
230+
-e "FLAT_NODES=enabled" \
230231
overv/openstreetmap-tile-server \
231232
import
232233
```
233234

234-
>Note that if you use a folder other than `/nodes` then you must make sure that you manually set the owner to `renderer`!
235-
236235
### Benchmarks
237236

238237
You can find an example of the import performance to expect with this image on the [OpenStreetMap wiki](https://wiki.openstreetmap.org/wiki/Osm2pgsql/benchmarks#debian_9_.2F_openstreetmap-tile-server).
@@ -250,7 +249,7 @@ To raise it use `--shm-size` parameter. For example:
250249
```
251250
docker run \
252251
-p 8080:80 \
253-
-v openstreetmap-data:/var/lib/postgresql/14/main \
252+
-v osm-data:/data/database/ \
254253
--shm-size="192m" \
255254
-d overv/openstreetmap-tile-server \
256255
run

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ services:
44
map:
55
image: overv/openstreetmap-tile-server
66
volumes:
7-
- openstreetmap-data:/var/lib/postgresql/14/main
7+
- osm-data:/data/database/
88
ports:
99
- "8080:80"
1010
command: "run"
1111

1212
volumes:
13-
openstreetmap-data:
13+
osm-data:
1414
external: true

0 commit comments

Comments
 (0)