Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make this work #19

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 56 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
## -*- docker-image-name: "homme/openstreetmap-tiles:latest" -*-
## -*- docker-image-name: "haroldship/openstreetmap-tiles:latest" -*-

##
# The OpenStreetMap Tile Server
#
# This creates an image with containing the OpenStreetMap tile server stack as
# described at
# <http://switch2osm.org/serving-tiles/manually-building-a-tile-server-12-04/>.
# <https://switch2osm.org/serving-tiles/manually-building-a-tile-server-14-04/>.
#
# Based on homme/openstreetmap-tiles Homme Zwaagstra <[email protected]>
#

FROM phusion/baseimage:0.9.11
MAINTAINER Homme Zwaagstra <[email protected]>
FROM phusion/baseimage:0.9.18
MAINTAINER Harold Ship <[email protected]>

# Set the locale. This affects the encoding of the Postgresql template
# databases.
Expand All @@ -33,6 +35,7 @@ RUN apt-get install -y postgresql-9.3-postgis-2.1 postgresql-contrib postgresql-
# Install osm2pgsql
RUN cd /tmp && git clone git://github.com/openstreetmap/osm2pgsql.git
RUN cd /tmp/osm2pgsql && \
git checkout 24e4d4bf273aaf3572fda11d2c0b32aa3156f84a && \
./autogen.sh && \
./configure && \
make && make install
Expand Down Expand Up @@ -60,17 +63,59 @@ RUN cd /tmp/mod_tile && \
ldconfig

# Install the Mapnik stylesheet
RUN cd /usr/local/src && svn co http://svn.openstreetmap.org/applications/rendering/mapnik mapnik-style
#RUN cd /usr/local/src && svn co http://svn.openstreetmap.org/applications/rendering/mapnik mapnik-style

# Install the coastline data
RUN cd /usr/local/src/mapnik-style && ./get-coastlines.sh /usr/local/share
#RUN cd /usr/local/src/mapnik-style && ./get-coastlines.sh /usr/local/share

# Configure mapnik style-sheets
RUN cd /usr/local/src/mapnik-style/inc && cp fontset-settings.xml.inc.template fontset-settings.xml.inc
ADD datasource-settings.sed /tmp/
RUN cd /usr/local/src/mapnik-style/inc && sed --file /tmp/datasource-settings.sed datasource-settings.xml.inc.template > datasource-settings.xml.inc
ADD settings.sed /tmp/
RUN cd /usr/local/src/mapnik-style/inc && sed --file /tmp/settings.sed settings.xml.inc.template > settings.xml.inc
#RUN cd /usr/local/src/mapnik-style/inc && cp fontset-settings.xml.inc.template fontset-settings.xml.inc
#ADD datasource-settings.sed /tmp/
#RUN cd /usr/local/src/mapnik-style/inc && sed --file /tmp/datasource-settings.sed datasource-settings.xml.inc.template > datasource-settings.xml.inc
#ADD settings.sed /tmp/
#RUN cd /usr/local/src/mapnik-style/inc && sed --file /tmp/settings.sed settings.xml.inc.template > settings.xml.inc

# Install node-carto to compile CartoCSS
RUN apt-get install -y node-carto

# Download OSM Bright sources and polygons
RUN mkdir -p /usr/local/share/maps/style && \
chmod a+rx /usr/local/share/maps/style && \
cd /usr/local/share/maps/style && \
wget https://github.com/mapbox/osm-bright/archive/master.zip && \
wget http://data.openstreetmapdata.com/simplified-land-polygons-complete-3857.zip && \
wget http://data.openstreetmapdata.com/land-polygons-split-3857.zip && \
wget http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_populated_places_simple.zip

# Unpack the OSM Bright sources and polygons
RUN cd /usr/local/share/maps/style && \
unzip '*.zip' && \
mkdir osm-bright-master/shp && \
mv land-polygons-split-3857 osm-bright-master/shp && \
mv simplified-land-polygons-complete-3857 osm-bright-master/shp && \
mkdir ne_10m_populated_places_simple && \
mv ne_10m_populated_places_simple.* ne_10m_populated_places_simple && \
mv ne_10m_populated_places_simple osm-bright-master/shp/

# Create shapeindices for polygons
RUN cd /usr/local/share/maps/style/osm-bright-master/shp/land-polygons-split-3857 && shapeindex land_polygons.shp
RUN cd /usr/local/share/maps/style/osm-bright-master/shp/simplified-land-polygons-complete-3857 && shapeindex simplified_land_polygons.shp

# Configure OSM Bright style sheet
ADD osm-bright.osm2pgsql.sed /tmp/
RUN cd /usr/local/share/maps/style/osm-bright-master/osm-bright && \
sed --file /tmp/osm-bright.osm2pgsql.sed --in-place osm-bright.osm2pgsql.mml
ADD configure.py.sed /tmp/
RUN cd /usr/local/share/maps/style/osm-bright-master && \
sed --file /tmp/configure.py.sed configure.py.sample > configure.py

# Build the OSM Bright style sheet in cartocss
RUN cd /usr/local/share/maps/style/osm-bright-master && \
./make.py

# Build the OSM Bright style sheet in mapnik format
RUN cd /usr/local/share/maps/style/OSMBright && \
carto project.mml > OSMBright.xml

# Configure renderd
ADD renderd.conf.sed /tmp/
Expand Down
50 changes: 50 additions & 0 deletions GETTING_STARTED.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

These instructions are for **linux only**, and assume that Docker is up and running.

1. Make a working directory.

mkdir osm
cd osm

2. Make a directory to contain the import file.

mkdir import
cd import

3. Download the import file. *You can use any OSM PBF file, but it is important to name it* `import.pbf`.

curl -o import.pbf http://download.geofabrik.de/asia/israel-and-palestine-latest.osm.pbf

4. Move back to working directory.

cd ..

5. Run the image, with help.

docker run -it haroldship/openstreetmap-tiles-docker help

6. If everything goes well, then there are 3 steps:

* Initial setup, which includes creating the database and user
* Importing
* Running

7. Initialize:
*It is important to get the path to the PostgreSQL data directory correct.*

mkdir data
docker run -v $PWD/data:/var/lib/postgresql \
-it haroldship/openstreetmap-tiles-docker \
initdb startdb createuser createdb

8. Import:
*It is important to get the path to the import directory correct.*
*This step can take a long time, depending on how large a database you are importing.*

docker run -v $PWD/import:/data -v $PWD/data:/var/lib/postgresql \
-it haroldship/openstreetmap-tiles-docker startdb import

9. Start the services.

docker run -v $PWD/data:/var/lib/postgresql \
-d -P haroldship/openstreetmap-tiles-docker startdb startservices
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
This repository contains instructions for building a
[Docker](https://www.docker.io/) image containing the OpenStreetMap tile
serving software stack. It is based on the
[Switch2OSM instructions](http://switch2osm.org/serving-tiles/manually-building-a-tile-server-12-04/).
[Switch2OSM instructions](http://switch2osm.org/serving-tiles/manually-building-a-tile-server-14-04/).

The tiles are styled using [OSM Bright](https://github.com/mapbox/osm-bright/).

As well as providing an easy way to set up and run the tile serving software it
also provides instructions for managing the back end database, allowing you to:
Expand All @@ -12,7 +14,7 @@ also provides instructions for managing the back end database, allowing you to:
* Import OSM data into the database
* Drop the database

Run `docker run homme/openstreetmap-tiles` for usage instructions.
Run `docker run haroldship/openstreetmap-tiles-docker` for usage instructions.

## About

Expand All @@ -22,15 +24,16 @@ includes:

* Postgresql 9.3
* Apache 2.2
* The latest [Osm2pgsql](http://wiki.openstreetmap.org/wiki/Osm2pgsql) code (at
the time of image creation)
* [Osm2pgsql](http://wiki.openstreetmap.org/wiki/Osm2pgsql) from Oct 22 (24e4d4bf273aaf3572fda11d2c0b32aa3156f84a)
* The latest [Mapnik](http://mapnik.org/) code (at the time of image creation)
* The latest [Mod_Tile](http://wiki.openstreetmap.org/wiki/Mod_tile) code (at
the time of image creation)
* The latest [OSM Bright](https://github.com/mapbox/osm-bright/) code (at the
the time of image creation)

## Issues

This is a work in progress and although generally adequate it could benefit
from improvements. Please
[submit issues](https://github.com/geo-data/openstreetmap-tiles-docker/issues)
[submit issues](https://github.com/haroldship/openstreetmap-tiles-docker/issues)
on GitHub. Pull requests are very welcome!
2 changes: 2 additions & 0 deletions configure.py.sed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
s|config\["postgis"\]\["dbname"\] = "osm"|config["postgis"]["dbname"] = "gis"|
s|path.expanduser("~/Documents/MapBox/project")|path.expanduser("/usr/local/share/maps/style")|
10 changes: 5 additions & 5 deletions help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ Set up a database saved on an external volume:
The following command will initialise the postgresql database on an external
volume that can be used to persist the data:

docker run -v /data/osm-postgresql:/var/lib/postgresql homme/openstreetmap-tiles \
initdb startdb createuser createdb migrate
docker run -v /data/osm-postgresql:/var/lib/postgresql haroldship/openstreetmap-tiles-docker \
initdb startdb createuser createdb

Import data:
The following will import the .osm file at `/tmp/import.osm` into the
The following will import the .pbf file at `/tmp/import.pbf` into the
database.

docker run -v /data/osm-postgresql:/var/lib/postgresql -v /tmp:/data homme/openstreetmap-tiles \
docker run -v /data/osm-postgresql:/var/lib/postgresql -v /tmp:/data haroldship/openstreetmap-tiles-docker \
startdb import

Start the webserver:
Once data is loaded and users have been created run the webserver:

docker run -P -v /data/osm-postgresql:/var/lib/postgresql homme/openstreetmap-tiles \
docker run -P -v /data/osm-postgresql:/var/lib/postgresql haroldship/openstreetmap-tiles-docker \
startdb startservices

For further information run the cli and look at /usr/local/share/doc/README.md.
5 changes: 5 additions & 0 deletions osm-bright.osm2pgsql.sed
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
s|http://data.openstreetmapdata.com/\(.*\).zip|/usr/local/share/maps/style/osm-bright-master/shp/\1/\1.shp|
s|http://mapbox-geodata.s3.amazonaws.com/natural-earth-1.4.0/cultural/\(.*\).zip|/usr/local/share/maps/style/osm-bright-master/shp/ne_10m_populated_places_simple/ne_10m_populated_places_simple.shp|
/"file"/i\
"type": "shape",
s|"srs": "",|"srs": "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs",|
3 changes: 1 addition & 2 deletions renderd.conf.sed
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Perform sed substitutions for `renderd.conf`
s/;socketname=/socketname=/
s/plugins_dir=\/usr\/lib\/mapnik\/input/plugins_dir=\/usr\/local\/lib\/mapnik\/input/
s/\(font_dir=\/usr\/share\/fonts\/truetype\)/\1\/ttf-dejavu/
s/XML=.*/XML=\/usr\/local\/src\/mapnik-style\/osm.xml/
s/XML=.*/XML=\/usr\/local\/share\/maps\/style\/OSMBright\/OSMBright.xml/
s/HOST=tile.openstreetmap.org/HOST=localhost/
18 changes: 15 additions & 3 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ asweb="setuser www-data"

die () {
msg=$1
echo "FATAL ERROR: " msg > 2
echo "FATAL ERROR: $msg" >&2
exit
}

Expand All @@ -27,7 +27,19 @@ initdb () {
then
die "Initialisation failed: the directory is not empty: /var/lib/postgresql/9.3/main"
fi
_initdb
}

forceinitdb() {
echo "Initialising postgresql by FORCE"
if [ -d /var/lib/postgresql/9.3/main ] && [ $( ls -A /var/lib/postgresql/9.3/main | wc -c ) -ge 0 ]
then
rm -rf /var/lib/postgresql/9.3/main/*
fi
_initdb
}

_initdb() {
mkdir -p /var/lib/postgresql/9.3/main && chown -R postgres /var/lib/postgresql/
sudo -u postgres -i /usr/lib/postgresql/9.3/bin/initdb --pgdata /var/lib/postgresql/9.3/main
ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem /var/lib/postgresql/9.3/main/server.crt
Expand Down Expand Up @@ -56,8 +68,8 @@ createdb () {
# Set the correct table ownership
$asweb psql -d $dbname -c 'ALTER TABLE geometry_columns OWNER TO "www-data"; ALTER TABLE spatial_ref_sys OWNER TO "www-data";'

# Add the 900913 Spatial Reference System
$asweb psql -d $dbname -f /usr/local/share/osm2pgsql/900913.sql
# Add the Spatial Reference System
$asweb psql -d $dbname -f /usr/share/postgresql/9.3/contrib/postgis-2.1/spatial_ref_sys.sql
}

import () {
Expand Down